首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cypress Cucumber -如何让我的步骤按顺序运行?

问Cypress Cucumber -如何让我的步骤按顺序运行?
EN

Stack Overflow用户
提问于 2018-08-24 00:50:48
回答 1查看 1.8K关注 0票数 4

这里是Javascript / Cypress的相对新手。我正在使用Cypress Cucumber.js插件运行一些测试。问题是我不能让我的步骤按顺序运行--由于js的异步特性,'Then‘步骤在给定的etc之前运行。显然,这成为了一个问题,因为测试将会失败!

我的问题是:

1)我们如何使用异步代码使黄瓜步骤始终按顺序运行?我在这里看到了一个类似的问题:How to wait for a JavaScript Promise to resolve before resuming function?,根据我对给定块应用异步/等待的响应,希望它会强制我的步骤中的顺序,但这不起作用。

以下是我的功能文件:

代码语言:javascript
复制
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"

步骤:

代码语言:javascript
复制
  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来强制执行一些命令:

代码语言:javascript
复制
  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给出的仍然是最后的日志。

任何帮助都将不胜感激,我很乐意提供进一步的澄清。:)

EN

回答 1

Stack Overflow用户

发布于 2018-11-14 21:18:45

我正在使用Cypress,带有Typescript和Cucumber预处理器,功能文件中的所有步骤都在同步运行,请检查版本和示例:Test Repo Cypress-Cucumber-Typescript

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51990729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档