我们可以通过将不同的* _spec.js文件捆绑在一起来创建cypress测试套件吗?

时间:2018-04-20 09:56:46

标签: automated-tests bamboo cypress

现状: 我们正在使用cypress进行测试自动化。我们有一个名为“integration”的文件夹,其中包含多个“spec”文件。这些规范文件可以包含一个或多个彼此相关的测试。

问题: 我想正确地组织竹子上的柏树测试自动化。我想要做的是拥有测试套件,例如

  

Playground_suite包含:1)slide_tests_spec.js   2)teeter_totters_tests_spec.js ...

     

Road_suite包含:1)car_tests_spec.js 2)truck_tests_spec.js ...

我可以选择运行Playground_suite,它只运行此套件中定义的spec文件。

这是否可能在柏树,如果是的话,怎么样?请帮忙。

1 个答案:

答案 0 :(得分:1)

我们曾经遇到过相同类型的问题。我们想解决以下问题的方法如下:

00_suite.example.js:
import Test01 from './e2e_test01.example.js';
import Test02 from './e2e_test02.example.js';
import Test03 from './e2e_test03.example.js';

describe('Cypress_PreTest_Configuration', function() {
    console.log(Cypress.config());
});

// This is an example suite running tests in a specified order - 
// All tests contained in each of these files will be run before the next
// file is processed.
describe('Example_E2E_Test_Suite', function() {
    Test01();
    Test02();
    Test03();
});

describe('Example_Reverse_Ordered_E2E_Test_Suite', function() {
    Test03();
    Test02();
    Test01();
});

实际测试文件中的关键是它们在描述套件定义之前包含“导出默认功能(){}”选项:

e2e_test01.example.js:
export default function() {
    describe('Example_Tests_01', function() {
        it('TC01 - Example Tiger Tests', function() {
            doNothingOne();
            console.log(this.test.parent.parent.title);
            cy.visit(this.commonURIs.loginURI);
        })
    })
}

尝试在Cypress UI中运行e2e_test * .example.js文件时,您会发现该UI将报告未找到任何测试。您将必须通过套件定义文件执行测试。我们仅通过使用“套件”方法进行端到端测试,而使用标准规范文件进行回归和最低可接受性测试来解决此限制。

我希望这个示例对您有所帮助,也许其他人可能还有其他解决方案。