Skip to content
Browse files

Major overhaul and refactor

  • Loading branch information...
1 parent e7b2c66 commit 1bbc8cbc68ba3a72513fca3761fd6f7348740148 @90kts committed May 26, 2011
View
8 EXAMPLES.rdoc
@@ -21,7 +21,7 @@ This will bind the controller to your external facing interface and register the
e.g.
DRb server started on : druby://143.238.105.61:11235
Ring server started on: druby://143.238.105.61:12358
-
+
=== Start on specific interface or ports
To start a controller on specific interfaces or ports:
$ controller -H 127.0.0.1 -h 127.0.0.1 -d 12345 -r 54321
@@ -30,7 +30,7 @@ This will bind the controller to the localhost (127.0.0.1) with the DRb server l
e.g.
DRb server started on : druby://127.0.0.1:12345
Ring server started on: druby://127.0.0.1:54321
-
+
=== Start with access control list
To start a controller with an access control list:
@@ -80,7 +80,7 @@ This will deny all access by default and allow access to this provider on localh
=== Start with a specific browser supported
By default, the provider will try to instantiate a browser object based on availability with your operating system e.g. Internet Explorer, Firefox or Safari. You can force provision of a set browser type as follows:
- $ provider -b safari
+ $ provider -d webdriver
This will provide a Safari browser object. Other options are:
$ provider -b ie
@@ -129,4 +129,4 @@ Other attributes include:
Will determine which providers identified by a hash of hostnames that should be accessed. Useful if trying to limit the test to run from specific hostnames or IP addresses.
:browser_type => 'firefox'
-Will determine which providers identified by a browser type should be accessed. Useful if trying to to test with specific browser types.
+Will determine which providers identified by a browser type should be accessed. Useful if trying to to test with specific browser types.
View
7 README.rdoc
@@ -7,12 +7,13 @@ To install WatirGrid:
gem install watirgrid
=== The Basics
-WatirGrid is built on Rinda which implements the Linda distributed computing paradigm in Ruby. According to Wikipedia: “Linda is a model of coordination and communication among several parallel processes operating upon objects stored in and retrieved from shared, virtual, associative memory.”
-In other words, WatirGrid allows multiple parallel processes to *_provide_* remote Watir objects in the form of tuple spaces across a grid network. This grid network is *_controlled_* by a ring server.
+WatirGrid allows a local client to control remote Watir objects in parallel, hosted by *providers* on a grid network, via a central *controller*.
==== Key Terminology
-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 direct URI. You can also find this controller by its ring server, using a UDP broadcast for the ring server port.
+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.
View
53 bin/controller
@@ -8,39 +8,42 @@ options = {}
OptionParser.new do |opts|
opts.banner = "Usage: controller [options]"
opts.separator ""
- opts.separator "Specific options:"
- opts.on("-H", "--drb-server-host [HOST]", String,
- "Specify DRb Server interface to host on") do |h|
+ opts.separator "Advanced Options:"
+ opts.on("-h", "--drb HOST",
+ "Specify the DRb host for this controller to bind to.") do |h|
options[:drb_server_host] = h || nil
end
- opts.on("-d", "--drb-server-port [PORT]", Integer,
- "Specify DRb Server port to listen on") do |d|
- options[:drb_server_port] = d
+ opts.on("-p", "--drb-port PORT",
+ "Specify the DRb port for this controller to listen on.") do |p|
+ options[:drb_server_port] = p
end
- opts.on("-h", "--ring-server-host [HOST]", String,
- "Specify Ring Server interface to host on") do |h|
+ opts.on("-H", "--ring-server HOST",
+ "Specify the ring server host for this controller to bind to.") do |h|
options[:ring_server_host] = h || nil
end
- opts.on("-r", "--ring-server-port [PORT]", Integer,
- "Specify Ring Server port to listen on") do |r|
- options[:ring_server_port] = r
+ opts.on("-P", "--ring-server-port PORT",
+ "Specify the ring server port for this controller to listen on.") do |p|
+ options[:ring_server_port] = p
end
- opts.on("-a", "--access-control-list [ACLS]", Array,
- "Specify a comma separated Access Control List") do |a|
+ opts.on("-a", "--access-control-list ACL", Array,
+ "Specify a comma separated Access Control List.") do |a|
options[:acls] = a
end
- opts.on("-l", "--log-level [LEVEL]", String,
- "Specify log level {DEBUG|INFO|ERROR}") do |l|
- case l
- when 'DEBUG'
- options[:loglevel] = Logger::DEBUG
- when 'INFO'
- options[:loglevel] = Logger::INFO
- when 'ERROR'
- options[:loglevel] = Logger::ERROR
- else
- options[:loglevel] = Logger::ERROR
- end
+ opts.on("-l", "--log LEVEL",
+ "Specify the logging level:",
+ " - DEBUG",
+ " - INFO",
+ " - ERROR") do |l|
+ case l
+ when 'DEBUG'
+ options[:loglevel] = Logger::DEBUG
+ when 'INFO'
+ options[:loglevel] = Logger::INFO
+ when 'ERROR'
+ options[:loglevel] = Logger::ERROR
+ else
+ options[:loglevel] = Logger::ERROR
+ end
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
View
66 bin/provider
@@ -6,39 +6,57 @@ require 'optparse'
options = {}
optparse = OptionParser.new do |opts|
- opts.banner = "Usage: provider -b BROWSER_TYPE [options]"
+ opts.banner = "Usage: provider -d DRIVER [options]"
opts.separator ""
- opts.separator "Specific options:"
- opts.on("-b", "--browser-type TYPE",
- "Specify driver for browser type to register {watir|firewatir|safariwatir|webdriver|zombie}") do |b|
- options[:browser_type] = b
+ opts.separator "Basic Options:"
+ opts.on("-d", "--driver TYPE",
+ "Specify driver type to use on this provider:",
+ " - watir",
+ " - webdriver",
+ " - selenium",
+ " - firewatir",
+ " - safariwatir") do |d|
+ options[:driver] = d
end
- opts.on("-c", "--controller-uri [URI]",
- "Specify Controller URI e.g. druby://127.0.0.1:11235") do |h|
- options[:controller_uri] = h || nil
+ opts.on("-c", "--controller URI",
+ "Specify the controller URI to register this provider on e.g.:",
+ " - druby://127.0.0.1:11235") do |c|
+ options[:controller_uri] = c || nil
end
- opts.on("-H", "--drb-server-host [HOST]",
- "Specify DRb Server interface to host on") do |h|
+ opts.on("-b", "--browser TYPE",
+ "Specify the browser type to start when using webdriver or selenium:",
+ " - firefox",
+ " - chrome",
+ " - ie") do |b|
+ options[:browser_type] = b || nil
+ end
+ opts.separator ""
+ opts.separator "Advanced Options:"
+ opts.on("-h", "--drb HOST",
+ "Specify the DRb host for this provider to bind to.") do |h|
options[:drb_server_host] = h || nil
end
- opts.on("-d", "--drb-server-port [PORT]",
- "Specify DRb Server port to listen on") do |d|
- options[:drb_server_port] = d
+ opts.on("-p", "--drb-port PORT",
+ "Specify the DRb port for this provider to listen on.") do |p|
+ options[:drb_server_port] = p
end
- opts.on("-h", "--ring-server-host [HOST]",
- "Specify Ring Server host to connect to") do |h|
+ opts.on("-H", "--ring-server HOST",
+ "Optionally specify the ring server host if not using controller URI.") do |h|
options[:ring_server_host] = h || nil
end
- opts.on("-r", "--ring-server-port [PORT]",
- "Specify Ring Server port to broadcast on") do |r|
- options[:ring_server_port] = r
+ opts.on("-P", "--ring-server-port PORT",
+ "Optionally specify the ring server port if not using controller URI.") do |p|
+ options[:ring_server_port] = p
end
- opts.on("-a", "--access-control-list [ACL]", Array,
- "Specify a comma separated Access Control List") do |a|
+ opts.on("-a", "--access-control-list ACL", Array,
+ "Specify a comma separated Access Control List.") do |a|
options[:acls] = a
end
- opts.on("-l", "--log-level [LEVEL]",
- "Specify log level {DEBUG|INFO|ERROR}") do |l|
+ opts.on("-l", "--log LEVEL",
+ "Specify the logging level:",
+ " - DEBUG",
+ " - INFO",
+ " - ERROR") do |l|
case l
when 'DEBUG'
options[:loglevel] = Logger::DEBUG
@@ -58,7 +76,7 @@ end
begin
optparse.parse!
- mandatory = [:browser_type]
+ mandatory = [:driver]
missing = mandatory.select{ |param| options[param].nil? }
if not missing.empty?
puts "Missing options: #{missing.join(', ')}"
@@ -76,7 +94,7 @@ provider = Provider.new(
:drb_server_port => options[:drb_server_port] || 11236,
:ring_server_host => options[:ring_server_host],
:ring_server_port => options[:ring_server_port] || 12358,
- :browser_type => options[:browser_type] || nil,
+ :driver => options[:driver] || nil,
:controller_uri => options[:controller_uri] || nil,
:acls => options[:acls] || %w{ allow all },
:loglevel => options[:loglevel])
View
122 lib/provider.rb
@@ -11,23 +11,22 @@ module Watir
##
# Extend Watir with a Provider class
- # to determine which browser type is supported by the
+ # to determine which driver type is supported by the
# remote DRb process. This returns the DRb front object.
class Provider
include DRbUndumped # all objects will be proxied, not copied
attr_reader :browser
- def initialize(browser = nil)
- browser = (browser || 'tmp').downcase.to_sym
- case browser
- when :safari, :safariwatir
+ def initialize(driver=nil)
+ case driver.downcase.to_sym
+ when :safariwatir
require 'safariwatir'
@browser = Watir::Safari
- when :firefox, :firewatir
+ when :firewatir
require 'firewatir'
@browser = FireWatir::Firefox
- when :ie, :watir
+ when :watir
require 'watir'
@browser = Watir::IE
when :webdriver
@@ -41,30 +40,27 @@ def initialize(browser = nil)
require 'watir-webdriver'
require 'selenium-webdriver'
@browser = Watir::Browser
- when :zombie
- require 'watir-zombie'
- @browser = Watir::Zombie
when :selenium
require 'selenium-webdriver'
@browser = Selenium::WebDriver
end
end
- def new_browser(webdriver_browser_type = :firefox)
+ def new_browser(browser_type='firefox')
case @browser.inspect
when "Selenium::WebDriver"
- if webdriver_browser_type == :htmlunit
+ if browser_type == :htmlunit
caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
@browser.for(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => caps)
else
- @browser.for webdriver_browser_type
+ @browser.for browser_type.to_sym
end
when "Watir::Browser"
- if webdriver_browser_type == :htmlunit
+ if @browser_type == :htmlunit
caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true)
@browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => caps)
else
- @browser.new webdriver_browser_type
+ @browser.new browser_type.to_sym
end
when "Watir::Safari"
@browser.new
@@ -77,85 +73,6 @@ def new_browser(webdriver_browser_type = :firefox)
end
end
- ##
- # Get a list of running browsers (optionally specified by browser)
- # 'iexplore','firefox','firefox-bin','chrome','safari','opera'
- def get_running_browsers(browser=nil)
- browsers = browser || \
- ['iexplore','firefox','firefox-bin','chrome','safari','opera']
- case Config::CONFIG['arch']
- when /mswin/
- %x[tasklist].split(/\s+/).collect { |x| x[/\w+/]} \
- & browsers.collect { |x| x.downcase }
- when /linux|darwin/
- %x[ps -A | grep -v ruby].split(/\/|\s+/).collect { |x| x.downcase} \
- & browsers
- end
- end
-
- def get_running_processes
- %x[ps -A | grep -v ruby].split(/\/|\s+/).collect.uniq
- end
-
- ##
- # Kill any browser running
- def kill_all_browsers
- case Config::CONFIG['arch']
- when /mswin/
- browsers = ['iexplore.exe', 'firefox.exe', 'chrome.exe']
- browsers.each { |browser| %x[taskkill /F /IM #{browser}] }
- when /linux/
- browsers = ['firefox', 'chrome', 'opera']
- browsers.each { |browser| %x[killall -r #{browser}] }
- when /darwin/
- browsers = ['firefox-bin', 'Chrome', 'Safari']
- browsers.each { |browser| %x[pkill -9 #{browser}] }
- end
- end
-
- ##
- # Kill all browsers specified by browser name
- # Windows: 'iexplore.exe', 'firefox.exe', 'chrome.exe'
- # Linux: 'firefox', 'chrome', 'opera'
- # OSX: 'firefox-bin', 'Chrome', 'Safari'
- def kill_browser(browser)
- case Config::CONFIG['arch']
- when /mswin/
- %x[taskkill /F /IM #{browser}]
- when /linux/
- %x[killall -r #{browser}]
- when /darwin/
- %x[killall -m #{browser}]
- end
- end
-
- ##
- # Start firefox (with an optional bin path) using the -jssh extension
- def start_firefox_jssh(path=nil)
- case Config::CONFIG['arch']
- when /mswin/
- bin = path || "C:/Program Files/Mozilla Firefox/firefox.exe"
- when /linux/
- bin = path || "/usr/bin/firefox"
- when /darwin/
- bin = path || "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
- end
- # fork off and die!
- Thread.new {system(bin, "about:blank", "-jssh")}
- end
-
- ##
- # Get the logged-in user
- def get_logged_in_user
- %x[whoami].chomp
- end
-
- ##
- # Grep for a process (Linux/OSX-with-port only)
- def process_grep(pattern)
- %x[pgrep -l #{pattern}].split(/\n/)
- end
-
def renew_provider
self.class.superclass
end
@@ -174,22 +91,21 @@ def initialize(params = {})
@ring_server_host = params[:ring_server_host] || external_interface
@ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
@controller_uri = params[:controller_uri]
-
- @renewer = params[:renewer] || Rinda::SimpleRenewer.new
- @browser_type = params[:browser_type] || nil
+ @renewer = params[:renewer] || Rinda::SimpleRenewer.new
+ @driver = params[:driver] || 'webdriver'
+ @browser_type = params[:browser_type] || 'firefox'
logfile = params[:logfile] || STDOUT
@log = Logger.new(logfile, 'daily')
@log.level = params[:loglevel] || Logger::INFO
@log.datetime_format = "%Y-%m-%d %H:%M:%S "
-
end
##
- # Start providing watir objects on the ring server
- def start
+ # Start providing Watir objects on the ring server
+ def start(params = {})
# create a DRb 'front' object
- watir_provider = Watir::Provider.new(@browser_type)
+ watir_provider = Watir::Provider.new(@driver)
@log.debug("Watir provider is : #{watir_provider}")
architecture = Config::CONFIG['arch']
hostname = ENV['SERVER_NAME'] || %x{hostname}.strip
@@ -213,8 +129,8 @@ def start
'A watir provider',
hostname,
architecture,
- @browser_type
- ]
+ @driver
+ ]
# locate the Rinda Ring Server via a UDP broadcast
@log.debug("Broadcast Ring Server : druby://#{@ring_server_host}:#{@ring_server_port}")
View
36 lib/watirgrid.rb
@@ -13,20 +13,20 @@ class Grid
attr_accessor :drb_server_uri, :ring_server, :browsers, :tuples, :providers
def initialize(params = {})
- @drb_server_host = params[:drb_server_host] || external_interface
- @drb_server_port = params[:drb_server_port] || 0
- @controller_uri = params[:controller_uri]
- @ring_server_host = params[:ring_server_host] || external_interface unless @controller_uri
- @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
- @renewer = params[:renewer] || Rinda::SimpleRenewer.new
- logfile = params[:logfile] || STDOUT
- @log = Logger.new(logfile, 'daily')
- @log.level = params[:loglevel] || Logger::ERROR
- @log.datetime_format = "%Y-%m-%d %H:%M:%S "
- @webdriver_browser_type = params[:browser].to_sym if params[:browser]
- @browsers = []
- @tuples = []
- @providers = []
+ @drb_server_host = params[:drb_server_host] || external_interface
+ @drb_server_port = params[:drb_server_port] || 0
+ @controller_uri = params[:controller_uri]
+ @ring_server_host = params[:ring_server_host] || external_interface unless @controller_uri
+ @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
+ @renewer = params[:renewer] || Rinda::SimpleRenewer.new
+ logfile = params[:logfile] || STDOUT
+ @log = Logger.new(logfile, 'daily')
+ @log.level = params[:loglevel] || Logger::ERROR
+ @log.datetime_format = "%Y-%m-%d %H:%M:%S "
+ @browser_type = params[:browser_type]
+ @browsers = []
+ @tuples = []
+ @providers = []
end
##
@@ -55,7 +55,7 @@ def release_tuples
def setup
@browsers.each_with_index do |browser, index|
sleep 0.15
- @providers[index] ||= browser[:object].new_browser(@webdriver_browser_type)
+ @providers[index] ||= browser[:object].new_browser @browser_type
end
end
@@ -83,7 +83,7 @@ def self.control(params = {}, &block)
sleep rampup(grid.size, params)
threads << Thread.new do
start = ::Time.now
- @browser = browser[:object].new_browser
+ @browser = browser[:object].new_browser params[:browser_type]
yield @browser, "#{index}"
end
end
@@ -176,7 +176,7 @@ def read_tuples(params={})
nil, # provider description
nil, # hostname
params[:architecture],
- params[:browser_type]
+ params[:driver]
])
end
@@ -212,7 +212,7 @@ def tuple_to_hash(tuple)
tuple_hash[:description] = tuple[3]
tuple_hash[:hostname] = tuple[4]
tuple_hash[:architecture] = tuple[5]
- tuple_hash[:browser_type] = tuple[6]
+ tuple_hash[:driver] = tuple[6]
tuple_hash
end
View
2 spec/control_spec.rb → spec/grid_control_spec.rb
@@ -8,7 +8,7 @@
@controller.start
provider = Provider.new(
:ring_server_port => 12357,
- :loglevel => Logger::ERROR, :browser_type => 'safari')
+ :loglevel => Logger::ERROR, :driver => 'safariwatir')
provider.start
end
View
43 spec/grid_spec.rb → spec/grid_management_spec.rb
@@ -44,7 +44,8 @@
:drb_server_host => '127.0.0.1',
:ring_server_host => '127.0.0.1',
:ring_server_port => 12350,
- :loglevel => Logger::ERROR)
+ :loglevel => Logger::ERROR,
+ :driver => 'safariwatir')
provider.start
end
@@ -62,7 +63,7 @@
1.upto(5) do
provider = Provider.new(
:ring_server_port => 12357,
- :loglevel => Logger::ERROR, :browser_type => 'safari')
+ :loglevel => Logger::ERROR, :driver => 'safariwatir')
provider.start
end
end
@@ -101,32 +102,32 @@
grid.size.should == 0
end
- it 'should register 4 new providers on the grid' do
- 1.upto(4) do
+ it 'should register 3 new providers on the grid' do
+ 1.upto(3) do
provider = Provider.new(:ring_server_port => 12357,
- :loglevel => Logger::ERROR, :browser_type => 'safari')
+ :loglevel => Logger::ERROR, :driver => 'safariwatir')
provider.start
end
end
- it 'should take any 1 provider based on :browser_type from the grid' do
+ it 'should take any 1 provider based on :driver from the grid' do
grid = Watir::Grid.new(:ring_server_port => 12357)
grid.start(:quantity => 1,
- :take_all => true, :browser_type => 'safari')
+ :take_all => true, :driver => 'safariwatir')
grid.size.should == 1
end
- it 'should fail to find any providers on the grid based on a specific :browser_type' do
+ it 'should fail to find any providers on the grid based on a specific :driver' do
grid = Watir::Grid.new(:ring_server_port => 12357)
grid.start(:quantity => 1,
- :take_all => true, :browser_type => 'firefox')
+ :take_all => true, :driver => 'watir')
grid.size.should == 0
end
- it 'should fail to find any providers on the grid based on an unknown :browser_type' do
+ it 'should fail to find any providers on the grid based on an unknown :driver' do
grid = Watir::Grid.new(:ring_server_port => 12357)
grid.start(:quantity => 1,
- :take_all => true, :browser_type => 'penguin')
+ :take_all => true, :driver => 'operawatir')
grid.size.should == 0
end
@@ -162,26 +163,6 @@
grid.size.should == 0
end
- it 'should take the last provider on the grid and execute some Watir code in Safari' do
- grid = Watir::Grid.new(:ring_server_port => 12357)
- grid.start(:quantity => 1, :take_all => true)
- threads = []
- grid.browsers.each do |browser|
- threads << Thread.new do
- browser[:hostname].should == `hostname`.strip
- browser[:architecture].should == Config::CONFIG['arch']
- browser[:browser_type].should == 'safari'
- 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}
- grid.size.should == 1
- end
-
it 'should find no more providers on the grid' do
grid = Watir::Grid.new(:ring_server_port => 12357)
grid.start(:read_all => true)
View
34 spec/selenium_webdriver_spec.rb
@@ -8,7 +8,7 @@
1.upto(1) do
provider = Provider.new(
:ring_server_port => 12356,
- :loglevel => Logger::ERROR, :browser_type => 'selenium')
+ :loglevel => Logger::ERROR, :driver => 'selenium')
provider.start
end
end
@@ -17,31 +17,13 @@
@controller.stop
end
- it 'should take the last provider on the grid and execute some Watir code in Selenium::WebDriver with Firefox' do
- grid = Watir::Grid.new(:ring_server_port => 12356)
- grid.start(:quantity => 1, :take_all => true)
- threads = []
- grid.browsers.each do |browser|
- threads << Thread.new do
- browser[:hostname].should == `hostname`.strip
- browser[:architecture].should == Config::CONFIG['arch']
- browser[:browser_type].should == 'selenium'
- driver = browser[:object].new_browser(:firefox)
- driver.navigate.to "http://google.com"
- element = driver.find_element(:name, 'q')
- element.send_keys "Hello WebDriver!"
- element.submit
- driver.quit
- end
+ it 'should control a grid in Selenium::WebDriver with Firefox' do
+ Watir::Grid.control(:ring_server_port => 12356, :browser_type => 'firefox') do |driver, index|
+ driver.navigate.to "http://google.com"
+ element = driver.find_element(:name, 'q')
+ element.send_keys "Hello WebDriver!"
+ element.submit
+ driver.quit
end
- threads.each {|thread| thread.join}
- grid.size.should == 1
- end
-
- it 'should find no more providers on the grid' do
- grid = Watir::Grid.new(:ring_server_port => 12356)
- grid.start(:read_all => true)
- grid.size.should == 0
end
end
-
View
1 spec/spec_helper.rb
@@ -1,3 +1,4 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'watirgrid'
+require 'ap'
View
54 spec/utilities_spec.rb
@@ -1,54 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-
-describe 'Utility Functions for the Grid' do
- before(:all) do
- @controller = Controller.new(
- :ring_server_port => 12353,
- :loglevel => Logger::ERROR)
- @controller.start
- 1.upto(1) do
- provider = Provider.new(
- :ring_server_port => 12353,
- :loglevel => Logger::ERROR, :browser_type => 'safari')
- provider.start
- end
- grid = Watir::Grid.new(:ring_server_port => 12353)
- grid.start(:read_all => true)
- @browser = grid.browsers[0]
- end
-
- after(:all) do
- @controller.stop
- end
-
- it 'should get the logged-in user for the remote provider' do
- @browser[:object].get_logged_in_user.should == `whoami`.chomp
- end
-
- it 'should enumerate any running browsers on the remote provider' do
- @browser[:object].get_running_browsers(['firefox-bin']).size.should == 0
- end
-
- it 'should be able to start a new firefox browser' do
- @browser[:object].start_firefox_jssh
- sleep 5
- @browser[:object].get_running_browsers(['firefox-bin']).size.should == 1
- end
-
- it 'should be able to kill all firefox browsers' do
- @browser[:object].kill_browser('firefox-bin')
- @browser[:object].get_running_browsers(['firefox-bin']).size.should == 0
- end
-
- it 'should be able to start a new firefox browser specified by path' do
- @browser[:object].start_firefox_jssh
- ("/Applications/Firefox.app/Contents/MacOS/firefox-bin")
- sleep 5
- @browser[:object].get_running_browsers(['firefox-bin']).size.should == 1
- end
-
- it 'should be able to kill all browsers' do
- @browser[:object].kill_all_browsers
- @browser[:object].get_running_browsers.size.should == 0
- end
-end
View
60 spec/webdriver_remote_spec.rb
@@ -1,60 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
-
-describe 'Using the Grid with WebDriver Remote' do
- before(:all) do
- @controller = Controller.new(
- :loglevel => Logger::ERROR)
- @controller.start
- provider = Provider.new(
- :loglevel => Logger::ERROR, :browser_type => 'webdriver_remote')
- provider.start
- end
-
- after(:all) do
- @controller.stop
- end
-
- it 'should read the provider on the grid and execute some Watir code in WebDriver with HtmlUnit' do
- grid = Watir::Grid.new
- grid.start(:quantity => 1, :read_all => true)
- threads = []
- grid.browsers.each do |browser|
- threads << Thread.new do
- b = browser[:object].new_browser(:htmlunit)
- 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}
- grid.size.should == 1
- end
-
- it 'should read the provider on the grid and execute some Watir code in WebDriver with HtmlUnit' do
- grid = Watir::Grid.new
- grid.start(:quantity => 1, :read_all => true)
- threads = []
- grid.browsers.each do |browser|
- threads << Thread.new do
- vusers = []
- 3.times do
- vusers << Thread.new do
- b = browser[:object].new_browser(:htmlunit)
- b.goto("http://www.google.com")
- b.text_field(:name => "q").set "watirgrid"
- b.button(:name => "btnG").click
- b.div(:id => "resultStats").wait_until_present
- p "Displaying page: '#{b.title}' with results: '#{b.div(:id => "resultStats").text}'"
- b.close
- end
- vusers.each {|vuser| vuser.join}
- end
- end
- end
- threads.each {|thread| thread.join}
- grid.size.should == 1
- end
-
-end
View
34 spec/webdriver_spec.rb
@@ -17,29 +17,21 @@
@controller.stop
end
- it 'should take the last provider on the grid and execute some Watir code in WebDriver with Firefox' do
- grid = Watir::Grid.new(:ring_server_port => 12356)
- grid.start(:quantity => 1, :take_all => true)
- threads = []
- grid.browsers.each do |browser|
- threads << Thread.new do
- browser[:hostname].should == `hostname`.strip
- browser[:architecture].should == Config::CONFIG['arch']
- browser[:browser_type].should == 'webdriver'
- b = browser[:object].new_browser(:firefox)
- b.goto("http://www.google.com")
- b.text_field(:name, 'q').set("watirgrid")
- b.button(:name, "btnI").click
- b.close
- end
+ it 'should control a grid in WebDriver with Firefox' do
+ Watir::Grid.control(:ring_server_port => 12356, :browser_type => 'firefox') do |browser, index|
+ p "I am browser index #{index}"
+ browser.goto "http://google.com"
+ p browser.title
+ browser.close
end
- threads.each {|thread| thread.join}
- grid.size.should == 1
end
- it 'should find no more providers on the grid' do
- grid = Watir::Grid.new(:ring_server_port => 12356)
- grid.start(:read_all => true)
- grid.size.should == 0
+ it 'should iterate over a grid in WebDriver with Chrome' do
+ grid = Watir::Grid.new(:ring_server_port => 12356, :browser_type => 'chrome')
+ grid.start(:initiate => true)
+ grid.iterate do |browser|
+ browser.goto "http://google.com"
+ browser.close
+ end
end
end

0 comments on commit 1bbc8cb

Please sign in to comment.
Something went wrong with that request. Please try again.