问题
I am trying to test if an Angular ng-if element is visible or not using Geb. So far I've attempted to test if the displayed property is true or false as follows.
Angular:
<article ng-if="!condition" class="bar foo ng-scope">Text to Display</article>
Geb UI Module:
unselectedErrorText { $(class: "bar foo ng-scope") }
Test:
assertThat(unselectedErrorText.displayed).isFalse()
checkBox.value()==false
assertThat(unselectedErrorText.displayed).isTrue()
I am getting the following error:
The required page content 'unselectedErrorText - SimplePageContent' is not present
Thanks in advance!
回答1:
What I had missed was that the Angular code generates dynamic page content. Geb(through the underlying selenium) will just have the initial DOM before any JavaScript manipulation is performed.
I solved this using the waitFor method provided by Geb.
checkbox.value(false)
waitFor("quick") {
assertThat(unselectedErrorText.displayed).isTrue()
}
Any further, more comprehensive explanation is very much appreciated!
来源:https://stackoverflow.com/questions/30612921/testing-angular-dynamic-page-content-ng-if-with-geb