【问题标题】:Cypress choose what test file to launch based on a string赛普拉斯根据字符串选择要启动的测试文件
【发布时间】:2021-11-26 13:33:18
【问题描述】:

我目前在赛普拉斯工作,我会尽量简化我的问题:

我有几个测试文件:

integration/testA.spec.js
integration/testB.spec.js
integration/testC.spec.js

我还有一个 config.js 文件,其中有一个对象,其中包含我要运行的测试的名称:

{
    test: 'testA.spec.js'
}

我想做的——如果可能的话——是一个main.spec.js 文件,根据testproperty,运行相关的规范文件。

几乎所有东西都准备好了

describe('Test', () => {
  before(() => {})

  beforeEach(() => {})

  after(() => {})

  describe('Test Booking', () => {
    // retrieves the `test`property and returns the string name
    let testName = retrieveTestName()
    console.log('testName', testName)

    /** I want to do something like this */
    if (testName === 'testA.spec.js') {
        // launch testA.spec.js file
    }
  }

})

但是如果我可以做类似上面代码的事情,我会忽略;你觉得可能吗?

或者我必须创建一个脚本文件

  • 检查名称文件
  • 使用--spec 选项并启动测试

?

【问题讨论】:

    标签: javascript testing cypress


    【解决方案1】:

    一个选项可以是使用--spec 文件创建命令并将其添加到package.json 中的脚本下。比如:

    "scripts": {
      "testA": "npx cypress run --spec "cypress/integration/testA.spec.js",
      "testB": "npx cypress run --spec "cypress/integration/testB.spec.js",
      "testC": "npx cypress run --spec "cypress/integration/testC.spec.js"
    }
    

    你可以根据你要执行的测试直接运行上面的命令。

    npm run testA
    

    【讨论】:

      猜你喜欢
      • 2023-02-14
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      相关资源
      最近更新 更多