首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cucumber Selenium Java运行场景概述了多个示例

Cucumber Selenium Java运行场景概述了多个示例
EN

Stack Overflow用户
提问于 2017-10-09 18:07:07
回答 3查看 8.8K关注 0票数 1

是否有人可以帮助我找到以下用例的解决方案:

目前,我正在使用Cucumber开发Selenium Automation,我有以下问题。

我需要在web应用程序中自动化场景。

代码语言:javascript
复制
Scenario Outline
Login as "<User>" and purchase items and checkout by selecting "<Option>".
Examples:
|User|
|Arun|
|Ajay|
|Ashok|
Examples
|Option|  
|one|
|two|
|Three|

在这里,我需要看到9次为每个用户运行相同的场景(选项3)。

我的意思是,当Arun登录时,他应该结帐并选择选项一(EG:他在没有输入说明的情况下下订单),然后再次Arun登录,应该结帐并选择选项二(这次他输入说明并下订单),然后再次arun登录为选择选项3 (EG:输入说明并选中某个复选框并下订单)。

对于Ajay和Ashok也需要重复这一点。我如何在Cucumber中实现这一点。我可以对单个场景大纲使用多个示例吗?

或者有没有可能在背景中有例子。

这是我需要自动化的重要用例之一,并在Cucumber中尝试了各种选项。但是什么都不起作用。

提前感谢

EN

回答 3

Stack Overflow用户

发布于 2017-10-09 18:33:23

您可以编写场景大纲,如下所示。这可能是有用的。

代码语言:javascript
复制
Scenario Outline: Login as <user> and Purchase item with the option <option>
When I login as <user>
And I enter the description <description> 
And I checkout the item using the option <option>

Examples:
|user|description|option|
|Arun |Some Desc|One  |
|Arun |         |One  |
|Arun |Some Desc|two  |
|Ajay |         |three|
|Ajay |Some Desc|two  |
|Ajay |Some Desc|three|
|Ashok|         |One  |
|Ashok|Some Desc|two  |
|Ashok|Some Desc|three|

这将使用不同的用户、描述和选项运行所有步骤。

票数 1
EN

Stack Overflow用户

发布于 2017-10-09 18:26:22

一个想法可能是这样的:

代码语言:javascript
复制
Scenario Outline: Login with purchase and checkout
  Given I am on the login page
  When I log in as "<User>"
  And I purchase items
  Then I can checkout using the "<Option>"

Examples:
| User | Option |
| Arun | one    |
| Arun | two    |
| Arun | three  |
| Ajay | one    |
| Ajay | two    |
| Ajay | three  |
| Ashok| one    |
| Ashok| two    |
| Ashok| three  |

这将为每个用户运行每个选项。我不知道你的代码是什么样子,但是使用上面的格式应该很容易适应。查看documentationhow to write good Gherkin

票数 0
EN

Stack Overflow用户

发布于 2017-10-09 23:43:50

你的步骤和场景大纲似乎做得太多了。

如果用户具有明显不同的权限,或者3个用户中的每个用户的结帐方法都发生了变化,那么当然,9个场景可能是测试所必需的,如果不是这样,您可能只需要编写3个场景来测试。

我写这个测试的方式是:

代码语言:javascript
复制
Background:
   Given I am logged in as "Arun"
     And I have gone to the checkout after selecting various products
   When I purchase the items

Scenario Outline: Checkout descriptions
   Then I should be able to checkout <with?> a description

 Examples:
   | with?   |
   | with    |
   | without |

Scenario: Checkout with description and accept the terms of service*
   Then I should be able to checkout with a description
     And I should be able to accept the terms of service*

*将“接受服务条款”替换为您选择复选框背后的含义。

小黄瓜在那里是为了弥合开发团队和业务之间的对话鸿沟,因此确保所使用的语言是非技术业务人员可以理解的是必不可少的。将实现细节留在功能文件之外,因为它都是关于描述系统行为的。

编辑

如果在其他两个用户之间运行测试确实有业务上的好处(并且它并不是单独运行来设置测试数据,这应该在之前的钩子中完成),那么您可能需要做更多这样的事情:

代码语言:javascript
复制
Scenario Outline: Checkout descriptions
   Given I am logged in as "<user>"
     And I have gone to the checkout after selecting various products
   When I purchase the items
   Then I should be able to checkout <with?> a description

 Examples:
   | user  | with?   |
   | Arun  | with    |
   | Ajay  | with    |
   | Ashok | with    |
   | Arun  | without |
   | Ajay  | without |
   | Ashok | without |

Scenario Outline: Checkout with description and accept the terms of service*
   Given I am logged in as "<user>"
     And I have gone to the checkout after selecting various products
   When I purchase the items
   Then I should be able to checkout with a description
     And I should be able to accept the terms of service*

 Examples:
   | user  |
   | Arun  |
   | Ajay  |
   | Ashok |
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46643884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档