如何在 Gherkin 中实现“if" [英] How to implement 'if' in Gherkin

查看:13
本文介绍了如何在 Gherkin 中实现“if"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Selenium 测试转换为 Gherkin.有没有办法在 Gherkin 中实现 if 语句?

I am trying to convert Selenium test to Gherkin. Is there way to implement if statements in Gherkin?

示例:假设代码以以下格式编写.我只是写如下描述.请理解双斜杠后的部分是实际的 Selenium 代码:​​

Example : assume the code is written in the below format. I am just writing description as below. Please understand the part after double slash is the actual Selenium code:

// 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 中编写如下代码

For this I am trying to write code in Gherkin as follows

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 和选择框等其他验证.

but this code is incorrect because if the str is not equal to "XYZ" we want that title should not be verified but other verification like text field1,2 and select box should be verified.

推荐答案

你可以写这个场景,有点像这样:

You can write the scenario, somewhat like this:

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 步骤中,您管理所有逻辑.

Inside the Then step you manage all the logic.

Then(/^he should see the page details$/) do
  if condition
    ...
  else
    ...
  end
end

这篇关于如何在 Gherkin 中实现“if"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