Cypress Cucumber - How do I make my steps run in order?










3















Relative newbie to Javascript / Cypress here. I am running some tests using the Cypress Cucumber.js plugin. The issue is that I cannot make my steps run in order - the 'Then' steps run before the 'Given etc, due to the asynchronous nature of js. Obviously, this becomes an issue as the tests will fail!



My question:



1) How can we make it such that cucumber steps are always running in order using async code? I saw a similar question here: How to wait for a JavaScript Promise to resolve before resuming function? , and based on the responses I applied async / await to my Given block, hoping it would force an order in my steps however this did not work.



Here is my feature file:



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"


Steps:



 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');
);


Currently, this logs out 2,3,1.



After some searching, I attempted to use the Cypress.Promise to force some order:



 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');
);
);
);


But alas, no luck...the Given still logs last.



Any help would be greatly appreciated, and I'm happy to provide further clarification. :)










share|improve this question


























    3















    Relative newbie to Javascript / Cypress here. I am running some tests using the Cypress Cucumber.js plugin. The issue is that I cannot make my steps run in order - the 'Then' steps run before the 'Given etc, due to the asynchronous nature of js. Obviously, this becomes an issue as the tests will fail!



    My question:



    1) How can we make it such that cucumber steps are always running in order using async code? I saw a similar question here: How to wait for a JavaScript Promise to resolve before resuming function? , and based on the responses I applied async / await to my Given block, hoping it would force an order in my steps however this did not work.



    Here is my feature file:



    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"


    Steps:



     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');
    );


    Currently, this logs out 2,3,1.



    After some searching, I attempted to use the Cypress.Promise to force some order:



     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');
    );
    );
    );


    But alas, no luck...the Given still logs last.



    Any help would be greatly appreciated, and I'm happy to provide further clarification. :)










    share|improve this question
























      3












      3








      3


      1






      Relative newbie to Javascript / Cypress here. I am running some tests using the Cypress Cucumber.js plugin. The issue is that I cannot make my steps run in order - the 'Then' steps run before the 'Given etc, due to the asynchronous nature of js. Obviously, this becomes an issue as the tests will fail!



      My question:



      1) How can we make it such that cucumber steps are always running in order using async code? I saw a similar question here: How to wait for a JavaScript Promise to resolve before resuming function? , and based on the responses I applied async / await to my Given block, hoping it would force an order in my steps however this did not work.



      Here is my feature file:



      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"


      Steps:



       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');
      );


      Currently, this logs out 2,3,1.



      After some searching, I attempted to use the Cypress.Promise to force some order:



       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');
      );
      );
      );


      But alas, no luck...the Given still logs last.



      Any help would be greatly appreciated, and I'm happy to provide further clarification. :)










      share|improve this question














      Relative newbie to Javascript / Cypress here. I am running some tests using the Cypress Cucumber.js plugin. The issue is that I cannot make my steps run in order - the 'Then' steps run before the 'Given etc, due to the asynchronous nature of js. Obviously, this becomes an issue as the tests will fail!



      My question:



      1) How can we make it such that cucumber steps are always running in order using async code? I saw a similar question here: How to wait for a JavaScript Promise to resolve before resuming function? , and based on the responses I applied async / await to my Given block, hoping it would force an order in my steps however this did not work.



      Here is my feature file:



      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"


      Steps:



       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');
      );


      Currently, this logs out 2,3,1.



      After some searching, I attempted to use the Cypress.Promise to force some order:



       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');
      );
      );
      );


      But alas, no luck...the Given still logs last.



      Any help would be greatly appreciated, and I'm happy to provide further clarification. :)







      javascript node.js cucumber cucumberjs cypress






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 23 '18 at 16:50









      KZNKatanaKZNKatana

      184




      184






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I'm using Cypress with Typescript and Cucumber preprocessors and all steps in the feature file running synchronously, check the versions and example here: Test Repo Cypress-Cucumber-Typescript






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51990729%2fcypress-cucumber-how-do-i-make-my-steps-run-in-order%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I'm using Cypress with Typescript and Cucumber preprocessors and all steps in the feature file running synchronously, check the versions and example here: Test Repo Cypress-Cucumber-Typescript






            share|improve this answer



























              0














              I'm using Cypress with Typescript and Cucumber preprocessors and all steps in the feature file running synchronously, check the versions and example here: Test Repo Cypress-Cucumber-Typescript






              share|improve this answer

























                0












                0








                0







                I'm using Cypress with Typescript and Cucumber preprocessors and all steps in the feature file running synchronously, check the versions and example here: Test Repo Cypress-Cucumber-Typescript






                share|improve this answer













                I'm using Cypress with Typescript and Cucumber preprocessors and all steps in the feature file running synchronously, check the versions and example here: Test Repo Cypress-Cucumber-Typescript







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 '18 at 13:18









                LudmilaNLudmilaN

                663




                663





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51990729%2fcypress-cucumber-how-do-i-make-my-steps-run-in-order%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20