[英]Playwright: Possible to specify either number of workers or the browser for 1 test only?
I have my suite set up to run against 4 browsers using 3 workers (2 desktops and 2 mobile) I have a test that I need to either not run in parallel or limit to just run in one desktop browser.我将我的套件设置为使用 3 个工作人员(2 个台式机和 2 个移动设备)针对 4 个浏览器运行我有一个测试,我需要不并行运行或限制只在一个桌面浏览器中运行。
Is that possible?那可能吗?
The reason I need to do this is that the test is triggering an event that can take a few seconds to run, when running nobody else can start this event so if 3 tests are running at once only the first one can pass.我需要这样做的原因是测试正在触发一个可能需要几秒钟才能运行的事件,运行时没有其他人可以启动此事件,因此如果同时运行 3 个测试,则只有第一个可以通过。 Also, on mobile, you can't trigger the event, so I skip parts of the test if isMobile is true.
此外,在移动设备上,您无法触发该事件,因此如果 isMobile 为真,我将跳过部分测试。
Ideally, I'd like to just run this test in Firefox and leave the rest of the suite running in 3 workers with 4 browsers.理想情况下,我只想在 Firefox 中运行此测试,并让套件的 rest 在 3 个工作人员和 4 个浏览器中运行。
I looked at test.describe.configure({ mode: 'serial' });
我看着
test.describe.configure({ mode: 'serial' });
but that doesn't seem to make a difference I still see但这似乎没有什么区别我仍然看到
Running 4 tests using 3 workers
使用 3 个工作人员运行 4 个测试
when I try just running this single spec file.当我尝试运行这个单一的规范文件时。
To change the parallelism you have to have a look at the workers
config .要更改并行度,您必须查看
workers
config 。 You can either define it via playwright.config.js
or the command line.您可以通过
playwright.config.js
或命令行定义它。
What we do at work is to separate commands based on directory or custom annotations.我们在工作中所做的是根据目录或自定义注释来分离命令。
{
"name": "parallel",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test:parallel": "npx playwright test tests/parallel/",
"test:sequence": "npx playwright test tests/sequence/ --workers=1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.29.2"
}
}
This way you can configure only subsets of tests that run in parallel whereas others run sequentially.通过这种方式,您可以仅配置并行运行的测试子集,而其他测试则按顺序运行。
And funnily, I also recorded a video on the topic not too long ago .有趣的是,不久前我还录制了一段关于这个话题的视频。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.