请允许我向您展示我在学校平台上进行的测试中的这一小段代码:
Background:
I Enter the school page
In Schools I navigate to:
| Hierarchical level | Action | Value |
| District | expand | District-A |
| School | right click | Saint John's |
And Choose "Go to" on the Popup Menu
And Zoom In To See More Options in Control Bar
所以你看,我使用这个背景在网站的小树中导航。 我的问题是,我可以不使用“A 区”和“圣约翰”这样的两个变量,例如“区”和“学校”,这样当我在命令行上运行测试时,我可以得到一些东西就像一个额外的参数说:我希望这轮测试将我的“区”设置为“B 区”,并将“学校”变量设置为学校之一。 首先,这可能吗? 其次,如果是的话,有人可以告诉我如何做到这一点吗?
提前非常感谢您-
最佳答案
在 Cucumber 中,你可以编写场景来描述你想要做的事情,也许还可以解释为什么它很重要。您不应该编写解释您如何做某事的步骤。任何涉及点击、展开等的步骤最终都会导致像您遇到的问题。
因此,首先要描述这个背景想要实现的目标,以及为什么它很重要。考虑如何操作并将其插入您的步骤定义和辅助方法中。完成此操作后,您可能会得到类似的结果
Scenario: View a school
Given there is a school
When I view the school
Then I should see the school
现在这可能看起来很简单,但这就是重点。您应该使您的网站易于使用。因此,您需要做的第一件事就是能够参观学校。有了这个之后,您可能想要与很多学校打交道,并考虑寻找一所特定的学校。然后你可能会得到类似的东西
Feature: Search for a school
We want to be able to find a particular school
Scenario: Find a school
Given there are lots of schools with one searchable
When I search for the school
Then I should see search results with one school
您可能会对地区采取类似的做法
Feature: Districts
Schools are organised by districts. We would like to view all the schools in a district
Scenario: View district
Given there is a district
When I view the district
Then I should see the district
Scenario: See schools in a district
Given there is a district
And the district has some schools
When I view the district
Then I should see some schools
等等...
请注意,这些场景都与页面、点击等无关。这都是“什么”和“为什么”,而不是“如何”。还要注意一切都变得多么简单。
关于java - 运行 cucumber 测试改变变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53770967/