browser_shooter 0.0.5 → 0.1.1

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/examples/config4.yml CHANGED
@@ -7,20 +7,30 @@ scripts:
7
7
  commands: |
8
8
  open "/test/browser_shooter/lightbox_bareplayer.html"
9
9
  window_maximize
10
+ shot_system
10
11
  pause 5
11
12
  alert
12
13
  click "link=Show video"
13
14
  pause 5
15
+ shot_system
14
16
  select_frame "_sp_wiframe"
15
17
  run_script "$f().play()"
16
18
  wait_for_element "css=span.enabled", :timeout_in_seconds => 15
19
+ shot_system
17
20
  click "css=span.enabled"
18
- pause 5
21
+ pause 8
22
+ shot_system
19
23
  alert
20
24
 
21
25
  browsers:
22
- windows-firefox:
26
+ osx-firefox:
23
27
  name: "osx-firefox"
24
28
  host: 127.0.0.1
25
29
  port: 4444
26
- browser: "*firefox"
30
+ browser: "*firefox"
31
+
32
+ windows-firefox:
33
+ name: "windows-explorer"
34
+ host: 10.211.55.4
35
+ port: 4444
36
+ browser: "*iexploreproxy"
@@ -1,6 +1,6 @@
1
1
  class BrowserShooter
2
2
  module Commander
3
- def self.execute( command, client, output_path )
3
+ def self.execute( command, client, shots_path )
4
4
  BrowserShooter::Logger.log "command: #{command}"
5
5
 
6
6
  if( command.split[0].strip == "shot" )
@@ -8,7 +8,7 @@ class BrowserShooter
8
8
 
9
9
  BrowserShooter::Commander.shot(
10
10
  client,
11
- output_path,
11
+ shots_path,
12
12
  sufix
13
13
  )
14
14
 
@@ -17,7 +17,7 @@ class BrowserShooter
17
17
 
18
18
  BrowserShooter::Commander.shot_system(
19
19
  client,
20
- output_path,
20
+ shots_path,
21
21
  sufix
22
22
  )
23
23
 
@@ -30,7 +30,7 @@ class BrowserShooter
30
30
  end
31
31
  end
32
32
 
