Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 多次运行相同的cucumber场景_Ruby_Webdriver_Cucumber_Watir Webdriver - Fatal编程技术网

Ruby 多次运行相同的cucumber场景

Ruby 多次运行相同的cucumber场景,ruby,webdriver,cucumber,watir-webdriver,Ruby,Webdriver,Cucumber,Watir Webdriver,我尝试运行相同的场景大约1000次。我想测试的是,若我登录和注销n次,应用程序是否稳定。我想出了一个办法,但看起来不整洁。我还想为同一HTML中的1000次执行生成一个报告 这就是我所做的 黄瓜步骤: When I login "1000" number of times 在我的步骤中,定义是: successful_attempts = 0 unsuccessful_attempts = 0 attempt_login = attempt_login.to

我尝试运行相同的场景大约1000次。我想测试的是,若我登录和注销n次,应用程序是否稳定。我想出了一个办法,但看起来不整洁。我还想为同一HTML中的1000次执行生成一个报告

这就是我所做的

黄瓜步骤:

    When I login "1000" number of times  
在我的步骤中,定义是:

    successful_attempts = 0
    unsuccessful_attempts = 0
    attempt_login = attempt_login.to_i

    attempt_login.times do 

      visit_page(Login)

      on_page Login do |page|
        page.login_with username, password
        page.logout? ? (page.logout;successful_attempts+= 1) : unsuccessful_attempts+= 1
      end

    end

    puts "Total Attempts :  #{attempt_login}"
    puts "Successful Attempts : #{successful_attempts}"
    puts "Unsuccessful Attempts : #{unsuccessful_attempts}"

    fail if unsuccessful_attempts > 0

你的情况有点不寻常。如果是我,我会尝试使用,其中每个场景都包含一个名为“尝试”的参数,例如:

Scenario Outline: verify login 1000 times
  Given I am not logged in
  When I log in with attempt <attempt>
  Then ...

  Examples:
    | attempt |
    | 1       |
    | 2       |
    | ...     |
    | 1000    |

这样做的好处是,您可以清楚地报告尝试失败的原因,可能会保留不同的异常日志,并且1个失败的案例不会阻止其他案例。这样做的缺点是,您需要编写一些脚本来生成包含1000个数字的表。

在Cucumber中这样做有什么原因吗?对于Cucumber来说,这似乎是一个不寻常的用例。我有一个现有的自动化套件,其中包含200个测试用例,必须将其添加到套件中。。我知道这不是一个很好的情况,但我必须想出一个办法。很公平。你希望这份报告看起来怎么样?您希望在报告中看到每个登录尝试的一行还是一个摘要?事实上,任何事情都可以,我想出了上面的报告方法。好的。那么我不明白你的问题是什么。如果它已经起作用了,你为什么需要做一个改变呢?与
1000.times{i | put i}
的irb会话将为你生成数字……沿着这些思路的东西可能是你最好的解决方案。我会把这个场景放到它自己的功能文件中,因为它会有点难看,给它一个标签,这样你就可以自己运行它,或者根据需要包含/排除它。使用场景大纲肯定会让它看起来难看。缺点是我必须写1000行,如果用户必须增加尝试次数(比如将尝试次数增加到2000或更多),那么他/她将很难完成。这就是为什么我想出了上面的步骤,这样我就可以控制尝试的次数。
When(/^I log in with attempt (\d+)$/) do |attempt|
    ...
end