browser_shooter 0.2.3 → 0.3.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.
@@ -0,0 +1,6 @@
1
+ module BrowserShooter
2
+ module Models
3
+ class Browser < Struct.new( :name, :url, :type )
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module BrowserShooter
2
+ module Models
3
+ class Suite < Struct.new( :name, :tests, :browsers )
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module BrowserShooter
2
+ module Models
3
+ class Test < Struct.new( :name, :commands )
4
+ end
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
- class BrowserShooter
2
- VERSION = "0.2.3"
1
+ module BrowserShooter
2
+ VERSION = "0.3.1"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require_relative "test_helper"
2
+
3
+ class ARGVParserTest < Test::Unit::TestCase
4
+ def test_parse_options
5
+ argvs = "-c my/file/path.yml -v -s my_suite -t my_test -b browser1,browser2"
6
+ argv_parser = BrowserShooter::ARGVParsers.new
7
+ argv_parser.parse_options( argvs.split )
8
+
9
+ assert_equal( "my/file/path.yml", argv_parser.config[:config_file] )
10
+ assert_equal( "my_suite", argv_parser.config[:suite] )
11
+ assert_equal( "my_test", argv_parser.config[:test] )
12
+ assert_equal( ["browser1", "browser2"], argv_parser.config[:browsers] )
13
+ assert_equal( true, argv_parser.config[:verbose] )
14
+ end
15
+ end
data/test/base_test.rb ADDED
@@ -0,0 +1,51 @@
1
+ require_relative "test_helper"
2
+
3
+ class BaseTest < Test::Unit::TestCase
4
+ def setup
5
+ super
6
+
7
+ @test1 = BrowserShooter::Models::Test.new( "test1", ["command1", "command2"] )
8
+ @test2 = BrowserShooter::Models::Test.new( "test2", ["command3"] )
9
+ @browser1 = BrowserShooter::Models::Browser.new( "browser1", "url1", "type1" )
10
+ @browser2 = BrowserShooter::Models::Browser.new( "browser2", "url2", "type2" )
11
+ @suite1 = BrowserShooter::Models::Suite.new( "suite1", [@test1, @test2], [@browser1, @browser2] )
12
+ end
13
+
14
+ def test_initialize
15
+ assert_equal( "opts", BrowserShooter::Base.new( "opts" ).opts )
16
+ end
17
+
18
+ def test_run
19
+ BrowserShooter::Configurator.stubs( :set_up_output_path )
20
+
21
+ opts = {}
22
+
23
+ config_mock = mock()
24
+ BrowserShooter::Configurator.expects( :new ).with( opts ).returns( config_mock )
25
+
26
+ config_mock.stubs( :[] ).returns( "config_value" )
27
+ config_mock.expects( :suites ).returns( [@suite1] )
28
+
29
+ BrowserShooter::Base.expects( :run_test ).with( @suite1, @test1, @browser1, "config_value" )
30
+ BrowserShooter::Base.expects( :run_test ).with( @suite1, @test1, @browser2, "config_value" )
31
+ BrowserShooter::Base.expects( :run_test ).with( @suite1, @test2, @browser1, "config_value" )
32
+ BrowserShooter::Base.expects( :run_test ).with( @suite1, @test2, @browser2, "config_value" )
33
+
34
+ BrowserShooter::Base.new( opts ).run
35
+ end
36
+
37
+ def test_run_script
38
+ expected_opts = {
39
+ :url => "url1",
40
+ :desired_capabilities => "type1".to_sym
41
+ }
42
+
43
+ driver = mock()
44
+ driver.expects( :quit )
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" )
47
+ BrowserShooter::LogExporter.expects( :export ).with( "log1", "output_path/suite1/test1/browser1/logs" )
48
+
49
+ BrowserShooter::Base.run_test( @suite1, @test1, @browser1, "output_path" )
50
+ end
51
+ end
@@ -1,54 +1,61 @@
1
1
  require_relative "test_helper"
2
2
 
3
3
  class CommanderTest < Test::Unit::TestCase
4
- def test_execute_when_shot_with_sufix
5
- BrowserShooter::Commander.expects( :shot ).with( "client", "shoot-path", "sufix" )
6
- BrowserShooter::Commander.execute( "shot sufix", "client", "shoot-path" )
7
- end
4
+ def test_script
5
+ commands = [
6
+ "command1",
7
+ " command2 "
8
+ ]
8
9
 
