无论如何,我可以每次运行相同的测试用例但使用不同的值吗?

问题描述:

我有一个测试用例来测试每天特定环境中的特定场景,这是由jenkins工作自动完成的。无论如何,我可以每次运行相同的测试用例但使用不同的值吗?

Scenario Outline: Verify a user can book 
Given I navigate to the "xxxxx" Page 
And I set the "Location" field with "<location>" value 
And I click on the "Search" button on "xxxxx" page 
Then I verify the "Results" page is displayed 
Examples: 
    | location | 
    |Boston | 

我需要在内部有20个地点的列表,每次执行测试情况下,如何改变一些的位置,可以是随机发货或以任何顺序,但总是在不断变化。 我正在使用黄瓜,水豚,当然还有红宝石

想一想吗?

+0

为什么不写下例子列表中的所有20个位置? –

+0

在这种情况下,它不会再是一个单一的测试用例,它将会是10个或任意数量的位置,我将拥有 – Pamela

+0

您试图在这里测试什么?数据的存在? –

黄瓜在被用作一种编程语言方面有很大的局限性。如果你把它移动到一个ruby文件中(黄瓜文件不是红宝石),做这种事情更容易。

一种选择是在内部调用这些其他步骤。有些人可能会说,最好从其他步骤中调用方法而不是步骤,但是如果您已经将步骤编写为步骤,那么这样做会更快,因为您不必重写代码转化为方法。最好在方法中编写测试代码,然后逐步调用它们,而不是将所有逻辑放在测试用例中。

黄瓜文件:

Scenario Outline: Verify a user can book 
    Given I navigate to the "xxxxx" Page 
    Then the search bar works 

红宝石文件:

Then /the search bar works/ do 
    locations = ["Boston", "Berkeley"].shuffle 
    locations.each do |location| 
    step %{I set the "Location" field with "#{location}" value} 
    step %{I click on the "Search" button on "xxxxx" page} 
    step %{I verify the "Results" page is displayed} 
    end 
end 

另一个原因,这可能被视为nonidiomatic是因为它的包装太多成一个单一的测试用例。但是我不确定一个好办法来解决这个问题,而不是简单地使用不同的硬编码值复制粘贴黄瓜文件中的原始步骤定义。

+0

考虑到测试要求的性质(我认为这是开始讨论的),我不觉得这种特别非惯用。 –

有可能

locations = ["Boston", ...] 
day_of_the_month = Date.new(2001,2,3).mday 
today_location = locations[(day_of_the_month - 1) % locations.count] 

我用- 1以来#mday回报整数第三行从1到31

+0

我试了一下,并改变了系统日期,以便能够看到它的工作,但它总是选择列表中的第一个选项“波士顿” – Pamela

+0

我的示例每天更改位置,而不是每月或每年。请看我的示例https://repl.it/KTFm/0 –