简体   繁体   English

剧作家:是否可以仅指定 worker 数量或浏览器以进行 1 次测试?

[英]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.

相关问题 如何让编剧工作者在 NUnit 测试中执行单独的逻辑路径? - How to have playwright workers execute separate logical paths in an NUnit test? Playwright 测试运行器:将测试限制为仅一个浏览器,其配置文件包含许多项目 - Playwright test runner: Limit test to only one browser with a config file that has many projects 剧作家浏览器正在重新打开每个测试语句 - Playwright browser is reopening every test statement Playwright 可以根据运行它的浏览器进行条件测试吗? - Can Playwright do conditional test based on the browser that is running it? 您如何使用 Playwright 指定测试文件夹/路径? - How do you specify a test folder/path with Playwright? 是否可以像 Cypress 一样使用 Playwright 测试 API 端点? - Is it possible to test API endpoints with Playwright just like Cypress? 是否可以使用 CodeceptJS + PlayWright 或 CodeceptJS + Puppeteer 启动 Chrome 浏览器 - Is it possible to launch Chrome Browser with CodeceptJS + PlayWright or CodeceptJS + Puppeteer Puppeteer/Playwright 是否可以在无头启动时将浏览器设置为可见 - Puppeteer/Playwright is it possible to set the browser visible when launching as headless 测试套件的剧作家元数据 - playwright metadata for a test suite 与剧作家一起测试元标签 - Test meta tags with playwright
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM