CucumberJS 和 Selenium Webdriver - 运行 不同输入的相同步骤
CucumberJS and Selenium Webdriver - Run same steps with different inputs
我从 Cucumber 和 Selenium 开始。
我创建了一个测试用例,其中 selenium 运行 是一个表单并输入默认值,然后单击默认按钮,我们称之为 test case 1
,但现在我需要 test case 2
,我应该 运行 相同的步骤,但输入不同,想象一下:
我有一个表格,如果用户是 男性 或 女性,则取决于点击的按钮,我的表格发生了变化,所以如果我选择 Male,我会得到一个输入,询问我是否 "tall"(只是一个例子),但是如果我选择 Female,我收到一个询问是否 "I have a boyfriend" 的输入。根据我在表格上的旅程,最终结果会有所不同,考虑到这一点:
如何在不重复代码的情况下创建多个测试用例来测试每个选项?
示例:
Test case A: Male Input
Test case B: Female Input
我需要测试用例A来完成表单,接下来执行测试用例B,请记住我的表单在两种情况下都有相同的输入,所以我将不得不多次使用相同的:
Scenario A:
Given I have to choose Male or Female
When I click ('one of them')
Then I will click other stuff
这可能吗?
欢迎使用 Whosebug!
场景大纲最适合您的场景。
Scenario Outline: Validate Selection
Given I am in the required page
When I selection <choice> from the option
Then I will click other stuff
Examples:
|choice|
|Male |
|Female|
此处文档中的最佳示例。 Link
Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
我从 Cucumber 和 Selenium 开始。
我创建了一个测试用例,其中 selenium 运行 是一个表单并输入默认值,然后单击默认按钮,我们称之为 test case 1
,但现在我需要 test case 2
,我应该 运行 相同的步骤,但输入不同,想象一下:
我有一个表格,如果用户是 男性 或 女性,则取决于点击的按钮,我的表格发生了变化,所以如果我选择 Male,我会得到一个输入,询问我是否 "tall"(只是一个例子),但是如果我选择 Female,我收到一个询问是否 "I have a boyfriend" 的输入。根据我在表格上的旅程,最终结果会有所不同,考虑到这一点:
如何在不重复代码的情况下创建多个测试用例来测试每个选项?
示例:
Test case A: Male Input
Test case B: Female Input
我需要测试用例A来完成表单,接下来执行测试用例B,请记住我的表单在两种情况下都有相同的输入,所以我将不得不多次使用相同的:
Scenario A:
Given I have to choose Male or Female
When I click ('one of them')
Then I will click other stuff
这可能吗?
欢迎使用 Whosebug!
场景大纲最适合您的场景。
Scenario Outline: Validate Selection
Given I am in the required page
When I selection <choice> from the option
Then I will click other stuff
Examples:
|choice|
|Male |
|Female|
此处文档中的最佳示例。 Link
Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |