![](/img/trans.png)
[英]How to make cucumber test steps run half steps only on Chrome and rest of the steps on different browsers?
[英]Cypress Cucumber - How do I make my steps run in order?
这里是Javascript / Cypress的相对新手。 我正在使用赛普拉斯Cucumber.js插件运行一些测试。 问题是我不能按顺序运行我的步骤 - 由于js的异步性质,'Then'步骤在'Given etc之前运行。 显然,这成为一个问题,因为测试将失败!
我的问题:
1)我们怎样才能使黄瓜步骤始终按顺序运行使用异步代码? 我在这里看到了一个类似的问题: 如何在恢复功能之前等待JavaScript Promise解决? ,并根据我应用async / await到我的Given块的响应,希望它会强制我的步骤中的顺序但是这不起作用。
这是我的功能文件:
Given I get the data from CMS
Then I can verify that the title is the same as the CMA title in tab "0"
And I can verify that the link is the correct link in tab "0"
脚步:
Given('I get the data from CMS', async() => {
let api = await Api.buildDevApi();
expectedNav = await new NavExpected(api);
console.log('1');
});
Then('I can verify that the title is the same as the CMA title in tab {string}', (index) => {
cy.root().find(".primary-item").eq(index).children().first(".nav-link").as('nav');
cy.get('@nav').should(async(text) => {
let title = await expectedNav.expectedTitle(index);
expect(text.get(0).innerText).to.eq(title);
})
console.log('2');
});
Then('I can verify that the link is the correct link in tab {string}', (index) => {
cy.get('@nav').should(async(url) => {
let link = await expectedNav.expectedLink(index);
expect(url.attr('href')).to.eq(link);
})
console.log('3');
});
目前,这将退出2,3,1。
经过一番搜索,我试图使用Cypress.Promise强制执行一些命令:
Given('I get the data from Prismic T1', () => {
return new Cypress.Promise((resolve) => {
PrismicApi.buildDevApi().then(api => {
expectedNav = new NavExpected(api);
resolve();
console.log('1');
});
});
});
但是,唉,没有运气......鉴定仍然记录最后。
任何帮助将不胜感激,我很乐意提供进一步的澄清。 :)
我正在使用赛普拉斯的Typescript和Cucumber预处理器以及同步运行的功能文件中的所有步骤,请查看版本和示例: Test Repo Cypress-Cucumber-Typescript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.