cucumber · QA · rspec · Testing · watir

RSpec + Watir WebDriver

Installation:

1. Install Ruby

2. CMD>gem install watir-webdriver

3. CMD>gem install rspec

Code:

google_search.rb

require 'rubygems'
require 'watir-webdriver'

class Google
def search(browser,term,result)

if browser.downcase=="ie"
br= :ie
elsif browser.downcase=="ff"
br= :ff
elsif browser.downcase=="chrome"
br= :chrome
else
br= :ie
end

$ie=Watir::Browser.new br
$ie.goto("http://google.com")
$ie.text_field(:name,'q').set(term)
sleep 3
$ie.button(:name,'btnG').click
sleep 3
$result=$ie.text.downcase.include?(result)

$ie.close
end

end

googleSearch_spec.rb

require 'rubygems'
require 'rspec'
require 'google_search'

describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Raveendran","ruby")
$result.should eq(true)
end
end

describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Raveendran","wordpress")
$result.should eq(true)
end
end

describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Watir, Selenium,Cucumber highline","raveendran")
$result.should eq(true)
end
end

describe Google, "#Searchresult" do
it "returns the expected result in search result page" do
bowling = Google.new
bowling.search("chrome","Ruby highline","raveendran")
$result.should eq(true)
end
end

RUN THE RSPEC code:

1. Navigate to the folder where files available

>rspec googleSearch_spec.rb

 

OUTPUT:

It will launch Chrome browser and will execute the test cases. Finally You will get the output like,

Started ChromeDriver
port=4113
version=14.0.836.0
.Started ChromeDriver
port=4164
version=14.0.836.0
.Started ChromeDriver
port=4218
version=14.0.836.0
.Started ChromeDriver
port=4260
version=14.0.836.0
.

Finished in 77.28 seconds
4 examples, 0 failures

 

cucumber · cuRF

cuRF

cuRF – It will create Cucumber feature files with different set of test data.

Installation:

Usage:

  • Create multiple Cucumber Feature files with different set of TEST DATA.

Why it is needed?

  • Cucumber currently supports Keyword driven and TABLE structured data driven flows. The table structure data driven works perfectly within Scenario’s. But it doesn’t pass anything to ANTOHER scenario’s in same feature file.
  • To increase the data driven approach in cucumber, we are creating more feature files depends upon TEST data from user.

Steps for Demo:

  • Open main_feature.feature file
    • It has 2 scenario’s
    • Instead of TEST DATA it has the variable name such as,
      • number1
      • number2
      • total1
      • total2
  • These all variables should be unique
  • Open data.xls file
    • Here you need provide all headers. Header name is nothing but all the variable names without the symbol “@”
    • Keep the method name created? At last column.
    • Create the rows with TEST DATA
    • Save and Close the Excel file
    • Run the batch file named as “run.bat”
      • Open the folder named as “result_features”
        • Lot of new feature files created automatically with the different set of test data.