Testing Angular dynamic page content (ng-if) with Geb

╄→尐↘猪︶ㄣ 提交于 2020-01-03 16:14:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!