Reputation: 1
I have a problem with a browser.wait function in my project:
it("should display plan description", async () => {
//changing description in LIC
await app.navigateTo(LIC_PLANS_URL);
browser.sleep(2000);
dashboard.filtrByTitle = PLAN_TITLE;
browser.sleep(2000);
await dashboard.plansEdit.click();
browser.sleep(2000);
dashboard.description = PLAN_TEST;
browser.sleep(2000);
await dashboard.savePlan.click();
//checking that the plan description has changed in ACC
app.navigateTo(ACC_DASHBOARD);
browser.sleep(4000);
expect(dashboard.planDescription.getText()).toContain("automation_test");
Can i do something with this browser.sleep functions? I thing that this is not a proper way to make test but without this it makes timeout errors.
I was trying to solve this with:
var EC = browser.ExpectedConditions;
browser.wait(EC.visibilityOf(dashboard.plansEdit),5000);
But it doesnt help at all, im using protractor 7.0.0. Anyone know how to solve this problem.
Upvotes: 0
Views: 313
Reputation: 734
you are correct when saying that browser.sleep()
is not a good practice and should be replaced with explicit waits.
In the particular case of visibilityOf()
, Protractor assumes the element is already present and tries to locate it right away, if it's not present, thus not visible, it'll throw an exception. But you could use the presenceOf()
method which waits for the element to be present in the html DOM for any given amount of time that you specify (default is 5000ms).
You could make a function that waits for the presence of an element then for its visibility/clickability:
const EC = browser.ExpectedConditions;
const waitForEl = async (ele) = {
await browser.wait(EC.presenceOf(ele), 5000);
return await browser.wait(EC.visibilityOf(ele), 5000);
};
// call it:
await waitForEl(dashboard.plansEdit);
Upvotes: 1