这里是Javascript / Cypress的相对新手。我正在使用Cypress Cucumber.js插件运行一些测试。问题是我不能让我的步骤按顺序运行--由于js的异步特性,'Then‘步骤在给定的etc之前运行。显然,这成为了一个问题,因为测试将会失败!
我的问题是:
1)我们如何使用异步代码使黄瓜步骤始终按顺序运行?我在这里看到了一个类似的问题:How to wait for a JavaScript Promise to resolve before resuming function?,根据我对给定块应用异步/等待的响应,希望它会强制我的步骤中的顺序,但这不起作用。
以下是我的功能文件:
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');
});
});
});但是,遗憾的是,没有luck...the给出的仍然是最后的日志。
任何帮助都将不胜感激,我很乐意提供进一步的澄清。:)
发布于 2018-11-14 21:18:45
我正在使用Cypress,带有Typescript和Cucumber预处理器,功能文件中的所有步骤都在同步运行,请检查版本和示例:Test Repo Cypress-Cucumber-Typescript
https://stackoverflow.com/questions/51990729
复制相似问题