QiaoranC 2019-09-08

客户端测试通常使用Selenium,它可自动执测试行任务。
但是,您可能不需要Seleniumna那种重量级的或者那么多功能的框架。如果您正在寻找一种更轻巧,易于使用的工具来自动执行任务或运行端到端测试,Puppeteer是一个不错的选择。
本文中我们将使用:
所有这些库都是流行的开源项目,由著名的软件公司(谷歌,Facebook和微软)维护,这意味着这些工具不会很快消亡。 在这篇文章的最后,我们应该有一个可以可靠地运行测试或自动化任务的项目,用Chromium浏览器中的TypeScript编写。

module.exports = {
preset: 'jest-puppeteer',
testMatch: ["**/?(*.)+(spec|test).[t]s"],
testPathIgnorePatterns: ['/node_modules/', 'dist'], //
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
transform: {
"^.+\\.ts?$": "ts-jest"
},
globalSetup: './jest.global-setup.ts', // will be called once before all tests are executed
globalTeardown: './jest.global-teardown.ts' // will be called once after all tests are executed
};import "expect-puppeteer";
module.exports = {
launch: {
dumpio: true,
headless: false,
args: ['--disable-infobars'],
},
browserContext: 'default'
};const { setup: setupPuppeteer } = require('jest-environment-puppeteer');
/**
* Sets up the environment for running tests with Jest
*/
module.exports = async function globalSetup(globalConfig) {
// do stuff which needs to be done before all tests are executed
await setupPuppeteer(globalConfig);
};感谢你做将这篇文章读完。正如您所见,连接Jest,Puppeteer和TypeScript需要短短几个步骤。一旦完成这些设置,您可以实现很多您想实现的事情。
希望本文能帮助到您!
点赞,让更多的人也能看到这篇内容(收藏不点赞,都是耍流氓-_-)
关注公众号「新前端社区」,享受文章首发体验!
每周重点攻克一个前端技术难点。

运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算。以上实例中 7、5 和 12 是操作数。关系运算符用于计算结果是否为 true 或者 false。逻辑运算符用于测定变量或值之间的逻辑。