📜 ⬆️ ⬇️

Watir - Automated testing tool. Installation and the first script.

Watir is a tool for automated testing of web applications in the Ruby language. Then I will tell you a little about Watir, how to install it and write a simple test script with it.


Watir works with Internet Explorer * on the Windows platform and allows you to automate web applications that are represented in the browser using HTML code. Watir does not work with ActiveX components, Java Applets, Macromedia Flash and other embedded applications.

* supports Internet Explorer 5.5, 6 and 7, Firewatir is required to support Firefox 2 and 3, as well as a plugin. Also works on Linux and Mac.
')
To use and install Watir, you will need installed Ruby and Ruby Gems. Also useful is Internet Explorer Developer Toolbar.

Install Ruby

We take Ruby 1.8.6 One-Click Installer from here , we start and we install - at installation we necessarily select the item - Enable Ruby gems and, if desired, SciTE. SciTE is a text Ruby editor.

Install Watir

After the successful installation of Ruby, open a command prompt and enter the following *:
gem update –-system
gem install watir


* If a proxy server is used to connect to the Internet, each command must contain the following key:
-p http://[__]:[]
Example:
gem update –-system -p proxy.com:3128


If the installation was successful, the result should be displayed lines that do not contain error messages. Something like this:
C:\Documents and Settings\Administrator\>gem install watir
Successfully installed watir-1.6.2
Installing ri documentation for watir-1.6.2...
Installing RDoc documentation for watir-1.6.2...


Install Internet Explorer Developer Toolbar

Internet Explorer Developer Toolbar will be very useful for working with Watir, as it can easily display the attributes and properties of page elements.
Steps:
  1. Download the Internet Explorer Developer Toolbar from here.
  2. Run the downloaded IEDevToolBarSetup.msi and install it.


To test the operation of the Internet Explorer Developer Toolbar, launch IE and enable the toolbar - View - Explorer Bar - IE Developer Toolbar (for IE 7).

Something like this will appear:
image
Fig. 1 Internet Explorer Developer Toolbar

We write the first script

As can be seen from the previous screenshot, the highlighted item - the search string - has the attribute name = q. It can be used.

Steps:
  1. Create a file with a .rb extension, for example, google.rb
  2. Open the file with a text editor. You can use the editor provided with Ruby - SciTE, you can use Notepad or another text editor, or you can integrate Ruby with any development environment, for example, NetBeans
  3. To use Watir in the code, you must connect it:
    Require 'watir'
  4. Next, perform a simple search using the following code:

Full code:
require 'watir'
google = "http://google.ru"

puts " 1. ."

#
ie = Watir::IE.new

# Google
ie.goto google

# "habrahabr.ru"
ie.text_field(:name, "q").set "habrahabr.ru"

# - Google
ie.button(:name, "btnG").click

puts " :"
# ""
if ie.text.include? ""
puts " - "
else
puts " - :-("
end

#
ie.close


Run the script

Launch options:
  1. If you used the SciTE editor, then pressing F5 , while working in it, you run the script.
  2. You can also run the script from the command line:
    ruby [__rb____]
    Example:

    ruby C:\google.rb


We start and ... as you can see, the test is successful :-)

References:

http://wiki.openqa.org/display/WTR/Tutorial - detailed tutorial
http://ru.wikibooks.org/wiki/Ruby - Ruby - Wikibooks

Source: https://habr.com/ru/post/52551/


All Articles