Tuesday, September 11, 2012

Grid Continued...


WatirGrid is Distributed

Built with standard DRb packages. Completely written in Ruby using core libraries.Lets you control Watir objects remotely with transmission passed by reference.

The standard Ruby library ships with a package known as DRb, it means Distributed Ruby. DRb is an incredibly easy package to learn and use. It has the benefits of being written completely in Ruby and using core libraries. It also offers advantages such as automatic selection of object transmission (either pass by value or pass by reference), reasonable speed, and the ability to run on any operating system that runs Ruby. 

WatirGrid is Parallel

WatirGrid uses Threads to execute Watir test cases in parallel (sort of). Threads execute on remote Watir objects, offloading any processing overheads

threads = []
  grid.browsers.each_with_index do |browser, index|
    threads << Thread.new do
      ...
    end
  end
threads.each {|thread| thread.join}


Key Terminology

Controllers implements a repository of tuples (tuple space) that can be accessed concurrently. The controller hosts the ring server which advertises these tuples across a grid network. Typically you will host one controller on a central machine.

Providers make remote Watir objects available to the tuple space hosted by the ring server. Typically you will host one or many providers on your grid network, for example, each PC may become a single provider of a Watir tuple in the form of an Internet Explorer, Firefox or Safari browser object.

Example:

require 'watirgrid'
require 'pp'
# Start a Controller

controller = Controller.new
controller.start
# Start a Provider
provider = Provider.new(:browser_type => 'safari')
provider.start
grid = Watir::Grid.new
grid.start(:take_all => true)
pp grid.browsers.first
# Take the first browser on the grid and execute some Watir
browser = grid.browsers.first[:object].new_browser
browser.goto "http://google.com"
browser.close


Thursday, September 6, 2012

WatirGrid

WatirGrid allows for distributed testing across a grid network using Watir.WatirGrid allows a local client to control remote Watir objects in parallel, hosted by providers on a grid network, via a central controller.

The controller implements a repository of tuples (tuple space) that can be accessed concurrently. The controller also hosts a ring server which advertises these tuples across a grid network making it loosely coupled.
Typically you will host one controller on a central machine. You will normally connect to this controller via a contoller_uri. You can also find this controller by its ring server, using a UDP broadcast for the ring server port.
The providers make remote Watir objects available to the tuple space hosted by the controller. Typically you will host one or many providers on your grid network, for example, each PC may become a single provider of a Watir tuple in the form of an Internet Explorer, Firefox, Safari or WebDriver browser object.

WatirGrid IS

  • A lightweight, pure Ruby implementation of distributed computing using DRb and Rinda.
  • A simple way to control remote Watir objects in parallel.
  • Cross platform friendly and works on Windows, OSX or Linux.
  • Open source, you’re already looking in the right place if you want the source code.
  • WebDriver friendly, thanks to the wire protocol, WatirGrid happily runs with WebDriver implementations such as watir-webdriver and selenium-webdriver.

    More Coming soon...

Wednesday, September 5, 2012

Dealing With Browser Certificates


IE:

The watir documentation has a workaround for this:

my_browser.link(:id, "overridelink").click

Another solution for this is to use autoit to tab into the 'continue to website', saves having to add to website all the time

    autoit=WIN32OLE.new('AutoItX3.Control')
    i=1
    while i < 11 
        autoit.Send("{Tab}")
        i+=1
    end

    autoit.Send("{Enter}")

Firefox:

The Firefox driver properly handles untrusted certificates by default.

If you have a trusted certificate, but there is some other certificate error such as a hostname mismatch (eg. using a production certificate in test), you should do the following:

profile = Selenium::WebDriver::Firefox::Profile.new
profile.assume_untrusted_certificate_issuer = false
b = Watir::Browser.new :firefox, :profile => profile
The reason this is needed is explained here.

Chrome:

It is easy to ignore invalid Browser certificates in Google Chrome by passing a command line switch:

Watir::Browser.new :chrome, :switches => ['--ignore-certificate-errors']