我们可以基于Env配置并选择剧作家启动选项吗?

发布于 2025-01-24 20:18:17 字数 719 浏览 1 评论 0原文

上下文:作为CI/CD进程的一部分,我正在为企业Web应用程序运行一堆剧作E2E测试,该测试是在GitHub Action上运行的。

要使用剧作家启动铬,我们有以下启动选项 -

const options = {
  headless: true,
  slowMo: 100,
  ..
  // all args added to help run Chromium in headless mode
  args: [
    '--start-maximized',
    '--disable-dev-shm-usage',
    '--no-sandbox'
  ],
  
  video: "true"
};

当在添加新测试用例的过程中,在本地系统上运行相同的测试时,我们必须手动将 true 更改为> false具有头部执行。

我想知道我们是否可以根据运行进行配置以更改 - 当执行是本地时,它在CI上运行时将无头模式更改为false和true。假设对于在本地运行测试,

npm运行测试-env = local将无头作为false,而npm运行test -env = ci在此处无头为true。 选项

我已经浏览了剧作家的文档,但找不到任何具体的文档。剧作家/Puppeteer上的大多数答案都是关于如何基于Env更改URL等的。

Context : I am running a bunch of Playwright e2e tests for a enterprise web application, which are run on Github actions, as a part of the CI/CD process.

To launch Chromium using Playwright we have these launch options -

const options = {
  headless: true,
  slowMo: 100,
  ..
  // all args added to help run Chromium in headless mode
  args: [
    '--start-maximized',
    '--disable-dev-shm-usage',
    '--no-sandbox'
  ],
  
  video: "true"
};

When the same tests are run on the local system during the time we add new test cases, we have to manually change the headless: true to false to have a head-ful execution.

I'm wondering if we can configure this to have change based on the run - when the execution is local, it changes the headless mode to false and true when it runs on ci. Let's say for running tests on local,

npm run test --env=local gets the headless as false, and npm run test --env=ci gets headless true in the options.

I've gone through Playwright's documentation but couldn't find anything concrete. Most of the answers on Playwright/Puppeteer are about how to change the URL's etc, based on the env.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高冷爸爸 2025-01-31 20:18:17

您可以尝试以下选项之一:

  1. 创建两个独立的配置文件,一个用于CI,一个用于本地执行。在package.json中创建两个脚本
  headless: !!process.env.HEADLESS,
  slowMo: 100,
  ..
  // all args added to help run Chromium in headless mode
  args: [
    '--start-maximized',
    '--disable-dev-shm-usage',
    '--no-sandbox'
  ],
  
  video: "true"
};```

// create two scripts in your package.json:

"headless":"HEADLESS=true npm run test"
"local":"npm run test"

You could try one of the below options:

  1. Create two separate config files, one for ci and one for local execution. Create two scripts in package.json one for local and one ci pointing to respective config file
  2. Update your current code as below:
  headless: !!process.env.HEADLESS,
  slowMo: 100,
  ..
  // all args added to help run Chromium in headless mode
  args: [
    '--start-maximized',
    '--disable-dev-shm-usage',
    '--no-sandbox'
  ],
  
  video: "true"
};```

// create two scripts in your package.json:

"headless":"HEADLESS=true npm run test"
"local":"npm run test"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文