运行黄瓜测试更改变量?

时间:2018-12-13 22:27:22

标签: java selenium cucumber

请允许我向您展示我在学校平台上进行的测试中的一小段代码:

  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

因此,您看到了,我使用此背景来浏览网站上的一棵小树。 我的问题是,我可以代替“ District-A”和“ Saint John's”这两个变量吗,例如“ district”和“ school”,这样我可以在命令行上运行测试时就像一个额外的参数这样说:我希望这一轮测试将我的“区”设置为“区B”,并让“学校”变量成为学校之一。  首先,这有可能吗? 第二,如果可以的话,有人可以给我一个快速的想法,我该怎么做吗?

非常感谢您-

1 个答案:

答案 0 :(得分:1)

在黄瓜中,您编写了一些方案来描述您要尝试做的事情,并可能解释其重要性的原因。您不应编写解释您如何做某事的步骤。任何有关单击,扩展等的步骤最终都会导致出现您遇到的问题。

因此,第一件事是描述此背景要实现的目标以及其重要性。在考虑如何操作之后,将其下推到步骤定义和辅助方法中。完成此操作后,您可能会遇到类似

的问题
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

您可能会对Districts采取类似的做法

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

依此类推...

请注意,这些方案在页面,单击等方面都没有任何用处。这都是什么,为什么不怎样。还要注意一切都简单得多。