Reputation: 477
I have an angular page that shows or hides a countries dropDownList based on the value of a radioButton. If the rb is true, then the ddl gets hidden and if the ddl is false, the ddl is shown. This is done directly in the ddl HTML, adding the following attribute to the select tag: ng-show="!vm.inscriptor.isLocalCountry"
.
All Works well as expected, except for the following protractor test:
it(testNumber++ + " ddl de países debería estar oculto", function () {
pages.register.rbdLocalCountryTrue.click();
expect(pages.register.ddlCountries.isPresent()).toBeTruthy();
expect(pages.register.ddlCountries.isDisplayed()).toBeFalsy();
});
As expected, when the radio button for the true value is clicked, the ddl gets hidden, however the "isDisplayed" expect throws the following error:
Expected true to be falsy.
The only reason I can think of is that the expect statement is being executed before the click finishes procesing. I tried to refactor the test per the following:
it(testNumber++ + " ddl de países debería estar oculto", function () {
pages.register.rbdLocalCountryTrue.click().then(function () {
expect(pages.register.ddlCountries.isPresent()).toBeTruthy();
expect(pages.register.ddlCountries.isDisplayed()).toBeFalsy();
});
});
but I still get random results with the expect.
If I add a browser.sleep(5000), then the expect results show correctly, but everywhere I've read says that browser.sleep is a last resort kind of trick.
Is there any other way to tell protractor to wait for the click to finish processing? Any other suggestions?
Thx
Upvotes: 3
Views: 632
Reputation: 3645
You can use browser.wait()
for the element to be hidden after the click()
. And to add, you don't need to chain the promises of Click()
and expect()
as Protractor Control Flow does it for you
You can have something like this
it(testNumber++ + " ddl de países debería estar oculto", function () {
pages.register.rbdLocalCountryTrue.click();
browser.wait(protractor.ExpectedConditions.invisibilityOf(pages.register.ddlCountries), 10000);
expect(pages.register.ddlCountries.isPresent()).toBeTruthy();
expect(pages.register.ddlCountries.isDisplayed()).toBeFalsy();
});
Upvotes: 1