33
- def self.wrapper_execute( command, client, output_path )
33
+ def self.wrapper_execute( command, client, shots_path )
34
34
  result = {
35
35
  :time => Time.now.to_i,
36
36
  :command => command
@@ -41,7 +41,7 @@ class BrowserShooter
41
41
  BrowserShooter::Commander.execute(
42
42
  command,
43
43
  client,
44
- output_path
44
+ shots_path
45
45
  )
46
46
 
47
47
  result.merge!(
@@ -61,8 +61,8 @@ class BrowserShooter
61
61
  end
62
62
 
63
63
  def self.shot( client, path, sufix = nil )
64
- sufix = "_#{sufix}" unless sufix.nil?
65
- path = "#{path}#{sufix}.png"
64
+ sufix = timestamp unless sufix
65
+ path = "#{path}_#{sufix}.png"
66
66
 
67
67
  BrowserShooter::Logger.log "shooting in '#{path}'"
68
68
 
@@ -73,9 +73,9 @@ class BrowserShooter
73
73
  return path
74
74
  end
75
75
 
76
- def self.shot_system( client, path, sufix = nil )
77
- sufix = "_#{sufix}" unless sufix.nil?
78
- path = "#{path}#{sufix}.system.png"
76
+ def self.shot_system( client, path, sufix = timestamp )
77
+ sufix = timestamp unless sufix
78
+ path = "#{path}_#{sufix}.system.png"
79
79
 
80
80
  BrowserShooter::Logger.log "shooting system in '#{path}'"
81
81
 
@@ -92,5 +92,9 @@ class BrowserShooter
92
92
 
93
93
  return "#{seconds} later..."
94
94
  end
95
+
96
+ def self.timestamp
97
+ Time.now.to_i
98
+ end
95
99
  end
96
100
  end
@@ -1,6 +1,6 @@
1
1
  class BrowserShooter
2
2
  module Driver
3
- def self.run_script_on_browser(script, browser, output_path)
3
+ def self.run_script_on_browser(script, browser, shots_path)
4
4
  client = nil
5
5
 
6
6
  begin
@@ -22,7 +22,7 @@ class BrowserShooter
22
22
  BrowserShooter::Commander.wrapper_execute(
23
23
  command.strip,
24
24
  client,
25
- "#{output_path}/#{script["name"]}_#{browser["name"]}"
25
+ "#{shots_path}/#{script["name"]}_#{browser["name"]}"
26
26
  )
27
27
  end
28
28
 
@@ -1,17 +1,17 @@
1
1
  class BrowserShooter
2
2
  module LogExporter
3
- def self.export( path, logs, format )
3
+ def self.export( logs, path, format )
4
4
  BrowserShooter::Logger.log "Exporting '#{format}' logs to #{path}"
5
- send(:"export_to_#{format}", path, logs )
5
+ send(:"export_to_#{format}", logs, path )
6
6
  end
7
7
 
8
- def self.export_to_json( path, logs )
9
- File.open( "#{path}.json", "w" ) do |f|
8
+ def self.export_to_json( logs, path )
9
+ File.open( "#{path}/logs.json", "w" ) do |f|
10
10
  f.write JSON.pretty_generate( logs )
11
11
  end
12
12
  end
13
13
 
14
- def self.export_to_csv( path, logs )
14
+ def self.export_to_csv( logs, path )
15
15
  logs.each do |script_name, results|
16
16
  _path = File.expand_path "#{path}/#{script_name}.csv"
17
17
 
@@ -1,3 +1,3 @@
1
1
  class BrowserShooter
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -26,11 +26,11 @@ class BrowserShooter
26
26
  config["scripts"].each_value do |script|
27
27
  config["browsers"].each_value do |browser|
28
28
  logs["#{script["name"]}_#{browser["name"]}"] =
29
- BrowserShooter::Driver.run_script_on_browser(script, browser, config["output_path"])
29
+ BrowserShooter::Driver.run_script_on_browser(script, browser, "#{config["output_path"]}/shots")
30
30
  end
31
31
  end
32
32
 
33
- BrowserShooter::LogExporter.export( "#{config["output_path"]}/logs", logs, config["logs_format"] )
33
+ BrowserShooter::LogExporter.export( logs, "#{config["output_path"]}/logs", config["logs_format"] )
34
34
 
35
35
  BrowserShooter::Logger.log "... script running ended."
36
36
  BrowserShooter::Logger.log "shots are in: #{config["output_path"]}/shots"
@@ -9,14 +9,14 @@ class BrowserScreenshotTest < Test::Unit::TestCase
9
9
  config_file_path = "#{FIXTURES}/config_simple.yml"
10
10
  BrowserShooter::Configurator.expects( :load_config ).with( config_file_path ).returns( YAML.load_file( config_file_path ) )
11
11
 
12
- BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-one", "browser-one", "/shoots-path" )
13
- BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-one", "browser-two", "/shoots-path" )
14
- BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-one", "browser-three", "/shoots-path" )
15
- BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-two", "browser-one", "/shoots-path" )
16
- BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-two", "browser-two", "/shoots-path" )
17
- BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-two", "browser-three", "/shoots-path" )
12
+ BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-one", "browser-one", "/output_path/shots" )
13
+ BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-one", "browser-two", "/output_path/shots" )
14
+ BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-one", "browser-three", "/output_path/shots" )
15
+ BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-two", "browser-one", "/output_path/shots" )
16
+ BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-two", "browser-two", "/output_path/shots" )
17
+ BrowserShooter::Driver.expects( :run_script_on_browser).with( "script-two", "browser-three", "/output_path/shots" )
18
18
 
19
- BrowserShooter::Util.expects( :export_logs_to_csv )
19
+ BrowserShooter::LogExporter.expects( :export_to_csv )
20
20
 
21
21
  BrowserShooter.new( config_file_path ).run
22
22
  end
@@ -41,6 +41,8 @@ class CommanderTest < Test::Unit::TestCase
41
41
  end
42
42
 
43
43
  def test_shot_without_sufix
44
+ BrowserShooter::Commander.stubs( :timestamp ).returns( "timestamp" )
45
+
44
46
  in_tmpdir do |tmpdir|
45
47
  client = stub( :capture_entire_page_screenshot_to_string => read_fixture( "screenshot.base64" ) )
46
48
  path = "#{tmpdir}/myfile"
@@ -49,7 +51,7 @@ class CommanderTest < Test::Unit::TestCase
49
51
 
50
52
  assert_equal(
51
53
  Digest::MD5.hexdigest( Base64.decode64( read_fixture( "screenshot.base64" ) ) ),
52
- Digest::MD5.hexdigest( File.read( "#{path}.png" ) )
54
+ Digest::MD5.hexdigest( File.read( "#{path}_timestamp.png" ) )
53
55
  )
54
56
  end
55
57
  end
@@ -69,6 +71,8 @@ class CommanderTest < Test::Unit::TestCase
69
71
  end
70
72
 
71
73
  def test_shot_system_without_sufix
74
+ BrowserShooter::Commander.stubs( :timestamp ).returns( "timestamp" )
75
+
72
76
  in_tmpdir do |tmpdir|
73
77
  client = stub( :capture_screenshot_to_string => read_fixture( "screenshot.base64" ) )
74
78
  path = "#{tmpdir}/myfile"
@@ -77,7 +81,7 @@ class CommanderTest < Test::Unit::TestCase
77
81
 
78
82
  assert_equal(
79
83
  Digest::MD5.hexdigest( Base64.decode64( read_fixture( "screenshot.base64" ) ) ),
80
- Digest::MD5.hexdigest( File.read( "#{path}.system.png" ) )
84
+ Digest::MD5.hexdigest( File.read( "#{path}_timestamp.system.png" ) )
81
85
  )
82
86
  end
83
87
  end
@@ -3,13 +3,13 @@ require_relative "test_helper"
3
3
  class ConfiguratorTest < Test::Unit::TestCase
4
4
  def test_load_config
5
5
  BrowserShooter::Configurator.expects( :timestamp ).returns( "timestamp" )
6
- FileUtils.expects( :mkdir_p ).with( "/shoots-path/timestamp" )
7
- FileUtils.expects( :mkdir ).with( "/shoots-path/timestamp/shots" )
8
- FileUtils.expects( :mkdir ).with( "/shoots-path/timestamp/logs" )
6
+ FileUtils.expects( :mkdir_p ).with( "/output_path/timestamp" )
7
+ FileUtils.expects( :mkdir ).with( "/output_path/timestamp/shots" )
8
+ FileUtils.expects( :mkdir ).with( "/output_path/timestamp/logs" )
9
9
 
10
10
  config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config_simple.yml" )
11
11
 
12
- assert_equal( "/shoots-path/timestamp", config["output_path"] )
12
+ assert_equal( "/output_path/timestamp", config["output_path"] )
13
13
  assert_equal( "script-one", config["scripts"]["script-one"] )
14
14
  assert_equal( "browser-one", config["browsers"]["browser-one"] )
15
15
  end
@@ -1,4 +1,4 @@
1
- output_path: "/tmp/shoots"
1
+ output_path: "/tmp/output"
2
2
 
3
3
  scripts:
4
4
  google:
@@ -1,4 +1,4 @@
1
- output_path: "/shoots-path"
1
+ output_path: "/output_path"
2
2
  logs_format: "csv"
3
3
 
4
4
  scripts:
@@ -0,0 +1,24 @@
1
+ {
2
+ "script1": [
3
+ {
4
+ "time": "the time 1",
5
+ "success": true,
6
+ "command": "the command 1",
7
+ "message": "the message 1"
8
+ },
9
+ {
10
+ "time": "the time 2",
11
+ "success": false,
12
+ "command": "the command 2",
13
+ "message": "the message 2"
14
+ }
15
+ ],
16
+ "script2": [
17
+ {
18
+ "time": "the time 3",
19
+ "success": true,
20
+ "command": "the command 3",
21
+ "message": "the message 3"
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,3 @@
1
+ time | success | command | message
2
+ the time 1 | true | the command 1 | the message 1
3
+ the time 2 | false | the command 2 | the message 2
@@ -0,0 +1,2 @@
1
+ time | success | command | message
2
+ the time 3 | true | the command 3 | the message 3
@@ -0,0 +1,62 @@
1
+ require_relative "test_helper"
2
+
3
+ class LogExporterTest < Test::Unit::TestCase
4
+ def setup
5
+ super
6
+
7
+ @logs = {
8
+ "script1" => [
9
+ {
10
+ :time => "the time 1",
11
+ :success => true,
12
+ :command => "the command 1",
13
+ :message => "the message 1"
14
+ },
15
+ {
16
+ :time => "the time 2",
17
+ :success => false,
18
+ :command => "the command 2",
19
+ :message => "the message 2"
20
+ }
21
+ ],
22
+ "script2" => [
23
+ {
24
+ :time => "the time 3",
25
+ :success => true,
26
+ :command => "the command 3",
27
+ :message => "the message 3"
28
+ }
29
+ ]
30
+ }
31
+ end
32
+
33
+ def test_export_should_call_sub_methods
34
+ BrowserShooter::LogExporter.expects( :"export_to_format" ).with( "logs", "path" )
35
+ BrowserShooter::LogExporter.export( "logs", "path", "format" )
36
+ end
37
+
38
+ def test_export_to_json
39
+ in_tmpdir do |path|
40
+ BrowserShooter::LogExporter.export_to_json( @logs, path )
41
+ result = File.read( "#{path}/logs.json" )
42
+
43
+ # File.open( "#{FIXTURES}/logs/logs.json", "w" ) { |f| f.write result }
44
+
45
+ assert_equal( read_fixture( "logs/logs.json" ), result )
46
+ end
47
+ end
48
+
49
+ def test_export_to_csv
50
+ in_tmpdir do |path|
51
+ BrowserShooter::LogExporter.export_to_csv( @logs, path )
52
+ result1 = File.read( "#{path}/script1.csv" )
53
+ result2 = File.read( "#{path}/script2.csv" )
54
+
55
+ # File.open( "#{FIXTURES}/logs/script1.csv", "w" ) { |f| f.write result1 }
56
+ # File.open( "#{FIXTURES}/logs/script2.csv", "w" ) { |f| f.write result2 }
57
+
58
+ assert_equal( read_fixture( "logs/script1.csv" ), result1 )
59
+ assert_equal( read_fixture( "logs/script2.csv" ), result2 )
60
+ end
61
+ end
62
+ 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.0.5
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70249375547000 !ruby/object:Gem::Requirement
16
+ requirement: &70305037223240 !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: *70249375547000
24
+ version_requirements: *70305037223240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70249375546500 !ruby/object:Gem::Requirement
27
+ requirement: &70305037222740 !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: *70249375546500
35
+ version_requirements: *70305037222740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mocha
38
- requirement: &70249375546120 !ruby/object:Gem::Requirement
38
+ requirement: &70305037222360 !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: *70249375546120
46
+ version_requirements: *70305037222360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: selenium-webdriver
49
- requirement: &70249375545660 !ruby/object:Gem::Requirement
49
+ requirement: &70305037221900 !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: *70249375545660
57
+ version_requirements: *70305037221900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: selenium
60
- requirement: &70249375545240 !ruby/object:Gem::Requirement
60
+ requirement: &70305037221480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70249375545240
68
+ version_requirements: *70305037221480
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: selenium-client
71
- requirement: &70249375544820 !ruby/object:Gem::Requirement
71
+ requirement: &70305037221060 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70249375544820
79
+ version_requirements: *70305037221060
80
80
  description: Selenium RC wraper to create browser screenshots
81
81
  email:
82
82
  - fguillen.mail@gmail.com
@@ -97,7 +97,6 @@ files:
97
97
  - examples/config2.yml
98
98
  - examples/config3.yml
99
99
  - examples/config4.yml
100
- - examples/config5.yml
101
100
  - lib/browser_shooter.rb
102
101
  - lib/browser_shooter/commander.rb
103
102
  - lib/browser_shooter/configurator.rb
@@ -111,7 +110,11 @@ files:
111
110
  - test/driver_test.rb
112
111
  - test/fixtures/config.yml
113
112
  - test/fixtures/config_simple.yml
113
+ - test/fixtures/logs/logs.json
114
+ - test/fixtures/logs/script1.csv
115
+ - test/fixtures/logs/script2.csv
114
116
  - test/fixtures/screenshot.base64
117
+ - test/log_exporter_test.rb
115
118
  - test/test_helper.rb
116
119
  homepage: https://github.com/fguillen/BrowserShooter
117
120
  licenses: []
@@ -144,5 +147,9 @@ test_files:
144
147
  - test/driver_test.rb
145
148
  - test/fixtures/config.yml
146
149
  - test/fixtures/config_simple.yml
150
+ - test/fixtures/logs/logs.json
151
+ - test/fixtures/logs/script1.csv
152
+ - test/fixtures/logs/script2.csv
147
153
  - test/fixtures/screenshot.base64
154
+ - test/log_exporter_test.rb
148
155
  - test/test_helper.rb
data/examples/config5.yml DELETED
@@ -1,18 +0,0 @@
1
- output_path: "~/browser_shooter"
2
-
3
- scripts:
4
- lightbox:
5
- name: "lightbox"
6
- url: "http://localhost:3000"
7
- commands: |
8
- open "/test/browser_shooter/lightbox_bareplayer.html"
9
- window_maximize
10
- shot
11
-
12
-
13
- browsers:
14
- windows-firefox:
15
- name: "osx-firefox"
16
- host: 127.0.0.1
17
- port: 4444
18
- browser: "*firefox"