Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Test case and fix for NoSuchElementError in visibilityOf #3777 #3958

Merged
merged 2 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/expectedConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,15 @@ export class ProtractorExpectedConditions {
* representing whether the element is visible.
*/
visibilityOf(elementFinder: ElementFinder): Function {
return this.and(this.presenceOf(elementFinder), elementFinder.isDisplayed.bind(elementFinder));
return this.and(this.presenceOf(elementFinder), () => {
return elementFinder.isDisplayed().then((displayed: boolean) => displayed, (err: any) => {
if (err instanceof wderror.NoSuchElementError) {
return false;
} else {
throw err;
}
});
});
}

/**
Expand Down
20 changes: 20 additions & 0 deletions spec/basic/expected_conditions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ describe('expected conditions', function() {
expect(visibilityOfHideable.call()).toBe(false);
});

it('should have visibilityOf (handling race conditions)', function() {
var disabledButton = $('#disabledButton[disabled="disabled"]');

// toggle presence (of .ng-hide) between visibility evaluation to simulate race condition
var originalIsDisplayedFn = disabledButton.isDisplayed;
disabledButton.isDisplayed = function () {
element(by.model('disabled')).click();
return originalIsDisplayedFn.call(this);
};

var visibilityOfDisabledButtonWithInterceptor = EC.visibilityOf(disabledButton);

element(by.model('disabled')).click();

expect(originalIsDisplayedFn.call(disabledButton)).toBe(true);
expect(disabledButton.isPresent()).toBe(true);

expect(visibilityOfDisabledButtonWithInterceptor.call()).toBe(false);
});

it('should have invisibilityOf', function() {
var invisibilityOfInvalid = EC.invisibilityOf($('#INVALID'));
var invisibilityOfHideable = EC.invisibilityOf($('#shower'));
Expand Down