Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 柏树黄瓜-我如何使我的步骤运行有序?_Javascript_Node.js_Cucumber_Cucumberjs_Cypress - Fatal编程技术网

Javascript 柏树黄瓜-我如何使我的步骤运行有序?

Javascript 柏树黄瓜-我如何使我的步骤运行有序?,javascript,node.js,cucumber,cucumberjs,cypress,Javascript,Node.js,Cucumber,Cucumberjs,Cypress,这里是Javascript/Cypress的相对新手。我正在使用Cypress Cucumber.js插件运行一些测试。问题是我不能让我的步骤按顺序运行——“Then”步骤在“Given etc”之前运行,因为js的异步特性。显然,这会成为一个问题,因为测试将失败 我的问题: 1) 如何使用异步代码使cucumber步骤始终按顺序运行?我在这里看到了一个类似的问题:,根据我对给定块应用async/Wait的响应,希望它能在我的步骤中强制执行命令,但这不起作用 这是我的功能文件: Given I

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

我的问题:

1) 如何使用异步代码使cucumber步骤始终按顺序运行?我在这里看到了一个类似的问题:,根据我对给定块应用async/Wait的响应,希望它能在我的步骤中强制执行命令,但这不起作用

这是我的功能文件:

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

经过一番搜索,我试图使用柏树。我承诺强制执行一些命令:

  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');
      });
    });
  });
但是,唉,没有运气……给定的仍然是最后的日志


非常感谢您的帮助,我很高兴提供进一步的说明。:)

我正在使用Cypress与Typescript和Cucumber预处理器以及同步运行的功能文件中的所有步骤,请检查此处的版本和示例:

步骤是否按场景分组?