我有一个用javascript编写的测试设置,使用黄瓜和webdriverio。
我在我的功能文件中定义了我的测试场景: example1.feature 和 example2.feature
Mx example1.feature文件如下所示:
Feature: Submit search term
As a user who is logged in
I want to submit a search term
Because I want to see the search results
Background:
I am logged in
And I am on the search view
Scenario outline:
When I enter and submit the search term <someString>
Then I can see the results of <someString>
Examples:
|someString|
|bananas|
这很有效,我的变量被example1.page.js和example1.steps.js
选中现在我想在我的example2.feature中重用example1.feature(包括变量someString)中的这个Scenario Outline(以及例如3.feature,example4.feature,...)
我的example2.feature看起来像这样:
Feature: Navigate to details page
As a user who is logged in
I want to submit a search term
Because I want to see the details of my search term
Background:
I am logged in
And I am on the search view
Scenario outline:
When I enter and submit the search term <someString>
Then I can see the results of <someString>
When I click on the details
Then I get redirected to the details page
Examples:
|someString|
|bananas|
我尝试重用example1.page.js中的部分,但这会破坏我的测试。 example1既不运行也不运行example2。当我删除example2时,example1工作。我尝试删除和重命名(someString和香蕉);这是行不通的。
我想出解决这个问题的两种方法是复制整个部分 example1到example2(包括定位器和page.js中的部分) 或者在example1中包含example2(使example1更大)。
但是,因为我想在example3和。中重用这个代码部分 example4等等,我对复制一切都不满意 还是制作了一个巨大的测试案例...
有人能想出一个以更好的方式解决这个问题的解决方案吗?
答案 0 :(得分:0)
功能文件似乎没有正确格式化,这可能会解决问题。背景的第一步中缺少Given
(将其转换为背景说明),outline
应为大写:Scenario Outline:
希望这可以解决您的问题:
example1.feature:
Feature: Submit search term
As a user who is logged in
I want to submit a search term
Because I want to see the search results
Background:
Given I am logged in
And I am on the search view
Scenario Outline:
When I enter and submit the search term <someString>
Then I can see the results of <someString>
Examples:
|someString|
|bananas |
example2.feature
Feature: Navigate to details page
As a user who is logged in
I want to submit a search term
Because I want to see the details of my search term
Background:
Given I am logged in
And I am on the search view
Scenario Outline:
When I enter and submit the search term <someString>
Then I can see the results of <someString>
When I click on the details
Then I get redirected to the details page
Examples:
|someString|
|bananas |