如何使用Geb验证是否需要字段?

时间:2018-02-28 20:20:53

标签: automated-tests spock geb

我正在使用Spock / Geb编写自动化测试,我想验证实际上是否需要字段。

以下是代码:

Code for Client Name and Client ID fields which are both required

以下是我试图编写的但未成功检查以确保实际需要这两个字段的内容:

Assertions

有没有人知道我的代码应该是什么样的?

以下是实际页面的样子 - 我正在尝试验证红色星号:

enter image description here

更新:以下代码有效: 断言clientConfigPage.modalClientNameTextBox.getAttribute(“required”)

1 个答案:

答案 0 :(得分:1)

您想使用Navigator.hasClass(String className)。这将返回一个布尔值,该元素是否具有给定名称的类。在您的示例中,您使用.getAttribute(" class")==" req"但是class属性是" required"所以你必须检查那个字符串文字。

相关问题