9
- def test_execute_when_shot_without_sufix
10
- BrowserShooter::Commander.expects( :shot ).with( "client", "shoot-path", nil )
11
- BrowserShooter::Commander.execute( "shot", "client", "shoot-path" )
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" )
12
+ BrowserShooter::Logger.expects( :command_result ).twice
13
+ BrowserShooter::Logger.expects( :test_result )
14
+
15
+ result = BrowserShooter::Commander.script( commands, "driver", "output_path" )
16
+
17
+ assert_equal( ["result1", "result2"], result )
12
18
  end
13
19
 
14
- def test_execute_when_shot_system_with_sufix
15
- BrowserShooter::Commander.expects( :shot_system ).with( "client", "shoot-path", "sufix" )
16
- BrowserShooter::Commander.execute( "shot_system sufix", "client", "shoot-path" )
20
+ def test_execute_when_shot_with_sufix
21
+ BrowserShooter::Commander.expects( :shot ).with( "driver", "shoot-path", "sufix" )
22
+ BrowserShooter::Commander.execute( "shot sufix", "driver", "shoot-path" )
17
23
  end
18
24
 
19
- def test_execute_when_shot_system_without_sufix
20
- BrowserShooter::Commander.expects( :shot_system ).with( "client", "shoot-path", nil )
21
- BrowserShooter::Commander.execute( "shot_system", "client", "shoot-path" )
25
+ def test_execute_when_shot_without_sufix
26
+ BrowserShooter::Commander.expects( :shot ).with( "driver", "shoot-path", nil )
27
+ BrowserShooter::Commander.execute( "shot", "driver", "shoot-path" )
22
28
  end
23
29
 
24
30
  def test_execute_when_pause
25
31
  BrowserShooter::Commander.expects( :pause ).with( 10 )
26
- BrowserShooter::Commander.execute( "pause 10", "client", "shoot-path" )
32
+ BrowserShooter::Commander.execute( "pause 10", "driver", "shoot-path" )
27
33
  end
28
34
 
29
35
  def test_execute_when_wait_for_element
30
- BrowserShooter::Commander.expects( :wait_for_element ).with( "client", "css_selector", 10 )
31
- BrowserShooter::Commander.execute( "wait_for_element \"css_selector\", 10", "client", nil )
36
+ BrowserShooter::Commander.expects( :wait_for_element ).with( "driver", "css_selector", 10 )
37
+ BrowserShooter::Commander.execute( "wait_for_element \"css_selector\", 10", "driver", nil )
32
38
  end
33
39
 
34
40
  def test_execute_when_click
35
- BrowserShooter::Commander.expects( :click ).with( "client", "css_selector" )
36
- BrowserShooter::Commander.execute( "click \"css_selector\"", "client", nil )
41
+ BrowserShooter::Commander.expects( :click ).with( "driver", "css_selector" )
42
+ BrowserShooter::Commander.execute( "click \"css_selector\"", "driver", nil )
37
43
  end
38
44
 
39
45
  def test_execute_when_type
40
- BrowserShooter::Commander.expects( :type ).with( "client", "css_selector", "message a b" )
41
- BrowserShooter::Commander.execute( "type \"css_selector\", \"message a b\"", "client", nil )
46
+ BrowserShooter::Commander.expects( :type ).with( "driver", "css_selector", "message a b" )
47
+ BrowserShooter::Commander.execute( "type \"css_selector\", \"message a b\"", "driver", nil )
42
48
  end
43
49
 
44
50
  def test_shot_with_sufix
45
51
  in_tmpdir do |tmpdir|
46
- client = mock()
47
- path = "#{tmpdir}/myfile"
52
+ driver = mock()
53
+ output_path = tmpdir
48
54
 
49
- client.expects( :save_screenshot ).with( "#{path}_sufix.png" )
55
+ FileUtils.expects( :mkdir_p ).with( "#{output_path}/shots" )
56
+ driver.expects( :save_screenshot ).with( "#{output_path}/shots/sufix.png" )
50
57
 
51
- BrowserShooter::Commander.shot( client, path, "sufix" )
58
+ BrowserShooter::Commander.shot( driver, output_path, "sufix" )
52
59
  end
