grid 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/examples/basic/basic.rb +67 -0
- data/examples/cucumber/example.feature +3 -3
- data/examples/cucumber/step_definitions/example_steps.rb +27 -17
- data/grid.gemspec +3 -1
- data/lib/grid.rb +73 -41
- data/spec/grid_spec.rb +56 -2
- data/spec/spec_helper.rb +1 -0
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require '../lib/grid'
|
2
|
+
require 'watir-webdriver-performance' # only if using webdriver_performance
|
3
|
+
|
4
|
+
##
|
5
|
+
# Set some parameters before we begin
|
6
|
+
params={}
|
7
|
+
params[:controller_uri] = "druby://ec2-50-16-63-81.compute-1.amazonaws.com:11235"
|
8
|
+
params[:browser] = "chrome"
|
9
|
+
params[:quantity] = 5
|
10
|
+
|
11
|
+
##
|
12
|
+
# Let's instantiate a grid object
|
13
|
+
grid = Grid.new(params)
|
14
|
+
|
15
|
+
##
|
16
|
+
# How big is my grid?
|
17
|
+
puts grid.size
|
18
|
+
|
19
|
+
##
|
20
|
+
# The setup method will prepare the browsers on the grid
|
21
|
+
grid.setup
|
22
|
+
|
23
|
+
##
|
24
|
+
# Info about providers on the grid
|
25
|
+
p grid.providers.first[:hostname]
|
26
|
+
p grid.providers.first[:architecture]
|
27
|
+
|
28
|
+
##
|
29
|
+
# The iterate method can be passed a block of watir code,
|
30
|
+
# and is yielded a browser object in return
|
31
|
+
grid.iterate do |browser|
|
32
|
+
2.times do # because we want to iterate more than once for each browser
|
33
|
+
browser.goto "altentee.com"
|
34
|
+
puts browser.title
|
35
|
+
# if using webdriver_performance we can get performance metrics
|
36
|
+
puts browser.performance.summary[:response_time]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# The teardown method will close browsers and release nodes back to the grid
|
42
|
+
grid.teardown
|
43
|
+
|
44
|
+
##
|
45
|
+
# There's also a iterate_with_index method if you want to keep track
|
46
|
+
# of individual browsers for further reporting and analysis
|
47
|
+
grid = Grid.new(params)
|
48
|
+
grid.setup
|
49
|
+
|
50
|
+
grid.iterate_with_index do |browser, index|
|
51
|
+
puts "I am browser index #{index}"
|
52
|
+
browser.goto "watirgrid.com"
|
53
|
+
puts browser.performance.summary[:dom_processing]
|
54
|
+
end
|
55
|
+
|
56
|
+
grid.teardown
|
57
|
+
|
58
|
+
##
|
59
|
+
# Finally, here's a shorthand control method to do the setup, iteration and teardown
|
60
|
+
# in one foul swoop!
|
61
|
+
|
62
|
+
params[:rampup] = 10 #seconds, optional rampup period for all the browsers
|
63
|
+
Grid.control(params) do |browser, index|
|
64
|
+
puts "I am browser index #{index}"
|
65
|
+
browser.goto "gridinit.com"
|
66
|
+
puts browser.performance.summary[:time_to_first_byte]
|
67
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
@
|
1
|
+
@NFR-001
|
2
2
|
Feature: User logons
|
3
3
|
In order to use the web applicaion users must be
|
4
4
|
able to logon and access the portal in 3 seconds
|
5
5
|
|
6
|
-
Scenario: Logon with 50 users in
|
7
|
-
Given
|
6
|
+
Scenario: Logon with 50 users in 1 minute
|
7
|
+
Given 50 users open "chrome"
|
8
8
|
And navigate to the portal
|
9
9
|
When they enter their credentials
|
10
10
|
Then they should see their account settings
|
@@ -1,29 +1,39 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib'))
|
3
|
-
require 'grid'
|
4
3
|
require 'rspec/expectations';
|
4
|
+
require 'watir-webdriver-performance'
|
5
|
+
require 'grid'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
Given /^(\d+) users open "([^"]*)"$/ do |quantity, browser|
|
8
|
+
params={}
|
9
|
+
params[:controller_uri] = "druby://ec2-50-16-63-81.compute-1.amazonaws.com:11235"
|
10
|
+
params[:browser] = browser # type of webdriver browser to spawn
|
11
|
+
params[:quantity] = quantity.to_i # max number of browsers to use
|
12
|
+
params[:rampup] = 10 # seconds
|
13
|
+
@grid = Grid.new(params)
|
14
|
+
@grid.setup
|
15
|
+
end
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
Given /^navigate to the portal$/ do
|
18
|
+
@grid.iterate {|browser| browser.goto "http://gridinit.com/examples/logon.html" }
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
When /^they enter their credentials$/ do
|
22
|
+
@grid.iterate do |browser|
|
23
|
+
browser.text_field(:name => "email").set "tim@mahenterprize.com"
|
24
|
+
browser.text_field(:name => "password").set "mahsecretz"
|
25
|
+
browser.button(:type => "submit").click
|
18
26
|
end
|
27
|
+
end
|
19
28
|
|
20
|
-
|
21
|
-
|
29
|
+
Then /^they should see their account settings$/ do
|
30
|
+
@grid.iterate do |browser|
|
31
|
+
browser.text.should =~ /Maybe I should get a real Gridinit account/
|
22
32
|
end
|
33
|
+
end
|
23
34
|
|
24
|
-
|
25
|
-
|
35
|
+
Then /^the response time should be less than (\d+) seconds$/ do |response_time|
|
36
|
+
@grid.iterate do |browser|
|
37
|
+
browser.performance.summary[:response_time].should < response_time.to_i * 1000
|
26
38
|
end
|
27
|
-
|
28
39
|
end
|
29
|
-
|
data/grid.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{grid}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tim Koopmans"]
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION",
|
30
30
|
"bin/grid",
|
31
|
+
"examples/basic/basic.rb",
|
31
32
|
"examples/cucumber/example.feature",
|
32
33
|
"examples/cucumber/step_definitions/.DS_Store",
|
33
34
|
"examples/cucumber/step_definitions/example_steps.rb",
|
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
|
|
42
43
|
s.rubygems_version = %q{1.4.2}
|
43
44
|
s.summary = %q{Gridinit command line utilities}
|
44
45
|
s.test_files = [
|
46
|
+
"examples/basic/basic.rb",
|
45
47
|
"examples/cucumber/step_definitions/example_steps.rb",
|
46
48
|
"spec/grid_spec.rb",
|
47
49
|
"spec/spec_helper.rb"
|
data/lib/grid.rb
CHANGED
@@ -10,56 +10,88 @@ require 'highline/import'
|
|
10
10
|
|
11
11
|
class Grid
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
def initialize(params = {})
|
14
|
+
@log = Logger.new(STDOUT, 'daily')
|
15
|
+
@log.level = params[:loglevel] || Logger::INFO
|
16
|
+
@exclusive = params[:exclusive]
|
17
|
+
@exclusive ? params[:take_all] = true : params[:read_all] = true
|
18
|
+
@webdriver_browser_type = params[:browser].to_sym if params[:browser]
|
19
|
+
@grid = Watir::Grid.new(params)
|
20
|
+
@grid.start(params)
|
21
|
+
@providers = @grid.browsers
|
22
|
+
@browsers = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def size
|
26
|
+
@grid.size
|
27
|
+
end
|
28
|
+
|
29
|
+
def browsers
|
30
|
+
@browsers
|
31
|
+
end
|
32
|
+
|
33
|
+
def providers
|
34
|
+
@providers
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
@grid.browsers.each_with_index do |browser, index|
|
39
|
+
sleep 0.15
|
40
|
+
@browsers[index] ||= browser[:object].new_browser(@webdriver_browser_type)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
@browsers.each do |browser|
|
46
|
+
browser.close
|
47
|
+
end
|
48
|
+
@grid.release_tuples if @exclusive
|
49
|
+
end
|
50
|
+
|
51
|
+
def iterate &block
|
52
|
+
threads = []
|
53
|
+
@browsers.each do |browser|
|
54
|
+
threads << Thread.new do
|
55
|
+
yield browser
|
56
|
+
end
|
57
|
+
end
|
58
|
+
threads.each {|thread| thread.join}
|
59
|
+
end
|
60
|
+
|
61
|
+
def iterate_with_index &block
|
25
62
|
threads = []
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
$stdout.flush
|
30
|
-
start = ::Time.now
|
31
|
-
log.debug("Browser #{index+1}##{Thread.current.object_id} start : #{::Time.now}")
|
32
|
-
log.debug("Browser #{index+1}##{Thread.current.object_id} architecture : #{browser[:architecture]}")
|
33
|
-
log.debug("Browser #{index+1}##{Thread.current.object_id} type : #{browser[:browser_type]}")
|
34
|
-
log.debug("Browser #{index+1}##{Thread.current.object_id} hostname : #{browser[:hostname]}")
|
35
|
-
if browser[:browser_type] =~ /webdriver/
|
36
|
-
webdriver_browser_type = "firefox" unless webdriver_browser_type
|
37
|
-
@browser = browser[:object].new_browser(webdriver_browser_type.to_sym)
|
38
|
-
else
|
39
|
-
@browser = browser[:object].new_browser
|
40
|
-
end
|
41
|
-
yield @browser, "#{index+1}##{Thread.current.object_id}"
|
42
|
-
log.debug("Browser #{index+1}##{Thread.current.object_id} stop : #{::Time.now}")
|
43
|
-
log.debug("Browser #{index+1}##{Thread.current.object_id} elapsed : #{(::Time.now - start).to_i} secs")
|
63
|
+
@browsers.each_with_index do |browser, index|
|
64
|
+
threads << Thread.new do
|
65
|
+
yield browser, index
|
44
66
|
end
|
45
67
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
68
|
+
threads.each {|thread| thread.join}
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.control(params = {}, &block)
|
72
|
+
@exclusive = params[:exclusive]
|
73
|
+
@exclusive ? params[:take_all] = true : params[:read_all] = true
|
74
|
+
@webdriver_browser_type = params[:browser].to_sym if params[:browser]
|
75
|
+
@grid = Watir::Grid.new(params)
|
76
|
+
@grid.start(params)
|
77
|
+
@browsers = []
|
78
|
+
threads = []
|
79
|
+
@grid.browsers.each_with_index do |browser, index|
|
80
|
+
sleep rampup(params)
|
81
|
+
threads << Thread.new(@webdriver_browser_type) do |webdriver_browser_type|
|
82
|
+
@browser = browser[:object].new_browser(webdriver_browser_type)
|
83
|
+
yield @browser, index
|
84
|
+
end
|
52
85
|
end
|
53
|
-
|
86
|
+
threads.each {|thread| thread.join}
|
87
|
+
@grid.release_tuples if @exclusive
|
54
88
|
end
|
55
89
|
|
56
90
|
private
|
57
91
|
|
58
|
-
|
59
|
-
# Calculate rampup in seconds
|
60
|
-
def self.rampup(total_threads, params = {})
|
92
|
+
def self.rampup(params = {})
|
61
93
|
if params[:rampup]
|
62
|
-
params[:rampup] /
|
94
|
+
params[:rampup] / @grid.size
|
63
95
|
else
|
64
96
|
0.5
|
65
97
|
end
|
data/spec/grid_spec.rb
CHANGED
@@ -1,7 +1,61 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Grid" do
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
let!(:grid) do
|
6
|
+
params={}
|
7
|
+
params[:controller_uri] = "druby://ec2-50-16-63-81.compute-1.amazonaws.com:11235"
|
8
|
+
params[:browser] = "chrome"
|
9
|
+
params[:quantity] = 5
|
10
|
+
grid = Grid.new(params)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be able to check the size of a grid" do
|
14
|
+
grid.size.should == 5
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able setup browsers on the grid" do
|
18
|
+
grid.setup
|
19
|
+
grid.browsers.first.should be_an_instance_of(DRb::DRbObject)
|
20
|
+
grid.teardown
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be able to get information about individual providers on the grid" do
|
24
|
+
grid.providers.first[:hostname].should_not be_empty
|
25
|
+
grid.providers.first[:architecture].should_not be_empty
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to iterate over the grid" do
|
29
|
+
grid.setup
|
30
|
+
grid.iterate do |browser|
|
31
|
+
2.times do # because we want to iterate more than once for each browser
|
32
|
+
browser.goto "altentee.com"
|
33
|
+
browser.title.should =~ /The Automation Company/
|
34
|
+
# if using webdriver_performance we can get performance metrics
|
35
|
+
browser.performance.summary[:response_time].should > 0
|
36
|
+
end
|
37
|
+
end
|
38
|
+
grid.teardown
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to iterate over the grid with an index" do
|
42
|
+
grid.setup
|
43
|
+
grid.iterate_with_index do |browser, index|
|
44
|
+
browser.goto "watirgrid.com"
|
45
|
+
browser.performance.summary[:dom_processing].should > 0
|
46
|
+
end
|
47
|
+
grid.teardown
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be able to control the grid using shorthand method" do
|
51
|
+
params={}
|
52
|
+
params[:controller_uri] = "druby://ec2-50-16-63-81.compute-1.amazonaws.com:11235"
|
53
|
+
params[:browser] = "chrome" # type of webdriver browser to spawn
|
54
|
+
params[:quantity] = 5 # max number of browsers to use
|
55
|
+
params[:rampup] = 10 # seconds
|
56
|
+
Grid.control(params) do |browser, index|
|
57
|
+
browser.goto "gridinit.com"
|
58
|
+
browser.performance.summary[:time_to_first_byte].should > 0
|
59
|
+
end
|
6
60
|
end
|
7
61
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
4
|
require 'grid'
|
5
|
+
require 'watir-webdriver-performance'
|
5
6
|
|
6
7
|
# Requires supporting files with custom matchers and macros, etc,
|
7
8
|
# in ./support/ and its subdirectories.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Koopmans
|
@@ -253,6 +253,7 @@ files:
|
|
253
253
|
- Rakefile
|
254
254
|
- VERSION
|
255
255
|
- bin/grid
|
256
|
+
- examples/basic/basic.rb
|
256
257
|
- examples/cucumber/example.feature
|
257
258
|
- examples/cucumber/step_definitions/.DS_Store
|
258
259
|
- examples/cucumber/step_definitions/example_steps.rb
|
@@ -295,6 +296,7 @@ signing_key:
|
|
295
296
|
specification_version: 3
|
296
297
|
summary: Gridinit command line utilities
|
297
298
|
test_files:
|
299
|
+
- examples/basic/basic.rb
|
298
300
|
- examples/cucumber/step_definitions/example_steps.rb
|
299
301
|
- spec/grid_spec.rb
|
300
302
|
- spec/spec_helper.rb
|