【问题标题】:Not able to run my CodeceptJS testcases in headless chrome无法在无头 chrome 中运行我的 CodeceptJS 测试用例
【发布时间】:2020-03-07 00:03:50
【问题描述】:

我为我的应用程序设置了 CodeceptJS 框架,并且测试运行顺利。 但现在我希望他们运行无头 chrome。尝试了官方网站上提到的一些东西,但它不适合我。

我尝试使用npx codeceptjs run --verbose 运行我的测试。

我的 codecept.conf.js 文件如下所示:

exports.config = {
  tests: './tests/features/**/*_test.js',
  output: './tests/output',
  helpers: {
    WebDriver: {
      smartwait: 10000,
      waitForTimeout: 10000,
      url: 'https://affinity.sourcefuse.com',
      browser: 'chrome',
      windowSize: 'maximize',
      chromeOptions: {
        args: [ "--headless", "--disable-gpu", "--window-size=800,600"]
      }
    }
  },
  include: {
    I: './steps_file.js',
    createDatasetPage: 'tests/pages/createDataset.js',
  },
  bootstrap: null,
  mocha: {},
  name: 'dashboard',
  plugins: {
    "allure": {
      "enabled": true
    },
    wdio: {
      enabled: true,
      services: ['selenium-standalone']
    }
  }
}

实际:Chrome 已启动并开始运行测试。

预期:我希望它在 headless chrome 上运行。

【问题讨论】:

    标签: automated-tests google-chrome-headless codeceptjs


    【解决方案1】:

    chromeOptions 需要包裹在desiredCapabilities 中,你的配置应该是这样的:

    exports.config = {
      tests: './tests/features/**/*_test.js',
      output: './tests/output',
      helpers: {
        WebDriver: {
          smartwait: 10000,
          waitForTimeout: 10000,
          url: 'https://affinity.sourcefuse.com',
          browser: 'chrome',
          windowSize: 'maximize',
          desiredCapabilities: {
            chromeOptions: {
              args: ["--headless", "--disable-gpu", "--no-sandbox"]
            }
          }
        }
      },
      include: {
        I: './steps_file.js',
        createDatasetPage: 'tests/pages/createDataset.js',
      },
      bootstrap: null,
      mocha: {},
      name: 'dashboard',
      plugins: {
        "allure": {
          "enabled": true
        },
        wdio: {
          enabled: true,
          services: ['selenium-standalone']
        }
      }
    }
    
    

    我从args 中删除了windowSize,因为它已经用windowSize 设置并添加了no-sandbox,因为它建议用于测试自动化。

    【讨论】:

    • 改为添加 no-sandbox,因为它被推荐用于测试自动化。没有得到这部分。
    • 在您的初始配置中,您使用--window-size=800,600 作为chromeOptions 的第三个参数:1. 我建议将其省略 2. 我建议添加--no-sandbox arg
    猜你喜欢
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多