53
60
  end
54
61
 
@@ -56,75 +63,45 @@ class CommanderTest < Test::Unit::TestCase
56
63
  BrowserShooter::Commander.stubs( :timestamp ).returns( "timestamp" )
57
64
 
58
65
  in_tmpdir do |tmpdir|
59
- client = mock()
60
- path = "#{tmpdir}/myfile"
66
+ driver = mock()
67
+ output_path = tmpdir
61
68
 
62
- client.expects( :save_screenshot ).with( "#{path}_timestamp.png" )
69
+ FileUtils.expects( :mkdir_p ).with( "#{output_path}/shots" )
70
+ driver.expects( :save_screenshot ).with( "#{output_path}/shots/timestamp.png" )
63
71
 
64
- BrowserShooter::Commander.shot( client, path, nil )
72
+ BrowserShooter::Commander.shot( driver, output_path, nil )
65
73
  end
66
74
  end
67
75
 
68
- # FIXME: shot_system not supported in WebDriver
69
- # def test_shot_system_with_sufix
70
- # in_tmpdir do |tmpdir|
71
- # client = stub( :capture_screenshot_to_string => read_fixture( "screenshot.base64" ) )
72
- # path = "#{tmpdir}/myfile"
73
-
74
- # BrowserShooter::Commander.shot_system( client, path, "sufix" )
75
-
76
- # assert_equal(
77
- # Digest::MD5.hexdigest( Base64.decode64( read_fixture( "screenshot.base64" ) ) ),
78
- # Digest::MD5.hexdigest( File.read( "#{path}_sufix.system.png" ) )
79
- # )
80
- # end
81
- # end
82
-
83
- # def test_shot_system_without_sufix
84
- # BrowserShooter::Commander.stubs( :timestamp ).returns( "timestamp" )
85
-
86
- # in_tmpdir do |tmpdir|
87
- # client = stub( :capture_screenshot_to_string => read_fixture( "screenshot.base64" ) )
88
- # path = "#{tmpdir}/myfile"
89
-
90
- # BrowserShooter::Commander.shot_system( client, path, nil )
91
-
92
- # assert_equal(
93
- # Digest::MD5.hexdigest( Base64.decode64( read_fixture( "screenshot.base64" ) ) ),
94
- # Digest::MD5.hexdigest( File.read( "#{path}_timestamp.system.png" ) )
95
- # )
96
- # end
97
- # end
98
-
99
76
  def test_wait_for_element
100
77
  wait = mock()
101
- client = mock()
78
+ driver = mock()
102
79
 
103
80
  Selenium::WebDriver::Wait.expects( :new ).with( :timeout => 10 ).returns( wait )
104
81
  wait.expects( :until ).yields
105
- client.expects( :find_element ).with( "css", "css_selector" )
82
+ driver.expects( :find_element ).with( "css", "css_selector" )
106
83
 
107
- BrowserShooter::Commander.wait_for_element( client, "css_selector", 10 )
84
+ BrowserShooter::Commander.wait_for_element( driver, "css_selector", 10 )
108
85
  end
109
86
 
110
87
  def test_click
111
- client = mock()
88
+ driver = mock()
112
89
  element = mock()
113
90
 
114
- client.expects( :find_element ).with( "css", "css_selector" ).returns( element )
91
+ driver.expects( :find_element ).with( "css", "css_selector" ).returns( element )
115
92
  element.expects( :click )
116
93
 
117
- BrowserShooter::Commander.click( client, "css_selector" )
94
+ BrowserShooter::Commander.click( driver, "css_selector" )
118
95
  end
119
96
 
120
97
  def test_type
121
- client = mock()
98
+ driver = mock()
122
99
  element = mock()
123
100
 
124
- client.expects( :find_element ).with( "css", "css_selector" ).returns( element )
101
+ driver.expects( :find_element ).with( "css", "css_selector" ).returns( element )
125
102
  element.expects( :send_keys ).with( "message" )
126
103
 
127
- BrowserShooter::Commander.type( client, "css_selector", "message" )
104
+ BrowserShooter::Commander.type( driver, "css_selector", "message" )
128
105
  end
129
106
 
130
107
  def test_pause
@@ -1,11 +1,77 @@
1
1
  require_relative "test_helper"
2
2
 
