Reputation: 265
I have a login screen and when I press the Login button goes to the dashboard page. However, I often miss my timeout. Is there any possibility that when the button is pressed wait for the page to load?
my method in app.po.ts
login() {
element(by.name('username')).sendKeys(browser.params[0].UserName);
element(by.name('password')).sendKeys(browser.params[0].Password);
element(by.partialButtonText('SignIn')).click();
browser.sleep(5000);
}
Test is done here app.e2e-spec.ts
it('should be able to login', () => {
page.navigateToHome();
page.login();
page.browserSleep();
});
Upvotes: 3
Views: 2958
Reputation: 21688
if you are using protractor 4 or above angular 4 in can take advantages of async
and await
so your lofin function is a async function and while calling you will wait it to finish the async call.
async login() {
element(by.name('username')).sendKeys(browser.params[0].UserName);
element(by.name('password')).sendKeys(browser.params[0].Password);
element(by.partialButtonText('SignIn')).click();
browser.sleep(5000);
}
it('should be able to login', async () => {
await page.navigateToHome();
await page.login();
// page.browserSleep(); you dont need to use page sleep as its not requred
});
You may need to define
Upvotes: 1
Reputation: 18799
you can use the browser.wait
method to wait for a specific item inside your dashboard to appear, something like:
browser.wait(protractor.ExpectedConditions.visibilityOf(someElement), 10000, "Dashboard never loaded");
Upvotes: 2