In the process of developing an automated test suite for an AngularJS application using Protractor, I have reached a point where I no longer need to manually pause the script at each step with browser.pause()
. Now, I want to let the script run through to completion on its own.
To achieve this, I am exploring the use of browser.wait()
to ensure the browser has loaded before executing the next step. I am passing the last line of each test as a parameter to browser.wait()
along with a timeout value. For example:
it('should log the user in to the application', function() {
browser.wait(loginAsUser(username, password), 10000);
});
instead of the previous:
browser.pause();
it('should log the user in to the application', function() {
loginAsUser(username, password);
});
However, I encountered a failure with the message: "Failed: Wait condition must be a promise-like object, function, or a Condition object". This error puzzled me as the wait
condition is a function, specifically the loginAsUser()
function previously defined.
Further edits to my test revealed issues with subsequent tests failing due to elements not being found after the login step. It seems that the page was not given enough time to load following the login when browser.pause()
was removed.
Attempts to use browser.wait()
within the failing test did not resolve the issue, leading to the same "Failed: No element found using locator" error. It became clear that the application required more time to load after the login before proceeding to the next test.
Finally, I optimized the test script with a new approach utilizing EC.visibilityOf()
and browser.wait()
to wait for elements to be displayed before interacting with them. However, the test still failed with unexpected results, indicating a need for further debugging and understanding of the implementation.