WatirGrid

25
WatirGrid Parallel testing with Watir

description

An intro to testing in parallel with WatirGrid

Transcript of WatirGrid

Page 1: WatirGrid

WatirGridParallel testing with Watir

Page 2: WatirGrid

About

In 2007, WatirGrid was created by Dane Avilla (brilliant!)

In 2009, I packaged it as a gem , gave it a domain

watirgid.com and have since maintained it …

Tim Koopmans

@90kts

taking the FUD out of performance and test automation...

Page 3: WatirGrid

If Watir is …

Page 4: WatirGrid

WatirGrid is …

Page 5: WatirGrid

WatirGrid

Takes all the advantages of Watir …

And multiplies its use in a distributed,

parallel and coordinated fashion…

In other words “1 test case, many browsers”

//todo

Page 6: WatirGrid

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.

I, [2011-03-24 13:45:06 #1057] INFO -- :

DRb server started on : druby://192.168.1.6:50600

I, [2011-03-24 13:45:06 #1057] INFO -- :

Ring server started on: druby://192.168.1.6:7647

Page 7: WatirGrid

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}

Page 8: WatirGrid

WatirGrid is Coordinated

Based on Rinda, the Ruby version of Linda

Linda is a model of coordination and communication

among several parallel processes operating upon objects

stored in and retrieved from shared, virtual, associative

memory. [1]

[1] Markoff, John (January 19, 1992). "David Gelernter's Romance With Linda". The New York Times.

Page 9: WatirGrid

WatirGrid is Free

Uses the BSD license[1]

[1] https://github.com/90kts/watirgrid/raw/master/LICENSE

Page 10: WatirGrid

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.

Page 11: WatirGrid

Controller + Providers

Page 12: WatirGrid

= the Grid

A loosely coupled, distributed workforce …

Page 13: WatirGrid

A Canned Example # 1

If you haven‟t already …

Something simple …

gem install watirgrid

require 'watirgrid'

# Start a Controller

controller = Controller.new

controller.start

# Start a Provider with SafariWatir

provider = Provider.new(:browser_type => 'safari')

provider.start

# Create a Grid

grid = Watir::Grid.new

grid.start(:take_all => true)

Page 14: WatirGrid

What Just Happened?

Started a Controller

DRb server was started on a random port

A Rinda Ring Server was started on port 7647

Started 1 Provider (using SafariWatir)

DRb server started on a random port

The Ring Server was found on port 7647

A browser “tuple” was registed on the Ring Server

INFO -- : DRb server started on : druby://192.168.1.6:51163

INFO -- : Ring server started on: druby://192.168.1.6:7647

INFO -- : DRb server started on : druby://192.168.1.6:51164

INFO -- : Ring server found on : druby://192.168.1.6:7647

INFO -- : New tuple registered : druby://192.168.1.6:7647

Page 15: WatirGrid

What Just Happened?

Created a Grid

We can see the previously registered tuple

represented as a hash. We‟ll be using the „front

object‟ provided …

>> pp grid.browsers.first

{:uuid=>"235fa1f0-37fd-012e-5bac-78ca394083a0",

:browser_type=>"safari",

:class=>:WatirProvider,

:hostname=>"air.local",

:object=>#<Watir::Provider:0x10166a240 @browser=Watir::Safari>,

:name=>:WatirGrid,

:architecture=>"universal-darwin10.0",

:description=>"A watir provider"}

Page 16: WatirGrid

Let‟s Use the Grid!

Take the first (and only) browser on the grid

and execute some Watir …# Take the first browser on the grid and execute some Watir

b = grid.browsers.first[:object].new_browser

b.goto "http://altentee.com"

b.close

Page 17: WatirGrid

A Canned Example # 2

Let‟s try with 2 providers …

require 'watirgrid'

# Start a Controller using defaults

controller = Controller.new

controller.start

# Start 2 Providers with WebDriver

2.times do

provider = Provider.new(:browser_type => 'webdriver')

provider.start

End

# Start another Grid

grid = Watir::Grid.new

grid.start(:take_all => true)

Page 18: WatirGrid

Let‟s Use the Grid!

Take all browsers on the grid in parallel using

Threads …browser_types = [:firefox, :chrome]

threads = []

grid.browsers.each_with_index do |browser, index|

threads << Thread.new do

b = browser[:object].new_browser(browser_types[index])

b.goto "http://altentee.com"

sleep 5

b.close

end

end

threads.each {|thread| thread.join}

Page 19: WatirGrid

Let‟s all Try .. 1

I‟ll start a new Controller on port 12358

require 'watirgrid'

# Start a Controller on port 12358

controller = Controller.new(:ring_server_port => 12358)

controller.start

Page 20: WatirGrid

Let‟s all Try .. 2

You start a Provider and register on my

Controllerrequire 'watirgrid'

provider = Provider.new(

browser_type => ‟firefox', # or ie, safari ...

:ring_server_port => 12358)

provider.start

Page 21: WatirGrid

Let‟s all Try .. 3!

See if I can control the grid …

require 'watirgrid'

# Start another Grid

grid = Watir::Grid.new

grid.start(:take_all => true)

threads = []

grid.browsers.each do |browser|

threads << Thread.new do

b = browser[:object].new_browser

b.goto("http://www.google.com")

b.text_field(:name, 'q').set("watirgrid")

b.button(:name, "btnI").click

b.close

end

end

threads.each {|thread| thread.join}

Page 22: WatirGrid

Security Considerations

$SAFE = 1

- poor man‟s paranoia

- on latest branch

ACLs

HTTPS

- not yet implemented

# Start a Controller with Access Control Lists

controller -a deny,all,allow,127.0.0.1 -H 127.0.0.1 -h 127.0.0.1

Page 23: WatirGrid

Performance

Considerations

Yes, but does it scale? 50..n

Ruby threads 1.8 vs. native threads 1.9, truly parallel?

Garbage collection cleaning up referenced objects!

Memory footprint of Controller? 100 Providers = 20MB

Page 24: WatirGrid

What‟$ Next?

GRIDinit.com => a commercial

implementation of WatirGrid on

different cloud providers.

Private alpha April – May,

Public beta June

[email protected]

to participate …

Page 25: WatirGrid

Questions?About WatirGrid that is …