Watir installation:
3. You should update gem by using command.
6. After successfully installation of watir and watir-webdriver run some below commands to verify installation.
Watirdriver exe:
Hope this is post help to set up and create first watir test script.
1. Download and install the latest Ruby version from link “Ruby”. Setup ruby bin folder path to system environment variables. After installation and setup path run command:
ruby -v
2. setup OK if you get ruby version as a message.
gem -v
3. You should update gem by using command.
gem update --system
4. Watir and watir-webdriver gems need to “ffi” gem, and it needs Ruby Installer Development Kit (DevKit). Download DevKit from link DevKit. and follow installation process as mentioned in url http://github.com/oneclick/rubyinstaller/wiki/Development-Kit
5. After DevKit successful installation, you need to install water and watir-webdriver by running following commands.
gem install watir
gem install watir-webdriver
6. After successfully installation of watir and watir-webdriver run some below commands to verify installation.
>irb
Below message should be displayed
DL is deprecated, please use Fiddle
irb(main):001:0>
>require "watir-webdriver"
Message “true” should be displayed
>browser = Watir::Browser.new :ff
Firefox browser should be open
here is example “Google.rb” of watir Unit Test script.
Above script is divided into three part “setup”, “testdown” and test_Google_search”
require 'watir'
gem "test-unit"
require "test/unit"
class Google < Test::Unit::TestCase
def setup
@browser = Watir::Browser.new :ff
@browser.goto "http://google.com"
end
def teardown
@browser.close
end
def test_Google_Search
@browser.a(:text => "Images").click
@browser.a(:text => "Maps").click
@browser.a(:text => "News").click
@browser.a(:text => "Search").click
@browser.text_field(:id => "gbqfq").set "book"
@browser.button(:name => "btnG").click
end
end
Above script is divided into three part “setup”, “testdown” and test_Google_search”
setup: setup method executed before any test method in script. In this method we put open browser functionality or any other which we need to perform before test method execution.
teardown: this method execute after test method so in this method we put browse close functionality or any other which we need to perform after test method execution.
test: we need to add test prefix for test method.
Browsers Watir driver:
Following are the watirdriver which we need to use in watir test script for particular browser.
Firefox:
browser = Watir::Browser.new :ff
Internet explorer:
browser = Watir::Browser.new :ie
Google chrome:
browser = Watir::Browser.new :chrome
Watirdriver exe:
If you are running your test scripts on google chrome then you need to download and setup path of “chromedriver.exe” driver. Best way to put this into folder “C:\Ruby192\bin”
Execution:
For test execution need to run using ruby command
ruby testScriptName
In my case after execution command prompt look like as below.
Hope this is post help to set up and create first watir test script.
Realy very nice post of ruby watir for be beginner. Thanks for such a great post...
ReplyDelete