我在夹具文件夹中只有以下 Test.json 文件:
[
{
"searchKeyword":"cypress"
},
{
"searchKeyword":"QA automation"
},
{
"searchKeyword":"stackoverflow"
}
]
上述文件包含三个不同的数据集。
我只有以下规范文件,它包含一个它(测试用例),它将根据上述输入运行多次。
Test.spec.js 文件:
describe("Run the test parallel based on the input data",() =>{
const baseUrl = "https://www.google.com/";
before("Login to consumer account", () => {
cy.fixture('Test').then(function (data) {
this.data = data;
})
});
it("Search the keyword", function () {
this.data.forEach((testData) =>{
cy.visit(baseUrl);
cy.xpath("//input[@name='q']").type(testData.searchKeyword);
cy.xpath("//input[@value='Google Search']").click();
cy.get("//ul/li[2]").should("be.visible");
});
});
});
上面的代码按预期工作。但我只想通过使用不同的数据集并行运行上述单个测试。
示例:三个浏览器实例打开,它应该从 Test.json 文件中选择三个不同的数据并运行 Test.spec.js 文件中可用的单个测试。
我只需要为我的一个项目实现逻辑,但我无法共享更复杂的代码,这就是为什么只创建一些虚拟测试数据和测试脚本来实现我的逻辑。
有人可以分享你的想法来实现这一目标。