browser_shooter 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -49,6 +49,7 @@ Create a YAML file like this:
49
49
  click "a.kls"
50
50
  pause 3
51
51
  shot after
52
+ shot_system final_shot
52
53
 
53
54
  miniclip: |
54
55
  navigate.to "http://www.miniclip.com/games/de/"
@@ -58,10 +59,12 @@ Create a YAML file like this:
58
59
  windows-firefox:
59
60
  url: "http://127.0.0.1:4444/wd/hub"
60
61
  type: "firefox"
62
+ vm: "VirtualBox name"
61
63
 
62
64
  windows-iexplore:
63
65
  url: "http://127.0.0.1:4444/wd/hub"
64
66
  type: "ie"
67
+ vm: "VirtualBox name"
65
68
 
66
69
  suites:
67
70
  suite1:
@@ -86,6 +89,7 @@ Look in the [examples folder](https://github.com/fguillen/BrowserShooter/tree/ma
86
89
  Commands are WebDriver commands, except:
87
90
 
88
91
  * **shot** command which receive an optional param with the 'sufix' of the page screenshot png
92
+ * **shot_system** equal to 'shot' but use the "VirtualBox" system command "VBoxManage" to make an screenshot of the OS screen.
89
93
  * **pause** command which use a Ruby 'sleep' command to pause
90
94
  * **click** command which receive a 'css_selector' as a param, find the element and click on it
91
95
  * **type** command which receive two params: 'css_selector' ana a 'message', find the element and type the message on it
@@ -97,6 +101,8 @@ You can define as much tests as you want. Every test is composed by a list of **
97
101
 
98
102
  All the available browsers with the **selenium server url** and the **selenium browser type**.
99
103
 
104
+ Also if you are gonna use the _shot_system_ command you have to indicate the name of the VirtualBox machine in the **vm** attribute.
105
+
100
106
  ##### Suites section
101
107
 
102
108
  Groups of **tests** and **browsers** to be executed as one.
@@ -137,4 +143,8 @@ The logs will be stored in:
137
143
 
138
144
  ## Status
139
145
 
140
- Still in a _development_ state.. but is already **functional**.
146
+ Still in a _development_ state.. but is already **functional**.
147
+
148
+ ## TODO
149
+
150
+ Support _Parallels_ screenshots with `$ prlctl capture`.
data/examples/config0.yml CHANGED
@@ -3,7 +3,8 @@ output_path: "~/browser_shoots"
3
3
  tests:
4
4
  google: |
5
5
  navigate.to "http://www.google.com"
6
- shot
6
+ shot browser
7
+ shot_system system
7
8
 
8
9
  miniclip: |
9
10
  navigate.to "http://www.miniclip.com/games/de/"
@@ -13,10 +14,17 @@ browsers:
13
14
  ios-firefox:
14
15
  url: "http://127.0.0.1:4444/wd/hub"
15
16
  type: "firefox"
17
+ vm: "My VM"
16
18
 
17
19
  ios-chrome:
18
20
  url: "http://127.0.0.1:4444/wd/hub"
19
21
  type: "chrome"
22
+ vm: "My VM"
23
+
24
+ win-ie:
25
+ url: "http://192.168.2.102:4444/wd/hub"
26
+ type: "ie"
27
+ vm: "windows7"
20
28
 
21
29
  suites:
22
30
  suite1:
@@ -31,5 +39,5 @@ suites:
31
39
  tests:
32
40
  - google
33
41
  browsers:
34
- - ios-chrome
42
+ - win-ie
35
43
 
data/examples/config1.yml CHANGED
@@ -19,10 +19,12 @@ browsers:
19
19
  ios-firefox:
20
20
  url: "http://127.0.0.1:4444/wd/hub"
21
21
  type: "firefox"
22
+ vm: "myVM"
22
23
 
23
24
  ios-chrome:
24
25
  url: "http://127.0.0.1:4444/wd/hub"
25
26
  type: "chrome"
27
+ vm: "myVM"
26
28
 
27
29
  suites:
28
30
  suite1:
data/examples/config2.yml CHANGED
@@ -29,18 +29,22 @@ browsers:
29
29
  osx-chrome:
30
30
  url: "http://127.0.0.1:4444/wd/hub"
31
31
  type: "chrome"
32
+ vm: "myVM"
32
33
 
33
34
  windows-chrome:
34
35
  url: "http://10.211.55.4:4444/wd/hub"
35
36
  type: "chrome"
37
+ vm: "myVM"
36
38
 
37
39
  windows-firefox:
38
40
  url: "http://10.211.55.4:4444/wd/hub"
39
41
  type: "firefox"
42
+ vm: "myVM"
40
43
 
41
44
  windows-ie:
42
45
  url: "http://10.211.55.4:4444/wd/hub"
43
46
  type: "ie"
47
+ vm: "myVM"
44
48
 
45
49
  suites:
46
50
  suite1:
@@ -49,6 +49,7 @@ module BrowserShooter
49
49
  BrowserShooter::Commander.script(
50
50
  test.commands,
51
51
  driver,
52
+ browser,
52
53
  output_path
53
54
  )
54
55
 
@@ -1,12 +1,13 @@
1
1
  module BrowserShooter::Commander
2
2
 
3
- def self.script( commands, driver, output_path )
3
+ def self.script( commands, driver, browser, output_path )
4
4
  test_result =
5
5
  commands.map do |command|
6
6
  command_result =
7
7
  BrowserShooter::Commander.wrapper_execute(
8
8
  command.strip,
9
9
  driver,
10
+ browser,
10
11
  output_path
11
12
  )
12
13
 
@@ -20,7 +21,7 @@ module BrowserShooter::Commander
20
21
  test_result
21
22
  end
22
23
 
23
- def self.execute( command, driver, output_path )
24
+ def self.execute( command, driver, browser, output_path )
24
25
  BrowserShooter::Logger.log "command: #{command}"
25
26
 
26
27
  if( command.split[0].strip == "shot" )
@@ -32,6 +33,16 @@ module BrowserShooter::Commander
32
33
  sufix
33
34
  )
