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

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


    Watir works with Internet Explorer * browser on the Windows platform and allows you to automate web applications that are presented 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 as well as a plugin to support Firefox 2 and 3. Also works on Linux and Mac.

    To work and install Watir, you will need installed Ruby and Ruby Gems. Internet Explorer Developer Toolbar also comes in handy.

    Install Ruby

    We take Ruby 1.8.6 One-Click Installer from here , run and install - during installation, be sure to select the option - Enable Ruby gems and, if desired, SciTE. SciTE is a text ruby ​​editor.

    Installing Watir

    After Ruby successful installation, open a command prompt and enter the following *: * if you connect to the Internet using proxy-server, each team must contain the following key: Example: If the installation is successful, the result should be output lines that do not contain messages about mistakes. Something like this:
    gem update –-system
    gem install watir



    -p http://[имя_прокси_сервера]:[порт]

    gem update –-system -p proxy.com:3128



    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 show attributes and properties of page elements.
    Steps:
    1. Load the Internet Explorer Developer Toolbar here
    2. We start the loaded IEDevToolBarSetup.msi and install.


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

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

    Writing the first script

    As you can see from the previous screenshot, the highlighted element - the search bar - has the attribute name = q. It can be used.

    Steps:
    1. Create a file with the extension .rb, for example, google.rb
    2. Open the file using a text editor. You can use the editor provided with Ruby - SciTE, you can use a notepad or other text editor, or you can integrate Ruby with some development environment, for example, NetBeans
    3. To use Watir in the code, you must connect it:
      Require 'watir'
    4. Next, we 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 by pressing F5 , while working in it, you will 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 - Wikibook

    Also popular now: