0

In Protractor tests I call many times browser.wait method for example to wait once the particular element will appear on the screen or it will be clickable.

In many cases tests passes on my local machine, but does not on other. I receive very generic information about the timeout which doesn't help me a lot to debug / find a source of issue.

Is it possible to make a browser.wait more verbose, for example:

  • if at least defaultTimeoutInterval will elapse when waiting for particular element, will it be possible to console.log information about the element that it tried to wait for,
  • take a screenshot when the timeout error occurs,
  • provide full call stack when timeout appears in browser.wait
matandked
  • 1,527
  • 4
  • 26
  • 51

3 Answers3

1

If the main issue is that you don't know for which element the wait timed out, I would suggest writing a helper function for wait and use it instead of wait, something like:

    wait = function(variable, variableName,waitingTime){
    console.log('Waiting for ' + variableName);
    browser.wait(protractor.ExpectedConditions.elementToBeClickable(variablename),waitingTime);
    console.log('Success');
}

Because protractor stops executing test after first fail, if wait timed out, console won't print success message after failing to load a certain element.

For screenshots I suggest trying out protractor-jasmine2-screenshot-reporter, it generates an easily readable html report with screenshots and debug information on failed tests (for example, in which code line the failure occured).

E SV
  • 133
  • 7
  • Thank you. I've also considerd this, but I think that it will create much output in the console. Maybe I should add switch to this helper method, so that I could easily switch on and off verbose mode. – matandked Sep 04 '18 at 15:21
0

Look into using protractor's Expected Condition, you can specify what to wait for and how long to wait for it.

For screenshots there are npm modules out there that can take a screenshot when a test fails. This might help.

MkMan
  • 1,779
  • 1
  • 14
  • 27
  • I'm using Expected Condition. In my question I mentioned (not directly) that I use elementToBeClickable and presenceOf. The problem is that when Protractor waits for one of them and then mark it as failed, I don't know which one caused an issue, because there's only information that timeout occurred in the console. – matandked Sep 04 '18 at 12:03
0

browser.wait returns a promise, so catch the error and print/throw something meaningful like:

await browser.wait(ExpectedConditions.visibilityOf(css), waitingTime).catch((error) => 
{
  throw new CustomError(`Could not find ${css} ${error.message}`)
});
carl kenne
  • 80
  • 8