我正在尝试将硒测试转换为Gherkin。有没有办法在Gherkin中实现if语句?
示例:假设代码是以以下格式编写的。我只是写了下面的描述。请理解双斜杠后的部分是实际的Selenium代码:
// launch the application
// login to application
// navigate to page
String str;
if(str== "XYZ")
{
// verify title
}
//verify text field 1
//verify test field 2
//verify select box为此,我试图用Gherkin编写如下代码
Given user launches the application
When user login with valid credentials
and navigate to required page
When String str is "XYZ"
Then verify title
And verify text field 1
And verify test field 2
And verify select box但是这个代码是不正确的,因为如果str不等于"XYZ“,我们希望这个标题不应该被验证,但是其他的验证,比如文本字段1,2和复选框应该被验证。
发布于 2017-08-01 10:10:55
您可以编写这个场景,有点像这样:
Given the user launches the application
When user login with valid credentials
And navigates to required page
Then he should see the page datails在Then步骤中,您管理所有逻辑。
Then(/^he should see the page details$/) do
if condition
...
else
...
end
end发布于 2017-08-04 04:53:18
你不能在Gherkin实现。
Gherkin是关于沟通和那些你想要沟通的人,非编码者,不知道什么是if语句。他们也不在乎。
解决方案是什么?这两种情况都包括在内。
发布于 2017-08-01 10:09:53
理想情况下,这一级别的细节不会出现在Gherkin场景中。最好的方法是描述业务用例,而不是低层次的细节。这就是Gherkin设计的目的:与非技术利益相关者进行沟通,这样您就可以确定您是否正在构建正确的东西。以下是我要写的内容:
Given the user is logged in
And the user is on the required page
When they enter data that requires the optional fields to be validated
And they enter invalid data in the optional fields
Then the form shows an error on the optional fields低级别的细节并不重要(字符串具体是"XYZ“,或者它是title字段并不重要),因此这些信息应该隐藏在步骤定义和/或单元测试中。
为了继续检查其他字段,只需在下面添加另一个步骤:
When they enter invalid data in all of the other fields
Then each other field has an error message attached to it.同样,不需要指定实际字段,也不需要将它们划分为自己的步骤。其思想是表达场景的高级业务价值,即表单应该在什么时候被验证。
保持较高水平的好处是,当表单发生变化(可能最终会发生)时,这个场景可以保持不变。这是正确的,因为业务用例是相同的:它应该在应该验证的时候进行验证。所有更改都将在步骤定义中进行。这意味着没有理由再与您的涉众讨论方案是否仍在测试正确的内容。
https://stackoverflow.com/questions/45434613
复制相似问题