javascript - 重用功能文件中的变量(javascript、wdio、黄瓜)
问题描述
我有一个用 javascript 编写的测试设置,使用 cucumber 和 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(以及example3.feature,example4.feature,...)中重用来自example1.feature(包括变量someString)的这个场景大纲
我的 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 和香蕉);这没用。
我想出的解决这个问题的两种方法是将整个部分从示例 1 复制到示例 2(包括定位器和 page.js 中的部分)或将示例 2 包含在示例 1 中(使示例 1 更大)。
但是,由于我也想在 example3 和 example4 等中重用此代码部分,所以我既不喜欢复制所有内容,也不喜欢制作一个巨大的测试用例......
有人能想出一个更好的方法来解决这个问题吗?
解决方案
功能文件的格式似乎不正确,这可能会解决问题。Given
背景的第一步(将其转换为背景的描述)中缺少一个,outline
应该是大写的:Scenario Outline:
希望这可以解决您的问题:
示例1.功能:
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 |
推荐阅读
- c# - 使用非托管导出将字符串从 C# 返回到 C++ 返回数字
- c++ - 文件存在时,最新检查声称构建输入“丢失”
- opentk - OpenTK 识别 PS4v2 控制器(通过 USB)
- machine-learning - 创建基于 3 列的预测模型
- android - IntentService 使用 NativeScript 和 Angular 处理 FCM
- r - ggplot2中的分组条形图
- qt - 仅从 Qt 中的给定 MIME 类型(无文件本身)获取文件图标
- c - C - 检查系统是否是虚拟机的便捷方法?
- javascript - 在循环中将不同的变量值传递给事件处理程序
- python - PLY - 添加第二条类似行时出现解析错误