3
3
  class ConfiguratorTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ opts = { :config_file => "config_file" }
6
+ config = { :key1 => "value1" }
7
+
8
+ BrowserShooter::Configurator.expects( :load_config ).with( "config_file" ).returns( config )
9
+ BrowserShooter::Configurator.expects( :build_models ).with( config ).returns( "models" )
10
+ BrowserShooter::Configurator.expects( :filter_suites ).with( "models", opts ).returns( "suites" )
11
+
12
+ configurator = BrowserShooter::Configurator.new( opts )
13
+
14
+ assert_equal( "value1", configurator[:key1] )
15
+ assert_equal( "suites", configurator.suites )
16
+ end
17
+
18
+ def test_build_models
19
+ BrowserShooter::Configurator.stubs( :set_up_output_path )
20
+ config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config.yml" )
21
+ models = BrowserShooter::Configurator.build_models( config )
22
+
23
+ assert_equal( 2, models[:tests].size )
24
+ assert_equal( "google", models[:tests].first.name )
25
+ assert_equal( 6, models[:tests].first.commands.size )
26
+ assert_equal( "navigate.to \"http://www.google.de\"", models[:tests].first.commands.first )
27
+
28
+ assert_equal( 3, models[:browsers].size )
29
+ assert_equal( "windows-firefox", models[:browsers].first.name )
30
+ assert_equal( "http://10.211.55.4:4444/wd/hub", models[:browsers].first.url )
31
+ assert_equal( "firefox", models[:browsers].first.type )
32
+
33
+ assert_equal( 2, models[:suites].size )
34
+ assert_equal( "suite1", models[:suites].first.name )
35
+ assert_equal( 2, models[:suites].first.tests.size )
36
+ assert_equal( models[:tests].first, models[:suites].first.tests.first )
37
+ assert_equal( 2, models[:suites].first.browsers.size )
38
+ assert_equal( models[:browsers].first, models[:suites].first.browsers.first )
39
+ end
40
+
41
+ def test_filter_suites
42
+ BrowserShooter::Configurator.stubs( :set_up_output_path )
43
+ config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config.yml" )
44
+ models = BrowserShooter::Configurator.build_models( config )
45
+
46
+ opts = {}
47
+ suites = BrowserShooter::Configurator.filter_suites( models, opts )
48
+ assert_equal( 2, suites.size )
49
+
50
+ opts = { :suite => "suite2" }
51
+ suites = BrowserShooter::Configurator.filter_suites( models, opts )
52
+ assert_equal( 1, suites.size )
53
+ assert_equal( "suite2", suites.first.name )
54
+
55
+ opts = { :test => "google" }
56
+ suites = BrowserShooter::Configurator.filter_suites( models, opts )
57
+ assert_equal( 1, suites.size )
58
+ assert_equal( "anonymous", suites.first.name )
59
+ assert_equal( 1, suites.first.tests.size )
60
+ assert_equal( "google", suites.first.tests.first.name )
61
+ assert_equal( 3, suites.first.browsers.size )
62
+
63
+ opts = { :test => "google", :browsers => ["windows-firefox", "windows-iexplore"] }
64
+ suites = BrowserShooter::Configurator.filter_suites( models, opts )
65
+ assert_equal( 1, suites.size )
66
+ assert_equal( "anonymous", suites.first.name )
67
+ assert_equal( 1, suites.first.tests.size )
68
+ assert_equal( "google", suites.first.tests.first.name )
69
+ assert_equal( 2, suites.first.browsers.size )
70
+ assert_equal( "windows-firefox", suites.first.browsers.first.name )
71
+ end
72
+
4
73
  def test_load_config
5
74
  BrowserShooter::Configurator.expects( :timestamp ).returns( "timestamp" )
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
75
 
10
76
  config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config_simple.yml" )
11
77
 
@@ -1,34 +1,43 @@
1
1
  output_path: "/tmp/output"
2
2
 
3
- scripts:
4
- google:
5
- name: "google"
6
- commands: |
7
- navigate.to "http://www.google.de"
8
- shot 01_before
9
- type "id=lst-ib", "fernando guillen"
10
- click "name=btnG", wait_for :page
11
- pause 3
12
- shot 02_after
3
+ tests:
4
+ google: |
5
+ navigate.to "http://www.google.de"
6
+ shot 01_before
7
+ type "id=lst-ib", "fernando guillen"
8
+ click "name=btnG", wait_for :page
9
+ pause 3
10
+ shot 02_after
13
11
 
