Skip to content

Instantly share code, notes, and snippets.

@martinhbramwell
Last active September 25, 2017 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinhbramwell/ed5457a511aab9f8f82ce67239addee3 to your computer and use it in GitHub Desktop.
Save martinhbramwell/ed5457a511aab9f8f82ce67239addee3 to your computer and use it in GitHub Desktop.

So, what has me hysterical is the seeming random behavior. Sometimes it works, sometimes it does not. When it fails, the selected item is clearly visible on screen for the entire 60 second wait. Screenshots also show it's available all the time, and there is no consistency about which scenario will succeed or fail.

The problematic step is And I have elected to edit the "Graphic Designer" item,

One call to the stepDef looks like this :

  @watch
  Scenario: Verify field validation
WARNING: the "timeoutsImplicitWait" command will be depcrecated soon. Please use a different command in order to avoid failures in your test after updating WebdriverIO.
  ✔ Given I have opened the books list page : "http://localhost:3000/books"
Log output : link is "//a[@data-cuke="Graphic Designer"]"
  ✖ And I have elected to edit the "Graphic Designer" item,
  - When I set 'Number of Pages' to "55"
  - And I submit the item,
  - Then I see the number of pages validation hint "Pages count cannot be less than 60!".

A second call might look like this :

  @watch
  Scenario: Update book
 Exception :: Error: element ("//a[@data-cuke="Graphic Designer"]") still not existing after 60000ms
Log output : Ready to click the link
WARNING: the "timeoutsImplicitWait" command will be depcrecated soon. Please use a different command in order to avoid failures in your test after updating WebdriverIO.
  ✔ Given I have opened the books list page : "http://localhost:3000/books"
Log output : link is "//a[@data-cuke="Graphic Designer"]"
Log output : Ready to click the link
  ✔ And I have elected to edit the "Graphic Designer" item,
  ✔ When I set 'Number of Pages' to "321"
  ✔ And I submit the item with new content "SciFi is the new ---> Religion!",
  ✔ Then I see the record with the new content.

After all tests have run, the error appears as :

1) Scenario: Verify field validation - .pkgs/gitignored_mmks_book/.e2e_tests/features/books/addBook.feature:24
   Step: And I have elected to edit the "Graphic Designer" item, - .pkgs/gitignored_mmks_book/.e2e_tests/features/books/addBook.feature:26
   Step Definition: .e2e_tests/features/000_shared/step_defs.js:167
   Message:
     function timed out after 60000 milliseconds

The code looks like this :

  this.Given(/^I have elected to edit the "([^"]*)" item,$/, function (_item) {
    link = '//a[@data-cuke="' + _item + '"]';
    console.log('Log output : link is "%s"', link);
    try {
      browser.waitForExist( link );
    }
    catch (e) {
       console.log(' Exception :: %s', e);
       browser.saveScreenshot('/home/you/tmp/NoGraphicDesigner.png');
    }
    console.log('Log output : Ready to click the link');
    browser.click(link);
    browser.waitForEnabled( cukeHrefEdit );
    browser.click(cukeHrefEdit);
  });

The exception seems to appear asynchronously.

@UncleGus
Copy link

Try putting browser.debug() in your catch block and then inspect the element that you're trying to find
make sure it matches your selector, etc.
Also, if I'm not mistaken, the failed example test you have and the passed example test are actually different tests, no?
Is it the same test that sometimes passes and sometimes fails? or is it always the same tests that pass/fail?
It might be the same step definition that passes in one and fails in another, but the context will be different in different tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment