Below is a quick hello world example for google (I don't have your code, so can't properly do an example for your site).
The When
is what we are interested in really.
Given(/^I navigate to "([^"]*)"$/) do |url|
$driver.navigate.to url
end
When(/^I search for "([^"]*)"$/) do |search_term|
# Loop through 100 times
100.times do
# Clear any text present
$driver.find_element({css: 'input[name="q"]'}).clear
# Type in the request
$driver.find_element({css: 'input[name="q"]'}).send_keys(search_term)
# Fire the request with the return key
$driver.find_element({css: 'input[name="q"]'}).send_keys(:return)
# Give time for the process to complete before a reset (This could also go first)
sleep 1
end
end
Then(/^I (?:should|must) see some results$/) do
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { $driver.find_element({css: 'h3.r'}) }
end
Doing a for loop, like in the When
above, could also have a maximum set by a new captured integer:
When(/^I search for "([^"]*)" (\d+) times?$/) do |search_term, times|
# Loop through an amount of times
times.to_i.times do
$driver.find_element({css: 'input[name="q"]'}).clear
$driver.find_element({css: 'input[name="q"]'}).send_keys(search_term)
$driver.find_element({css: 'input[name="q"]'}).send_keys(:return)
sleep 1
end
end
This would mean that you don't have to dynamically set up capturing of previous steps (which is doable, I'm sure, but would be a giant amount of effort for what you seem to be wanting to do here).