14
- miniclip:
15
- name: "miniclip"
16
- commands: |
17
- navigate.to "http://www.miniclip.com/games/de/"
18
- shot
12
+ miniclip: |
13
+ navigate.to "http://www.miniclip.com/games/de/"
14
+ shot
19
15
 
20
16
  browsers:
21
17
  windows-firefox:
22
- name: "windows-firefox"
23
18
  url: "http://10.211.55.4:4444/wd/hub"
24
- browser: "firefox"
19
+ type: "firefox"
25
20
 
26
21
  windows-iexplore:
27
- name: "windows-iexploreproxy"
28
22
  url: "http://10.211.55.4:4444/wd/hub"
29
- browser: "iexploreproxy"
23
+ type: "iexploreproxy"
30
24
 
31
25
  linux-firefox:
32
- name: "linux-firefox"
33
26
  url: "http://10.211.55.4:4444/wd/hub"
34
- browser: "firefox"
27
+ type: "firefox"
28
+
29
+ suites:
30
+ suite1:
31
+ tests:
32
+ - google
33
+ - miniclip
34
+ browsers:
35
+ - windows-firefox
36
+ - windows-iexplore
37
+
38
+ suite2:
39
+ tests:
40
+ - miniclip
41
+ browsers:
42
+ - windows-firefox
43
+ - linux-firefox
@@ -5,6 +5,9 @@ scripts:
5
5
  script-one: "script-one"
6
6
  script-two: "script-two"
7
7
 
8
+ suites:
9
+ suite-one: "suite-one"
10
+
8
11
  browsers:
9
12
  browser-one: "browser-one"
10
13
  browser-two: "browser-two"
@@ -1,3 +1,3 @@
1
1
  time | success | command | message
2
- the time 1 | true | the command 1 | the message 1
2
+ the time 1 | true | the command 1 | the message 1 - with 2 lines
3
3
  the time 2 | false | the command 2 | the message 2
@@ -4,59 +4,41 @@ class LogExporterTest < Test::Unit::TestCase
4
4
  def setup
5
5
  super
6
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
- }
7
+ @logs = [
8
+ {
9
+ :time => "the time 1",
10
+ :success => true,
11
+ :command => "the command 1",
12
+ :message => "the message 1 \n with 2 lines"
13
+ },
14
+ {
15
+ :time => "the time 2",
16
+ :success => false,
17
+ :command => "the command 2",
18
+ :message => "the message 2"
19
+ }
20
+ ]
31
21
  end
32
22
 
33
23
  def test_export_should_call_sub_methods
34
- BrowserShooter::LogExporter.expects( :"export_to_format" ).with( "logs", "path" )
24
+ BrowserShooter::LogExporter.expects( :export_to_format ).with( "logs", File.expand_path( "path/log.format" ) )
35
25
  BrowserShooter::LogExporter.export( "logs", "path", "format" )
36
26
  end
37
27
 
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
28
+ def the_export_should_create_dir
29
+ BrowserShooter::LogExporter.stubs( :export_to_format )
30
+ FileUtils.expects( :mkdir_p ).with( File.expand_path( "output_path/log.format" ) )
31
+ BrowserShooter::LogExporter.export( "logs", "output_path", "format" )
47
32
  end
48
33
 
49
34
  def test_export_to_csv
50
35
  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" )
36
+ BrowserShooter::LogExporter.export_to_csv( @logs, "#{path}/log.csv" )
37
+ result = File.read( "#{path}/log.csv" )
54
38
 
55
- # File.open( "#{FIXTURES}/logs/script1.csv", "w" ) { |f| f.write result1 }
56
- # File.open( "#{FIXTURES}/logs/script2.csv", "w" ) { |f| f.write result2 }
39
+ # File.open( "#{FIXTURES}/logs/log.csv", "w" ) { |f| f.write result }
57
40
 
58
- assert_equal( read_fixture( "logs/script1.csv" ), result1 )
59
- assert_equal( read_fixture( "logs/script2.csv" ), result2 )
41
+ assert_equal( read_fixture( "logs/log.csv" ), result )
60
42
  end
61
43
  end
62
44
  end