{"id":28639,"date":"2019-11-23T07:23:28","date_gmt":"2019-11-23T07:23:28","guid":{"rendered":"https:\/\/www.softwaretestinghelp.com\/?page_id=28639"},"modified":"2025-04-01T08:03:54","modified_gmt":"2025-04-01T08:03:54","slug":"watir-tutorial","status":"publish","type":"page","link":"https:\/\/www.softwaretestinghelp.com\/watir-tutorial\/","title":{"rendered":"Getting Started With Watir: Web Application Testing In Ruby"},"content":{"rendered":"\n<p><strong>Watir is an Acronym for \u2018Web Application Testing In Ruby\u2019. Learn How to Install And Use Watir to Create And Run Test Cases With Code Examples:<\/strong><\/p>\n\n\n\n<p>Watir is pronounced as Water. It is an open-source collection of Ruby libraries. As it is the Web Application Testing In Ruby, it uses Ruby as its scripting language.<\/p>\n\n\n\n \n  \n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/watir-final.png\"><img decoding=\"async\" width=\"600\" height=\"300\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/watir-final.png\" alt=\"watir tutorial\" class=\"wp-image-28823\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/watir-final.png 600w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/watir-final-300x150.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Installation Of Watir<\/h3>\n\n\n\n<p>One should have basic knowledge of HTML, Programming, and Ruby to use Watir. However, as Ruby itself is easy to use and understand, learning it and using Watir is not that difficult.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">Watir Installation For Windows<\/span><\/h4>\n\n\n\n<p>There is a great chance that you don\u2019t have Ruby installed on your computer. To check that, open Command Prompt and type <strong>&gt;ruby \u2013v and press \u2018Enter\u2019<\/strong><span style=\"color: #ff6600;\"><strong>.<\/strong><\/span><\/p>\n\n\n\n<p><strong>Fig 1: If you don\u2019t have Ruby installed, you will get the following message.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/cmdprmt.png\"><img decoding=\"async\" width=\"500\" height=\"176\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/cmdprmt.png\" alt=\"Command Prompt - Ruby\" class=\"wp-image-28652\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/cmdprmt.png 500w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/cmdprmt-300x106.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/figure>\n\n\n\n<p>If Ruby is installed, you will get its version with this command. You can click <a href=\"https:\/\/rubyinstaller.org\/downloads\/\" target=\"_blank\" rel=\"noopener nofollow\">here<\/a> to download the latest version of Ruby. Select the appropriate version, the website itself will recommend Ruby <strong>2.4.X<\/strong>&nbsp;as x64 or x86 installer.<\/p>\n\n\n\n<p><strong>Fig 2: When you click on this version, you will get the following window.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/dwnlodruby.png\"><img decoding=\"async\" width=\"550\" height=\"182\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/dwnlodruby.png\" alt=\"Download Ruby\" class=\"wp-image-28653\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/dwnlodruby.png 550w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/dwnlodruby-300x99.png 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/figure>\n\n\n\n<p><strong>Fig 3: Click on the Start Download button and you will see the following window.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/dwnlodingruby.png\"><img decoding=\"async\" width=\"525\" height=\"264\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/dwnlodingruby.png\" alt=\"Start Downloading Ruby\" class=\"wp-image-28654\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/dwnlodingruby.png 525w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/dwnlodingruby-300x151.png 300w\" sizes=\"(max-width: 525px) 100vw, 525px\" \/><\/a><\/figure>\n\n\n\n<p>As the downloading process is paused for the purpose of taking a screenshot, you are able to see the <strong>\u2018Start\u2019<\/strong> button, otherwise, you will be able to see the <strong>\u2018Pause\u2019<\/strong> button here. Now go to the location\/folder where your file is downloaded (here as you can see in Fig 2, location is: <strong>C:\\Users\\Ojas\\Downloads\\Programs<\/strong>).<\/p>\n\n\n\n<p><strong>Fig 4: Execute the rubyinstaller-2.4.3-2-x64.exe file.&nbsp;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/executerubyexe.png\"><img decoding=\"async\" width=\"500\" height=\"393\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/executerubyexe.png\" alt=\"Ruby License Agreement\" class=\"wp-image-28655\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/executerubyexe.png 500w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/executerubyexe-300x236.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/figure>\n\n\n\n<p><strong>Fig 5: Select \u2018I accept the License\u2019 and click \u2018Next\u2019:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/nxtinstallpg.png\"><img decoding=\"async\" width=\"500\" height=\"384\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/nxtinstallpg.png\" alt=\"Accept License\" class=\"wp-image-28656\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/nxtinstallpg.png 500w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/nxtinstallpg-300x230.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/figure>\n\n\n\n<p><strong>Fig 6: Click Install and then Finish.&nbsp;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/cmddwnlod.png\"><img decoding=\"async\" width=\"550\" height=\"394\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/cmddwnlod.png\" alt=\"Install Ruby\" class=\"wp-image-28657\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/cmddwnlod.png 550w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/cmddwnlod-300x215.png 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/figure>\n\n\n\n<p>The above screen will ask \u2018Which components to be installed?\u2019 If you are not sure, just hit the Enter key and the system will install all the three components i.e. <strong>MSYS2 base installation, MSYS2 system update and MSYS2 and MINGW development toolchain<\/strong>.<\/p>\n\n\n\n<p>MSYS2 tools are necessary to compile C based ruby gems. MSYS2 can also be installed manually.<\/p>\n\n\n\n<p><strong>Fig 7: MSYS2 Installed Manually<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/installingmsy.png\"><img decoding=\"async\" width=\"500\" height=\"362\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/installingmsy.png\" alt=\"installingmsy\" class=\"wp-image-28658\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/installingmsy.png 500w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/installingmsy-300x217.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/figure>\n\n\n\n<p>It will take a few minutes to install all the components. Just close the Command Prompt and reopen it. Then type &gt;ruby \u2013v and hit the Enter key. If you get the following message then it means that Ruby is installed successfully.<\/p>\n\n\n\n<p><strong>ruby 2.4.3p205 (2017-12-14 revision 61247) [x64-mingw32]<\/strong><\/p>\n\n\n\n<p>Software that is written in Ruby is called Ruby Gems. We have installed Ruby but there is a possibility that we might not have the latest version of these Ruby Gems. Hence, first, we need to check this gem version using the command &gt;gem \u2013v, here we got the version 2.6.14.<\/p>\n\n\n\n<p>We will update it using the command:<\/p>\n\n\n\n<p><strong>&gt;gem update \u2013system<\/strong><\/p>\n\n\n\n<p>Once done we will get the message&#8211; <strong>RubyGems system software updated<\/strong>.<\/p>\n\n\n\n<p><strong>Now we need to install Selenium web driver gem using <\/strong>the command [&gt;gem install the selenium-web driver &#8211;no-ri &#8211;no-rdoc].<\/p>\n\n\n\n<p><strong>It will get installed and you will get the following message:<\/strong><\/p>\n\n\n\n<p>Fetching: selenium-web driver-3.11.0.gem (100%)<\/p>\n\n\n\n<p>Successfully installed selenium-web driver-3.11.0<\/p>\n\n\n\n<p>1 gem installed<\/p>\n\n\n\n<p><em>**If you get any Windows Firewall message, then close that window.<\/em><\/p>\n\n\n\n<p>Now we need IEDriverServer. Click <a href=\"http:\/\/selenium-release.storage.googleapis.com\/index.html\" target=\"_blank\" rel=\"noopener nofollow\">here<\/a> to Download IEDriverServer<\/p>\n\n\n\n<p>Click on the first link and then select the appropriate version for your computer i.e. Win32 or X64.Zip file will get downloaded. To know where to extract these files follow the below steps:<\/p>\n\n\n\n<p>Go to Command prompt.<\/p>\n\n\n\n<p><strong>Type &gt;PATH<\/strong><\/p>\n\n\n\n<p><strong>Fig 8<\/strong>: <strong>The following result will be obtained:&nbsp;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/path.png\"><img decoding=\"async\" width=\"600\" height=\"101\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/path.png\" alt=\"Type - PATH - Command Prompt\" class=\"wp-image-28659\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/path.png 600w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/path-300x51.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/figure>\n\n\n\n<p>We will extract our files to PATH<strong> C:\\Ruby24-x64\\bin<\/strong>. Extract files to your Ruby folder path. Now type irb in the command prompt and press ENTER. IRB stands for Interactive Ruby.<\/p>\n\n\n\n<p>&gt;require \u201cselenium-webdriver\u201d<\/p>\n\n\n\n<p><strong>You will get =&gt;true<\/strong><\/p>\n\n\n\n<p>&gt;browser = Selenium::WebDriver.for:internet_explorer<\/p>\n\n\n\n<p>Your IE browser will get open and you will see the message: <strong>\u201cThis is the initial start page for the WebDriver server\u201d<\/strong>.<\/p>\n\n\n\n<p>To open web page www.google.co.in in the IE browser type in the command:<\/p>\n\n\n\n<p><strong> &gt;browser. get \u201chttps:\/\/www.google.co.in\/\u201d<\/strong><\/p>\n\n\n\n<p>The following table will give you a list of drivers of the respective browsers and their download links. Follow the same procedure for the other drivers as well as explained for IEDriverServer.<\/p>\n\n\n\n<div id=\"tablepress-320-scroll-wrapper\" class=\"tablepress-scroll-wrapper\">\n<table id=\"tablepress-320\" class=\"tablepress tablepress-id-320 tablepress-responsive\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Browser Name<\/th><th class=\"column-2\">Driver Name     <\/th><th class=\"column-3\">Download Link<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">Firefox<\/td><td class=\"column-2\">geckodriver<\/td><td class=\"column-3\">https:\/\/github.com\/mozilla\/geckodriver\/releases<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">Google Chrome<\/td><td class=\"column-2\">chromedriver<\/td><td class=\"column-3\">http:\/\/chromedriver.storage.googleapis.com\/index.html<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">Safari<\/td><td class=\"column-2\">    &#8212;<br \/>\n<\/td><td class=\"column-3\">Safari does\u2019t work for windows<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<!-- #tablepress-320 from cache -->\n\n\n<p><strong>Watir Installation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to the command prompt.<\/li>\n\n\n\n<li>Type command &gt;gem install watir<\/li>\n\n\n\n<li>Hit the enter button.<\/li>\n<\/ul>\n\n\n\n<p>Watir will get installed. Now you can start using Watir.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">Watir Installation<\/span> <span style=\"color: #ff6600;\">For Mac<\/span><\/h4>\n\n\n\n<p><span style=\"color: #000000;\"><strong>Steps:<\/strong><\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Installing Ruby<\/li>\n\n\n\n<li>Installing Ruby gem<\/li>\n\n\n\n<li>Updating Ruby gem<\/li>\n\n\n\n<li>Installing Selenium WebDriver<\/li>\n\n\n\n<li>Installing IE Driver\/Gecko Driver\/Chrome Driver\/safari driver<\/li>\n\n\n\n<li>Installing Watir<\/li>\n<\/ul>\n\n\n\n<p>There is no need to install Ruby on Mac. Hence we have already covered the first step. It will save a lot of time. We will check the version of ruby with the command:&nbsp; <strong>$ruby -v<\/strong><\/p>\n\n\n\n<p><span style=\"color: #000000;\">Here, we have it as \u2014 <strong>ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]<\/strong><\/span><\/p>\n\n\n\n<p>Now we will check the version of ruby:&nbsp;<strong>gem&nbsp;$ gem -v<\/strong><\/p>\n\n\n\n<p>Here, it is \u2014 <strong><span style=\"color: #ff6600;\"><span style=\"color: #000000;\">2.0.14.1.<\/span> <\/span><\/strong>We will update our ruby gems using the command- <strong>$<\/strong> <strong>sudo gem update \u2014system.<\/strong> We will install Selenium WebDriver using the command: <strong>$sudo gem install selenium-webdriver \u2014no-ri \u2014no-rdoc<\/strong><\/p>\n\n\n\n<p>There is a possibility to get the following error while installing Selenium webdriver or updating the ruby gem.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #000000; text-decoration: underline;\"><strong>Error<\/strong>:<\/span><\/span> YAML safe loading is not available. Please upgrade the psych to a version that supports safe loading (&gt;= 2.0).<\/p>\n\n\n\n<p>To solve this error we need to update our Ruby. To update Ruby we will first require Ruby version manager, you can get it using this command <strong>[$ curl -L&nbsp;<a href=\"https:\/\/get.rvm.io\/\" target=\"_blank\" rel=\"noopener nofollow\">https:\/\/get.rvm.io<\/a>&nbsp;| bash -s stable]<\/strong>. To install the latest version of Ruby type <strong>[$ <\/strong>rvm<strong> install ruby -[version]]<\/strong>. Restart the terminal once the rvm is completely installed.<\/p>\n\n\n\n<p>Now we need to set this latest version as we want to use it. So type [$ rvm use ruby-2.4.1]. To set this version as the default one, use the following command: [$rvm \u2014default use 2.4.1]. Now again update ruby gems. Try installing selenium-webdriver. If you get any error again, then you might require command line developer tools, hence install it using [$ git \u2014version]. As we already have, we have not installed it here.<\/p>\n\n\n\n<p>To install the chrome driver, we need homebrew [$ ruby -e \u201c$(curl -fsSL <a href=\"https:\/\/raw.github.com\/mxcl\/homebrew\/go\/install)\" target=\"_blank\" rel=\"noopener nofollow\">https:\/\/raw.github.com\/mxcl\/homebrew\/go\/install)<\/a>\u201d].<\/p>\n\n\n\n<p>Let&#8217;s install the Chrome driver. [$ brew install chromedriver].<\/p>\n\n\n\n<p>Try this code in terminal:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$irb\n&gt;require \u201cselenium-webdriver\u201d\nYou will get &gt;true\nbrowser=Selenium::WebDriver.for:chrome\nbrowser.get \u201chttps:\/\/www.google.co.in\u201d<\/pre>\n\n\n\n<p>With this code, your browser should open with the specified webpage. Now we will install Watir: <strong>[$ gem install water].<\/strong><\/p>\n\n\n\n<p>We are done with the installation process. You can now start writing test scripts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How To Use Watir: Creation And Execution Of Test Cases<\/h3>\n\n\n\n<p>You can write the test cases or scripts in Notepad. Save this file with .rb extension.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong>Example:<\/strong><\/span> Suppose you have created one file test.rb. To run this script\/program double-click this file or follow the steps listed below. Suppose you have saved this file in the C drive. The address of this file is <strong>\u201cC\\Ruby_Programs\u201d.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;cd\\\n&gt;cd Ruby_Programs\n&gt;ruby test.rb<\/pre>\n\n\n\n<p>Hit the ENTER button. To edit this file, right-click on this file and select the option Open with.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">#1) Running Test Cases In Parallel<\/span><\/h4>\n\n\n\n<p>If you have written two test cases and saved them as test1.rb and test2.rb. To run these two tests in parallel, you need to follow these steps:<\/p>\n\n\n\n<p><strong>Fig.9:<\/strong> Go to the command prompt and type<strong> [&gt;gem install parallel_tests]. <\/strong>You will see the following message.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/parallel_testgeminstall.png\"><img decoding=\"async\" width=\"600\" height=\"291\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/parallel_testgeminstall.png\" alt=\"parallel_test gem install\" class=\"wp-image-28665\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/parallel_testgeminstall.png 600w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/06\/parallel_testgeminstall-300x146.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/figure>\n\n\n\n<p>Then run your tests.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;parallel_test test1.rb test2.rb<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">#2) Creating Test Suite<\/span><\/h4>\n\n\n\n<p>If you want a few tests to run frequently and add them in the test suite then here is the code for it.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline; color: #000000;\"><span style=\"text-decoration: underline;\"><strong>Code:<\/strong><\/span><\/span><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\nrequire 'minitest\/autorun'\nrequire 'C:\/Ruby_Programs\/test3' # This is the path of your test file which you want to include.\nrequire 'C:\/Ruby_Programs\/test4' # This is the path of your test file which you want to include.\n<\/pre><\/pre>\n\n\n\n<p>Save this file as testSuite.rb and run<\/p>\n\n\n\n<p><strong>C:\\Ruby_Programs&gt;ruby testSuite.rb<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Watir Examples<\/h3>\n\n\n\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #ff6600; text-decoration: underline;\"><strong>Example 1:<\/strong><\/span><\/span><\/p>\n\n\n\n<p>As this is our first program we will just open the \u201cGoogle.co.in\u201d web page and click on the Gmail link.<\/p>\n\n\n\n<p><strong>Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\nrequire 'watir'\ntest_site = &amp;amp;quot;https:\/\/www.google.co.in\/&amp;amp;quot;\nbrowser = Watir::Browser.new:firefox\nbrowser.goto test_site\nbrowser.link(:href, &amp;amp;quot;https:\/\/mail.google.com\/mail\/?tab=wm&amp;amp;quot;).click\nputs \u201cTest Executes\u201d\nbrowser.close\n<\/pre><\/pre>\n\n\n\n<p><strong>Understanding The Code<\/strong><\/p>\n\n\n\n<p>#1) require &#8216;watir&#8217; # Here we are telling that we will require Watir library to run our program and it will get loaded with this statement.<\/p>\n\n\n\n<p>#2) test_site = \u201chttps:\/\/www.google.co.in\/\u201d # Here we are declaring the variable.<\/p>\n\n\n\n<p>#3) browser = Watir::Browser.new:firefox # Here we are opening the Firefox browser.<\/p>\n\n\n\n<p>Watir::Browser.new:internet_explorer # For Internet Explorer<\/p>\n\n\n\n<p>Watir::Browser.new:safari # For Safari<\/p>\n\n\n\n<p>#4) browser.goto test_site # Or browser.goto \u201chttps:\/\/www.google.co.in\/\u201d # goto command is used to navigate to the specified website.<\/p>\n\n\n\n<p>#5) browser.link(:href, &#8220;https:\/\/mail.google.com\/mail\/?tab=wm&#8221;).click # Here we click the Gmail link. The hyperlink is referred as a link in the code and we are using its \u201chref\u201d property to locate this hyperlink.<\/p>\n\n\n\n<p>#6) puts \u201cTest Executed\u201d # This line will write the string \u201cTest Executed\u201d on the command prompt.<\/p>\n\n\n\n<p>#7) browser.close # This line will close the browser.<\/p>\n\n\n\n<p>If we don&#8217;t mention the browser names, then we will write only this line in our code [Watir::Browser.new], Watir will open the Chrome browser as Chrome is the default browser for Watir.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline; color: #ff6600;\"><strong>Example 2:<\/strong><\/span><\/p>\n\n\n\n<p>In this example, we will open the web page www.google.co.in. Then we will search the text \u201cManual Testing\u201d. Next, we will come back to the home page and click the \u201cGmail\u201d link.<\/p>\n\n\n\n<p><strong>Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\nrequire 'watir'\nbrowser=Watir::Browser.new:firefox\nbrowser.goto &amp;amp;quot;https:\/\/www.google.co.in&amp;amp;quot;\nif browser.title.include? &amp;amp;quot;Google&amp;amp;quot;\nbrowser.text_field(:class, &amp;amp;quot;gsfi&amp;amp;quot;).set &amp;amp;quot;Manual Testing&amp;amp;quot;\nbrowser.button(:name, &amp;amp;quot;btnK&amp;amp;quot;).click\nif browser.text.include? &amp;amp;quot;Manual Testing is a process of finding out the defects&amp;amp;quot;\nputs &amp;amp;quot;Title of webpage &amp;amp;quot;+ browser.title\nbrowser.img(:src, \u201c\/images\/branding\/googlelogo\/2x\/googlelogo_color_120x44dp.png&amp;amp;quot;).click\nbrowser.link(:class, &amp;amp;quot;gb_P&amp;amp;quot;).click\nelse\nputs &amp;amp;quot;Wrong result found&amp;amp;quot;\nend\nelse\nputs &amp;amp;quot;Either you are on wrong page or page not found&amp;amp;quot;\nend\nputs &amp;amp;quot;Now title of webpage &amp;amp;quot;+ browser.title\nbrowser.close\nputs &amp;amp;quot;Test Executed Successfully&amp;amp;quot;\n\n<\/pre><\/pre>\n\n\n\n<p><strong>Understanding the Code:<\/strong><\/p>\n\n\n\n<p>#1) browser.goto https:\/\/www.google.co.in &#8211; Here we are navigating to the specified website.<\/p>\n\n\n\n<p>#2) if browser.title.include? &#8220;Google&#8221; &#8211; Here we are checking the title of the webpage as whether it is as expected or not. In the else part of this \u2018If\u2019 we are putting this statement \u201cEither you are on the wrong page or page not found\u201d. This statement will get displayed on the command prompt.<\/p>\n\n\n\n<p>#3) browser.text_field(:class, &#8220;gsfi&#8221;).set &#8220;Manual Testing&#8221; &#8211; Here we are entering the text \u201cManual Testing\u201d in the search textbox.<\/p>\n\n\n\n<p>#4) browser.button(:name, &#8220;btnK&#8221;).click &#8211; Here we are clicking the \u201cGoogle Search\u201d button.<\/p>\n\n\n\n<p>#5) if browser.text.include? &#8220;Manual Testing is a process of finding out the defects&#8221; &#8211; Now we are checking the text on the webpage to verify if we got the correct search result. In the \u2018Else\u2019 part of this \u2018If\u2019 statement we are putting the statement \u201cWrong result found\u201d.<\/p>\n\n\n\n<p>#6) puts &#8220;Title of webpage &#8220;+ browser.title &#8211; Here we are displaying the title of the webpage on the command prompt.<\/p>\n\n\n\n<p>#7) browser.img(:src, &#8220;\/images\/branding\/googlelogo\/2x\/googlelogo_color_120x44dp.png&#8221;).click &#8211; Here we are clicking on the image to go back to the homepage.<\/p>\n\n\n\n<p>#8) browser.link(:class, &#8220;gb_P&#8221;).click &#8211; Here we are clicking the Gmail link.<\/p>\n\n\n\n<p>#9) puts &#8220;Now the title of webpage &#8220;+ browser.title &#8211; Now again we are putting the title of the webpage on the command prompt. It should be the title of the Gmail page.<\/p>\n\n\n\n<p>#10) browser.close &#8211; Here we are closing the browser.<\/p>\n\n\n\n<p>#11) puts &#8220;Test Executed Successfully&#8221;. Just to make sure that all the steps are executed correctly we are putting this statement on the command prompt.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline; color: #ff6600;\"><strong>Example 3:<\/strong><\/span><\/p>\n\n\n\n<p>In this example, we will try to use maximum Watir commands, so that you will understand how to use them. We will see its description as well along with the code.<\/p>\n\n\n\n<p><strong>Code with Comments:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\nrequire 'watir'\nbrowser=Watir::Browser.new:chrome\nbrowser.goto \u201chttp:\/\/watir.com\/examples\/forms_with_input_elements.html\u201d\n\n#Here we will see how to insert data in text field.\nt1=browser.text_field id: 'new_user_first_name'\nt1.set &amp;amp;quot;Testing&amp;amp;quot;\nt2=browser.text_field id: 'new_user_last_name'\nt2.set \u201ctestdata&amp;amp;quot;\n\n#Here we will see how to select data from select list.\nsl=browser.select_list id: 'new_user_languages'\nsl.select 'English'\nsl.selected_options\n\n#Here we will see how to select radio button.\nrd=browser.radio value: 'no'\nrd.set\nchk=browser.checkbox value: 'cars'\nchk.set\n\n#Here we will see how to click button.\nbtn=browser.button name: 'new_user_button_2'\nbtn.click\n\n#This is an Explicit wait statement. This statement will make the program wait #until the particular event happens.\nWatir::Wait.until {browser.text.include? 'submit'}\n\n# Here I used this if statement  because this is a test webpage and nothing is #happening after clicking the button. So just to show that button is clicked I used If #statement.\nif browser.text.include? &amp;amp;quot;submit&amp;amp;quot;\nputs &amp;amp;quot;Data Submitted&amp;amp;quot;\nelse\nputs &amp;amp;quot;Data not yet submitted&amp;amp;quot;\nend\n\n# This is an implicit wait statement. It will make your program to wait for 30 seconds compulsory.\nbrowser.driver.manage.timeouts.implicit_wait = 30\n\n# You can send special keys to browser. There is a big list of these keys.\nbrowser.send_keys :page_up\n\n#Here we are taking the screenshot and saving it in a png file.\nbrowser.screenshot.save \u2018screenshot1.png'\n\nbrowser.send_keys :page_down\nbrowser.screenshot.save \u2018screenshot2.png'\n\nputs &amp;amp;quot;TestCase Executed&amp;amp;quot;\nbrowser.close\n<\/pre><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Waits And Special Keys<\/h3>\n\n\n\n<p>There are two types of wait statements supported by Watir. First is an explicit wait and the second one is an implicit wait. We have seen the syntax for both in the above code i.e. Example 3.<\/p>\n\n\n\n<p>Special Keys supported by Watir: First, we will see the syntax for using these special keys.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>browser.send_keys :page_up #We have used this in our code.<\/li>\n\n\n\n<li>browser.element.send_keys [:control, \u2018c\u2019], :cancel<\/li>\n\n\n\n<li>browser.element.click(:enter, :space)<\/li>\n<\/ol>\n\n\n\n<p><strong>Following is a list of the special keys that are supported by Watir:<\/strong><\/p>\n\n\n\n<div id=\"tablepress-319-scroll-wrapper\" class=\"tablepress-scroll-wrapper\">\n<table id=\"tablepress-319\" class=\"tablepress tablepress-id-319 tablepress-responsive\">\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-1\">\n\t<td class=\"column-1\">:enter<br \/>\n<\/td><td class=\"column-2\">:f1<br \/>\n<\/td><td class=\"column-3\">:control<br \/>\n<\/td><td class=\"column-4\">:numpad0<br \/>\n<\/td>\n<\/tr>\n<tr class=\"row-2\">\n\t<td class=\"column-1\">:shift<\/td><td class=\"column-2\">:f2<br \/>\n<\/td><td class=\"column-3\">:alt<\/td><td class=\"column-4\">:numpad1<br \/>\n<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">:null<\/td><td class=\"column-2\">:f3<\/td><td class=\"column-3\">:pause<\/td><td class=\"column-4\">:numpad2<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">:cancel<\/td><td class=\"column-2\">:f4<\/td><td class=\"column-3\">:escape<\/td><td class=\"column-4\">:numpad3<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">:help<\/td><td class=\"column-2\">:f5<\/td><td class=\"column-3\">:space<\/td><td class=\"column-4\">:numpad4<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">:backspace<\/td><td class=\"column-2\">:f6<\/td><td class=\"column-3\">:end<\/td><td class=\"column-4\">:numpad5<br \/>\n<\/td>\n<\/tr>\n<tr class=\"row-7\">\n\t<td class=\"column-1\">:tab<\/td><td class=\"column-2\">:f7<\/td><td class=\"column-3\">:home<\/td><td class=\"column-4\">:numpad6<\/td>\n<\/tr>\n<tr class=\"row-8\">\n\t<td class=\"column-1\">:clear<\/td><td class=\"column-2\">:f8<\/td><td class=\"column-3\">:left<\/td><td class=\"column-4\">:numpad7<\/td>\n<\/tr>\n<tr class=\"row-9\">\n\t<td class=\"column-1\">:return<\/td><td class=\"column-2\">:f9<br \/>\n<\/td><td class=\"column-3\">:up<\/td><td class=\"column-4\">:numpad8<\/td>\n<\/tr>\n<tr class=\"row-10\">\n\t<td class=\"column-1\">:left_shift<\/td><td class=\"column-2\">:f10<\/td><td class=\"column-3\">:right<\/td><td class=\"column-4\">:numpad9<\/td>\n<\/tr>\n<tr class=\"row-11\">\n\t<td class=\"column-1\">:left_control<\/td><td class=\"column-2\">:f11<\/td><td class=\"column-3\">:down<\/td><td class=\"column-4\">:multiply<\/td>\n<\/tr>\n<tr class=\"row-12\">\n\t<td class=\"column-1\">:page_up<\/td><td class=\"column-2\">:f12<\/td><td class=\"column-3\">:insert<\/td><td class=\"column-4\">:add<\/td>\n<\/tr>\n<tr class=\"row-13\">\n\t<td class=\"column-1\">:page_down<\/td><td class=\"column-2\">:meta<\/td><td class=\"column-3\">:delete<\/td><td class=\"column-4\">:subtract<\/td>\n<\/tr>\n<tr class=\"row-14\">\n\t<td class=\"column-1\">:arrow_left<\/td><td class=\"column-2\">:command<\/td><td class=\"column-3\">:equals<\/td><td class=\"column-4\">:divide<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<!-- #tablepress-319 from cache -->\n\n\n<h3 class=\"wp-block-heading\">Regression Testing With Watir<\/h3>\n\n\n\n<p>In regression testing, we check if the changes have affected the unchanged part or not.<\/p>\n\n\n\n<p>For that, we need to rerun our previous test cases. Regression testing will be time-consuming if done manually. Watir is one of the best regression testing tools as writing, maintaining\/updating and executing test cases are easy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>To conclude, we can say that Watir is easy to learn the tool. It is an open-source tool, hence it is cost-effective and easy to use. Although it doesn\u2019t have so many advantages over Selenium WebDriver, it is a better tool when compared with many other tools.<\/p>\n\n\n\n<p>It supports programming, hence it much better than other recording and playback tools. It is indeed one of the best regression testing tools.<\/p>\n\n\n\n<p><em><strong>Have you given a try to the Watir tool?<\/strong><\/em><\/p>\n\r\n\t\t\t<div id=\"daexthefup-container\"\r\n\t\t\t\tclass=\"daexthefup-container daexthefup-layout-stacked daexthefup-alignment-center\"\r\n\t\t\t\tdata-post-id=\"28639\">\r\n\r\n\t\t\t\t<div class=\"daexthefup-feedback\">\r\n\t\t\t\t\t<div class=\"daexthefup-text\">\r\n\t\t\t\t\t\t<h3 class=\"daexthefup-title\">Was this helpful?<\/h3>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<div class=\"daexthefup-buttons-container\">\r\n\t\t\t\t\t\t<div class=\"daexthefup-buttons\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-yes daexthefup-button daexthefup-button-type-icon\" data-value=\"1\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-up-cls-1{fill:#c9c9c9;}.thumb-up-cls-2{fill:#e1e1e1;}.thumb-up-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_up\">\r\n                        <path class=\"thumb-up-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-up-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"20\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,9.06l-.49-.1c-.81-.17-1.61.35-1.78,1.16l-5.3,11.74c-.17.81,3.16,1.61,3.97,1.78l1.96.41c.81.17,1.61-.35,1.78-1.16l2.18-10.27c.34-1.61-.7-3.21-2.31-3.56Z\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,20h-18.67c-.83,0-1.5.67-1.5,1.5v12c0,.83.67,1.5,1.5,1.5h16.27c.71,0,1.33-.5,1.47-1.21l2.4-12c.19-.93-.53-1.8-1.47-1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-no daexthefup-button daexthefup-button-type-icon\" data-value=\"0\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-down-cls-1{fill:#c9c9c9;}.thumb-down-cls-2{fill:#e1e1e1;}.thumb-down-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_down\">\r\n                        <path class=\"thumb-down-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-down-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"13\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,38.94l-.49.1c-.81.17-1.61-.35-1.78-1.16l-5.3-11.74c-.17-.81,3.16-1.61,3.97-1.78l1.96-.41c.81-.17,1.61.35,1.78,1.16l2.18,10.27c.34,1.61-.7,3.21-2.31,3.56Z\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,28h-18.67c-.83,0-1.5-.67-1.5-1.5v-12c0-.83.67-1.5,1.5-1.5h16.27c.71,0,1.33.5,1.47,1.21l2.4,12c.19.93-.53,1.8-1.47,1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-comment\">\r\n\t\t\t\t\t<div class=\"daexthefup-comment-top-container\">\r\n\t\t\t\t\t\t<label id=\"daexthefup-comment-label\" class=\"daexthefup-comment-label\"><\/label>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-container\">\r\n\t\t\t\t\t\t\t\t<div id=\"daexthefup-comment-character-counter-number\"\r\n\t\t\t\t\t\t\t\t\tclass=\"daexthefup-comment-character-counter-number\"><\/div>\r\n\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-text\"><\/div>\r\n\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<textarea id=\"daexthefup-comment-textarea\" class=\"daexthefup-comment-textarea\"\r\n\t\t\t\t\t\t\t\tplaceholder=\"Type your message\"\r\n\t\t\t\t\t\t\t\tmaxlength=\"\r\n\t\t\t\t\t\t\t\t400\t\t\t\t\t\t\t\t\t\"><\/textarea>\r\n\t\t\t\t\t<div class=\"daexthefup-comment-buttons-container\">\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-submit daexthefup-button\">Submit<\/button>\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-cancel daexthefup-button\">Cancel<\/button>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-successful-submission-text\">Thanks for your feedback!<\/div>\r\n\r\n\t\t\t<\/div>\r\n\r\n\t\t\t","protected":false},"excerpt":{"rendered":"<p>Watir is an Acronym for \u2018Web Application Testing In Ruby\u2019. Learn How to Install And Use Watir to Create And Run Test Cases With Code Examples: Watir is pronounced as Water. It is an open-source collection of Ruby libraries. As it is the Web Application Testing In Ruby, it uses &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Getting Started With Watir: Web Application Testing In Ruby\" class=\"read-more button\" href=\"https:\/\/www.softwaretestinghelp.com\/watir-tutorial\/#more-28639\" aria-label=\"Read more about Getting Started With Watir: Web Application Testing In Ruby\">Read more<\/a><\/p>\n","protected":false},"author":9,"featured_media":28823,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_helpful_pro_status":1,"footnotes":""},"categories":[572],"tags":[],"class_list":{"0":"post-28639","1":"page","2":"type-page","3":"status-publish","4":"has-post-thumbnail","6":"category-framework"},"acf":[],"_links":{"self":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/28639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/comments?post=28639"}],"version-history":[{"count":0,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/28639\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media\/28823"}],"wp:attachment":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media?parent=28639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/categories?post=28639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/tags?post=28639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}