Skip to content

Instantly share code, notes, and snippets.

@SadPandaBear
Last active October 27, 2017 13:23
Show Gist options
  • Save SadPandaBear/7058838717a47940464472359b293cbf to your computer and use it in GitHub Desktop.
Save SadPandaBear/7058838717a47940464472359b293cbf to your computer and use it in GitHub Desktop.

Watir

What is WATIR?

Web Application Testing In Ruby

It's a library for the Ruby language which simulates users actions on major web browsers.

Examples:

  • Link clicking;
  • Form submitting;
  • Buttons pressed.

Watir can also check what is expected for determined data on the page (like searching for texts in determined HTML text boxes).

It can be used on all types of web applications (ASP.Net, JSP, PHP, Rails, etc...);

Open source project

What WATIR is not:

Watir is not a record/playback tool, although there are many dependencies on it that actually supplies such behavior;

Watir is not a link checker/validator;

Watir doesn't work with Flash;

What is Ruby?

  • Full featured Object Oriented language;
  • Interpreted rather than compiled;
  • Written in C.

How does WATIR works?

Watir mostly uses Selenium for browser automation, but also provides many more high level features that make it easy to write stable, maintainable tests.

Test Runner –> 
    Test code –> 
        PageObject code –> 
                Watir code –> 
                    Selenium code –> 
               		    Browser Driver –> 
                	        Browser

1. Test Runner: The platform the Ruby apps are going to be run through. The most popular one is RSpec, but Cucumber gets a noticiable attention from teams that are working in a BDD environment.

2. Test Code: Here, the code blocks are being focused by the testing tool. This level what is the code is referencing to the page elements (called Page Objects) readed by Watir.

3. Page Object: This is the "how" part from the testing part. A Page Object can be any element from a set of a page, or subset of a page (like a sidebar or a footer). PageObjects are compromised on two things, the elements with their own locators and selectors and the representation of actions that users might take on the page. Most of this code will be references to Watir objects.

4. Watir Code: Watir is designed for the "Automation" part from all the driven flux. The library takes every information provided by the code blocks on the tests and the references they have within Page Objects and turns them into series of Selenium and JavaScript events to accomplish the actions. Tipically, the code on these events follows a philosophy of "Do What I Mean".

5. Selenium Code: Selenium is the guy behind the Watir library. It takes the focus on the lowest levels that actions will work on a browser. It implements a small number of selectors that have the "Do What I Say" approach. It translates Ruby code from Watir into JSON for further processing.

6. Browser Driver: The driver is an executable file that lives on the same machine as the browser that is being automated. The driver takes the information from Selenium code and turns it into code for the particular browser the test is being specified.

7. Browser: The browser executes every command passed through the driver and reports the testing tool about the results.

Why Watir?

Scripting with Watir is simple and intuitive, it means you don't need to be a developer to write them;

Ruby is far way expressive and Testers do not need to spend time and space assigning data-types and compiling. Auto testers need something up and running in a short space of time;

Which also means you're learning a robust programming language - not just a tool;

It has a better documentation and community than Selenium;

Extremely hackable, which means you can create your own framework for your customers to test their application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment