使用 Geb 测试 Angular 动态页面内容 (ng-if)

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

我正在尝试使用 Geb 测试 Angular ng-if 元素是否可见。到目前为止,我已经尝试测试显示的 属性 是真还是假,如下所示。

Angular:

<article ng-if="!condition" class="bar foo ng-scope">Text to Display</article>

Geb UI 模块:

unselectedErrorText { $(class: "bar foo ng-scope") }

测试:

assertThat(unselectedErrorText.displayed).isFalse()
checkBox.value()==false
assertThat(unselectedErrorText.displayed).isTrue()

我收到以下错误:

The required page content 'unselectedErrorText - SimplePageContent' is not present

提前致谢!

我错过的是 Angular 代码生成动态页面内容。 Geb(through the underlying selenium) will just have the initial DOM before any JavaScript manipulation is performed.

我使用 Geb 提供的 waitFor 方法解决了这个问题。

checkbox.value(false)
waitFor("quick") {
    assertThat(unselectedErrorText.displayed).isTrue()
}

非常感谢任何进一步、更全面的解释!