1

I have a Webdriver test case written in Ruby as below, and I want to make it run for example 100 times:

require 'rubygems'
require 'selenium-webdriver'

$i = 0
$num = 100
while $i<$num do

  driver = Selenium::WebDriver.for :firefox

  driver.get "https://dev08-olb.nz.thenational.com/ib4b/app/login"
  # some other test which require $i to be incremental as unique ID
  driver.close

i++

end

It does like it.

Can you show me how to execute it as many time as I want?

Thanks.

4

1 回答 1

1

Not sure what you are trying to do here but try this

num = 100
num.times do |i|
   #INSERT YOUR BLOCK TO RUN HERE i will increment from 0..num  
end

if you want to specify a different number of times each time it is called I would create a method

def run_times(n)
  n.times do |i|
    #INSERT YOUR BLOCK TO RUN HERE
  end
end

Then you can call it with run_times 100

于 2013-10-16T15:10:41.210 回答