I have the following code:
const until = protractor.ExpectedConditions;
export class GenericPOClass {
waitForPagetoLoad(numberOfSecondsToWait: number = 30) { // note the default
(1) let elementToWaitFor = element(by.css('app-spec-mapper .stepper'));
(2) browser.wait(until.presenceOf(elementToWaitFor), numberOfSecondsToWait*1000);
(3) return expect(elementToWaitFor.isPresent()).toBeTruthy('Element stepper is not actually present.');
}
}
This is code called from a protractor/jasmine test to wait for my non-angular web page to load.
If I use all 3 lines, with a "default wait time of 30 seconds, I make it past this loading part of my test and move onto another section.
If I use just lines 1 & 3, I get the expectation error.
If I use line 2 as well with a number of seconds to wait of 0, it works anyway. The page is loaded, line 3 passes.
Is there some type of default wait time on browser.wait that overrides my wait time? Is there some freaky magic of asynchronicity that it works if observed (browser.wait calling the expected conditions is magic)?
Coming from a synchronous Java and TestNG background, I've been learning protractor and JavaScript as I go, writing automated test cases for my job and things like this without a formal class or knowledgeable person to ask keep tripping me up. I've been wrangling with getting waiting for things to load working for a week, please help me understand this black magic.
Protractor Version: 5.1.2
NodeJS: 6.11.2
IDE: IntelliJ WebStorm