34
35
 
36
+ elsif( command.split[0].strip == "shot_system" )
37
+ sufix = command.split[1] ? command.split[1].strip : nil
38
+
39
+ BrowserShooter::Commander.shot_system(
40
+ driver,
41
+ browser,
42
+ output_path,
43
+ sufix
44
+ )
45
+
35
46
  elsif( command.split[0].strip == "pause" )
36
47
  BrowserShooter::Commander.pause( command.split[1].strip.to_i )
37
48
 
@@ -66,7 +77,7 @@ module BrowserShooter::Commander
66
77
  end
67
78
  end
68
79
 
69
- def self.wrapper_execute( command, driver, output_path )
80
+ def self.wrapper_execute( command, driver, browser, output_path )
70
81
  result = {
71
82
  :time => Time.now.to_i,
72
83
  :command => command
@@ -77,6 +88,7 @@ module BrowserShooter::Commander
77
88
  BrowserShooter::Commander.execute(
78
89
  command,
79
90
  driver,
91
+ browser,
80
92
  output_path
81
93
  )
82
94
 
@@ -114,6 +126,24 @@ module BrowserShooter::Commander
114
126
  return shot_path
115
127
  end
116
128
 
129
+ def self.shot_system( driver, browser, output_path, sufix = nil )
130
+ sufix = timestamp unless sufix
131
+ shot_path = "#{output_path}/shots/#{sufix}.png"
132
+
133
+ BrowserShooter::Logger.log "shooting system in '#{shot_path}'"
134
+
135
+ FileUtils.mkdir_p( File.dirname( shot_path ) )
136
+
137
+ command = "VBoxManage controlvm '#{browser.vm}' screenshotpng '#{shot_path}'"
138
+ success = Kernel.system( command )
139
+
140
+ if( !success )
141
+ raise SystemCallError, "Shoot system command [#{command}] returns error: '#{$?}'"
142
+ end
143
+
144
+ return shot_path
145
+ end
146
+
117
147
  def self.wait_for_element( driver, css_selector, timeout )
118
148
  wait = Selenium::WebDriver::Wait.new( :timeout => timeout )
119
149
 
@@ -57,7 +57,7 @@ module BrowserShooter
57
57
 
58
58
  browsers =
59
59
  config["browsers"].map do |name, opts|
60
- BrowserShooter::Models::Browser.new( name, opts["url"], opts["type"] )
60
+ BrowserShooter::Models::Browser.new( name, opts["url"], opts["type"], opts["vm"] )
61
61
  end
62
62
 
63
63
  suites =
@@ -1,6 +1,6 @@
1
1
  module BrowserShooter
2
2
  module Models
3
- class Browser < Struct.new( :name, :url, :type )
3
+ class Browser < Struct.new( :name, :url, :type, :vm )
4
4
  end
5
5
  end
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module BrowserShooter
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
data/test/base_test.rb CHANGED
@@ -34,7 +34,7 @@ class BaseTest < Test::Unit::TestCase
34
34
  BrowserShooter::Base.new( opts ).run
35
35
  end
36
36
 
37
- def test_run_script
37
+ def test_run_test
38
38
  expected_opts = {
39
39
  :url => "url1",
40
40
  :desired_capabilities => "type1".to_sym
@@ -43,7 +43,7 @@ class BaseTest < Test::Unit::TestCase
43
43
  driver = mock()
44
44
  driver.expects( :quit )
45
45
  Selenium::WebDriver.expects( :for ).with( :remote, expected_opts ).returns( driver )
46
- BrowserShooter::Commander.expects( :script ).with( @test1.commands, driver, "output_path/suite1/test1/browser1" ).returns( "log1" )
46
+ BrowserShooter::Commander.expects( :script ).with( @test1.commands, driver, @browser1, "output_path/suite1/test1/browser1" ).returns( "log1" )
47
47
  BrowserShooter::LogExporter.expects( :export ).with( "log1", "output_path/suite1/test1/browser1/logs" )
48
48
 
49
49
  BrowserShooter::Base.run_test( @suite1, @test1, @browser1, "output_path" )
@@ -7,69 +7,129 @@ class CommanderTest < Test::Unit::TestCase
7
7
  " command2 "
8
8
  ]
9
9
 
10
- BrowserShooter::Commander.expects( :wrapper_execute ).with( "command1", "driver", "output_path" ).returns( "result1" )
11
- BrowserShooter::Commander.expects( :wrapper_execute ).with( "command2", "driver", "output_path" ).returns( "result2" )
10
+ BrowserShooter::Commander.expects( :wrapper_execute ).with( "command1", "driver", "browser", "output_path" ).returns( "result1" )
11
+ BrowserShooter::Commander.expects( :wrapper_execute ).with( "command2", "driver", "browser", "output_path" ).returns( "result2" )
12
12
  BrowserShooter::Logger.expects( :command_result ).twice
13
13
  BrowserShooter::Logger.expects( :test_result )
14
14
 
15
- result = BrowserShooter::Commander.script( commands, "driver", "output_path" )
15
+ result = BrowserShooter::Commander.script( commands, "driver", "browser", "output_path" )
16
16
 
17
17
  assert_equal( ["result1", "result2"], result )
18
18
  end
19
19
 
20
+ def test_wrapper_execute
21
+ BrowserShooter::Commander.expects( :execute ).with( "command", "driver", "browser", "output_path" ).returns( "message" )
22
+ result = BrowserShooter::Commander.wrapper_execute( "command", "driver", "browser", "output_path" )
23
+
24
+ assert_equal( "command", result[:command] )
25
+ assert_equal( false, result[:time].nil? )
26
+ assert_equal( true, result[:success] )
27
+ assert_equal( "message", result[:message] )
28
+ end
29
+
30
+ def test_wrapper_execute_when_error
31
+ BrowserShooter::Commander.expects( :execute ).with( "command", "driver", "browser", "output_path" ).raises( Exception.new( "error" ) )
32
+ result = BrowserShooter::Commander.wrapper_execute( "command", "driver", "browser", "output_path" )
33
+
34
+ assert_equal( "command", result[:command] )
35
+ assert_equal( false, result[:time].nil? )
36
+ assert_equal( false, result[:success] )
37
+ assert_equal( "error", result[:message] )
38
+ end
39
+
20
40
  def test_execute_when_shot_with_sufix
21
41
  BrowserShooter::Commander.expects( :shot ).with( "driver", "shoot-path", "sufix" )
22
- BrowserShooter::Commander.execute( "shot sufix", "driver", "shoot-path" )
42
+ BrowserShooter::Commander.execute( "shot sufix", "driver", "browser", "shoot-path" )
23
43
  end
24
44
 
25
45
  def test_execute_when_shot_without_sufix
26
46
  BrowserShooter::Commander.expects( :shot ).with( "driver", "shoot-path", nil )
27
- BrowserShooter::Commander.execute( "shot", "driver", "shoot-path" )
47
+ BrowserShooter::Commander.execute( "shot", "driver", "browser", "shoot-path" )
48
+ end
49
+
50
+ def test_execute_when_shot_system_with_sufix
51
+ BrowserShooter::Commander.expects( :shot_system ).with( "driver", "browser", "shoot-path", "sufix" )
52
+ BrowserShooter::Commander.execute( "shot_system sufix", "driver", "browser", "shoot-path" )
53
+ end
54
+
55
+ def test_execute_when_shot_system_without_sufix
56
+ BrowserShooter::Commander.expects( :shot_system ).with( "driver", "browser", "shoot-path", nil )
57
+ BrowserShooter::Commander.execute( "shot_system", "driver", "browser", "shoot-path" )
28
58
  end
29
59
 
30
60
  def test_execute_when_pause
31
61
  BrowserShooter::Commander.expects( :pause ).with( 10 )
32
- BrowserShooter::Commander.execute( "pause 10", "driver", "shoot-path" )
62
+ BrowserShooter::Commander.execute( "pause 10", "driver", "browser", "shoot-path" )
33
63
  end
34
64
 
35
65
  def test_execute_when_wait_for_element
36
66
  BrowserShooter::Commander.expects( :wait_for_element ).with( "driver", "css_selector", 10 )
37
- BrowserShooter::Commander.execute( "wait_for_element \"css_selector\", 10", "driver", nil )
67
+ BrowserShooter::Commander.execute( "wait_for_element \"css_selector\", 10", "driver", "browser", nil )
38
68
  end
39
69
 
40
70
  def test_execute_when_click
41
71
  BrowserShooter::Commander.expects( :click ).with( "driver", "css_selector" )
42
- BrowserShooter::Commander.execute( "click \"css_selector\"", "driver", nil )
72
+ BrowserShooter::Commander.execute( "click \"css_selector\"", "driver", "browser", nil )
43
73
  end
44
74
 
45
75
  def test_execute_when_type
46
76
  BrowserShooter::Commander.expects( :type ).with( "driver", "css_selector", "message a b" )
47
- BrowserShooter::Commander.execute( "type \"css_selector\", \"message a b\"", "driver", nil )
77
+ BrowserShooter::Commander.execute( "type \"css_selector\", \"message a b\"", "driver", "browser", nil )
48
78
  end
49
79
 
50
80
  def test_shot_with_sufix
51
- in_tmpdir do |tmpdir|
52
- driver = mock()
53
- output_path = tmpdir
81
+ driver = mock()
54
82
 
55
- FileUtils.expects( :mkdir_p ).with( "#{output_path}/shots" )
56
- driver.expects( :save_screenshot ).with( "#{output_path}/shots/sufix.png" )
83
+ FileUtils.expects( :mkdir_p ).with( "output_path/shots" )
84
+ driver.expects( :save_screenshot ).with( "output_path/shots/sufix.png" )
57
85
 
58
- BrowserShooter::Commander.shot( driver, output_path, "sufix" )
59
- end
86
+ BrowserShooter::Commander.shot( driver, "output_path", "sufix" )
60
87
  end
61
88
 
62
89
  def test_shot_without_sufix
63
90
  BrowserShooter::Commander.stubs( :timestamp ).returns( "timestamp" )
64
91
 
65
- in_tmpdir do |tmpdir|
66
- driver = mock()
67
- output_path = tmpdir
92
+ driver = mock()
93
+
94
+ FileUtils.expects( :mkdir_p ).with( "output_path/shots" )
95
+ driver.expects( :save_screenshot ).with( "output_path/shots/timestamp.png" )
96
+
97
+ BrowserShooter::Commander.shot( driver, "output_path", nil )
98
+ end
99
+
100
+ def test_shot_system_with_sufix
101
+ browser = mock()
102
+ command = "VBoxManage controlvm 'VMName' screenshotpng 'output_path/shots/sufix.png'"
103
+
104
+ browser.stubs( :vm ).returns( "VMName" )
105
+ FileUtils.expects( :mkdir_p ).with( "output_path/shots" )
106
+ Kernel.expects( :system ).with( command ).returns( true )
107
+
108
+ BrowserShooter::Commander.shot_system( "driver", browser, "output_path", "sufix" )
109
+ end
110
+
111
+ def test_shot_system_without_sufix
112
+ browser = mock()
113
+ command = "VBoxManage controlvm 'VMName' screenshotpng 'output_path/shots/timestamp.png'"
114
+
115
+ BrowserShooter::Commander.stubs( :timestamp ).returns( "timestamp" )
116
+ browser.stubs( :vm ).returns( "VMName" )
117
+ FileUtils.expects( :mkdir_p ).with( "output_path/shots" )
118
+ Kernel.expects( :system ).with( command ).returns( true )
119
+
120
+ BrowserShooter::Commander.shot_system( "driver", browser, "output_path" )
121
+ end
122
+
123
+ def test_shot_system_with_error
124
+ browser = mock()
125
+ command = "VBoxManage controlvm 'VMName' screenshotpng 'output_path/shots/sufix.png'"
68
126
 
69
- FileUtils.expects( :mkdir_p ).with( "#{output_path}/shots" )
70
- driver.expects( :save_screenshot ).with( "#{output_path}/shots/timestamp.png" )
127
+ browser.stubs( :vm ).returns( "VMName" )
128
+ FileUtils.expects( :mkdir_p ).with( "output_path/shots" )
129
+ Kernel.expects( :system ).with( command ).returns( false )
71
130
 
72
- BrowserShooter::Commander.shot( driver, output_path, nil )
131
+ assert_raise( SystemCallError ) do
132
+ BrowserShooter::Commander.shot_system( "driver", browser, "output_path", "sufix" )
73
133
  end
74
134
  end
75
135
 
@@ -29,6 +29,7 @@ class ConfiguratorTest < Test::Unit::TestCase
29
29
  assert_equal( "windows-firefox", models[:browsers].first.name )
30
30
  assert_equal( "http://10.211.55.4:4444/wd/hub", models[:browsers].first.url )
31
31
  assert_equal( "firefox", models[:browsers].first.type )
32
+ assert_equal( "vmName1", models[:browsers].first.vm )
32
33
 
33
34
  assert_equal( 2, models[:suites].size )
34
35
  assert_equal( "suite1", models[:suites].first.name )
@@ -17,14 +17,17 @@ browsers:
17
17
  windows-firefox:
18
18
  url: "http://10.211.55.4:4444/wd/hub"
19
19
  type: "firefox"
20
+ vm: "vmName1"
20
21
 
21
22
  windows-iexplore:
22
23
  url: "http://10.211.55.4:4444/wd/hub"
23
24
  type: "iexploreproxy"
25
+ vm: "vmName2"
24
26
 
25
27
  linux-firefox:
26
28
  url: "http://10.211.55.4:4444/wd/hub"
27
29
  type: "firefox"
30
+ vm: "vmName3"
28
31
 
29
32
  suites:
30
33
  suite1:
@@ -2,9 +2,10 @@ require_relative "../test_helper"
2
2
 
3
3
  class BrowserTest < Test::Unit::TestCase
4
4
  def test_initialize
5
- browser = BrowserShooter::Models::Browser.new( "name", "url", "type")
5
+ browser = BrowserShooter::Models::Browser.new( "name", "url", "type", "vm_name")
6
6
  assert_equal( "name", browser.name )
7
7
  assert_equal( "url", browser.url )
8
8
  assert_equal( "type", browser.type )
9
+ assert_equal( "vm_name", browser.vm )
9
10
  end
10
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser_shooter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-20 00:00:00.000000000Z
12
+ date: 2012-03-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70234217808280 !ruby/object:Gem::Requirement
16
+ requirement: &70311807614080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0.rc.6
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70234217808280
24
+ version_requirements: *70311807614080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70234217807780 !ruby/object:Gem::Requirement
27
+ requirement: &70311807613580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.9.2.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70234217807780
35
+ version_requirements: *70311807613580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mocha
38
- requirement: &70234217807400 !ruby/object:Gem::Requirement
38
+ requirement: &70311807613200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70234217807400
46
+ version_requirements: *70311807613200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: selenium-webdriver
49
- requirement: &70234217837900 !ruby/object:Gem::Requirement
49
+ requirement: &70311807612740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70234217837900
57
+ version_requirements: *70311807612740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mixlib-cli
60
- requirement: &70234217837480 !ruby/object:Gem::Requirement
60
+ requirement: &70311807612320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70234217837480
68
+ version_requirements: *70311807612320
69
69
  description: Selenium RC wraper to create browser screenshots
70
70
  email:
71
71
  - fguillen.mail@gmail.com