Way 1:
Feature File:
Scenario: Google
Given I am in Google Search page
When the user clicks on the next button
When clicks next
When selects Next
Then the title should be “Raveendran – Watir”
In your ruby file,
Given /^I am in Google Search page$/ do
puts “I am in google page”
end
When /^(?:the? )?(?:user? )?(?:clicks|selects)?(?: on? )?(?:the?)?(?: next?)?(?: button?)?$/i do
puts “The same script working for 3 step files 🙂 ”
end
Then /^the title should be (.*)$/ do |arg1|
#Code for verification
puts “It works”
end
Solution :
Only 1 step is enough Instead of 3 steps if it targets same script.
Way 2:
Feature File:
Scenario: Google
Given I have verified the result page
When nothing changed
Then the title should be “Raveendran – Watir”
In Your Ruby file,
Given /^I have verified the result page$/ do
Given “I am in Google Search page”
And “the user clicks on the next button”
And “clicks next”
And “selects Next”
And “the title should be “Raveendran – Watir””
end
When /^nothing changed$/ do
#Some Code
end
Then /^the title should be “([^\”]*)”$/ do |arg1|
#Some Code
end