browser_shooter 0.3.9 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ # Parse all the _shell commands params_
1
2
  module BrowserShooter
2
3
  class ARGVParsers
3
4
  include Mixlib::CLI
@@ -6,6 +6,7 @@ module BrowserShooter
6
6
  @opts = opts
7
7
  end
8
8
 
9
+ # Main method. Loads the configuration, filter the suites, runs the tests and exports the logs.
9
10
  def run
10
11
  BrowserShooter::Logger.verbose = opts[:verbose]
11
12
  BrowserShooter::Logger.log( "Starting script running with version #{BrowserShooter::VERSION}..." )
@@ -31,6 +32,7 @@ module BrowserShooter
31
32
  BrowserShooter::Logger.log( "BYE!" )
32
33
  end
33
34
 
35
+ # Runs a single test with all its _commands_ in an specific _browser_
34
36
  def self.run_test( suite, test, browser, config )
35
37
  BrowserShooter::Logger.log( "Executing #{suite.name} | #{test.name} | #{browser.name}", true )
36
38
  output_path = "#{config["output_path"]}/#{suite.name}/#{test.name}/#{browser.name}"
@@ -1,7 +1,15 @@
1
1
  module BrowserShooter::Commander
2
2
 
3
+ # Executes a test _script_ with all _its_ commands.
4
+ #
5
+ # Returns: the test result in this format:
6
+ # {
7
+ # :time => (the actual time),
8
+ # :success => (true|false),
9
+ # :command => (the actual command),
10
+ # :message => (the command message or error message),
11
+ # }
3
12
  def self.script( commands, driver, browser, output_path )
4
-
5
13
  command_executor =
6
14
  BrowserShooter::Commands::Base.new(
7
15
  driver,
@@ -2,6 +2,7 @@ module BrowserShooter
2
2
  class Configurator
3
3
  attr_reader :suites
4
4
 
5
+ # Takes the digested command options and create and filter the models
5
6
  def initialize( opts )
6
7
  @config = BrowserShooter::Configurator.load_config( opts[:config_file] )
7
8
  models = BrowserShooter::Configurator.build_models( @config )
@@ -10,45 +11,26 @@ module BrowserShooter
10
11
  BrowserShooter::Configurator.load_extensions( @config["extensions"] ) if @config["extensions"]
11
12
  end
12
13
 
14
+ # The hash version of the _config.yml_ is available here
13
15
  def [](value)
14
16
  @config[value]
15
17
  end
16
18
 
17
- def self.filter_suites( models, opts )
18
- suites = []
19
-
20
- if( opts[:suite] )
21
- suite = models[:suites].select{ |e| e.name == opts[:suite] }.first
22
- raise ArgumentError, "Not suite found '#{opts[:suite]}'" if suite.nil?
23
-
24
- suites = [suite]
25
-
26
- elsif( opts[:test] && opts[:browsers] )
27
- test = models[:tests].select{ |e| e.name == opts[:test] }.first
28
- raise ArgumentError, "Not test found '#{opts[:test]}'" if test.nil?
29
-
30
- browsers = models[:browsers].select{ |e| opts[:browsers].include? e.name }
31
- raise ArgumentError, "Not browsers found '#{opts[:browsers].join( "," )}'" if browsers.empty?
32
-
33
- suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers )
34
- suites = [suite]
35
-
36
- elsif( opts[:test] )
37
- test = models[:tests].select{ |e| e.name == opts[:test] }.first
38
- raise ArgumentError, "Not test found '#{opts[:test]}'" if test.nil?
39
-
40
- browsers = models[:browsers]
41
- suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers )
42
- suites = [suite]
19
+ # Load the _config.yml_ file and return it in a Hash format
20
+ def self.load_config( config_file_path )
21
+ config = {
22
+ "output_path" => "~/browser_shooter",
23
+ "timeout" => 40
24
+ }
43
25
 
44
- else
45
- suites = models[:suites]
26
+ config.merge! YAML.load_file( config_file_path )
46
27
 
47
- end
28
+ config["output_path"] = setup_output_path( config["output_path"] )
48
29
 
49
- suites
30
+ config
50
31
  end
51
32
 
33
+ # Creates the _tests_, _browsers_ and _suites_ arrays.
52
34
  def self.build_models( config )
53
35
  tests =
54
36
  config["tests"].map do |name, commands|
@@ -64,8 +46,8 @@ module BrowserShooter
64
46
 
65
47
  suites =
66
48
  config["suites"].map do |name, opts|
67
- suite_tests = tests.select{ |e| opts["tests"].include? e.name }
68
- suite_browsers = browsers.select{ |e| opts["browsers"].include? e.name }
49
+ suite_tests = BrowserShooter::Utils.find_by_names( tests, opts["tests"] )
50
+ suite_browsers = BrowserShooter::Utils.find_by_names( browsers, opts["browsers"] )
69
51
 
70
52
  BrowserShooter::Models::Suite.new( name, suite_tests, suite_browsers )
71
53
  end
@@ -77,21 +59,40 @@ module BrowserShooter
77
59
  }
78
60
  end
79
61
 
80
- def self.load_config( config_file_path )
81
- config = {
82
- "output_path" => "~/browser_shooter",
83
- "timeout" => 40
84
- }
62
+ # If special _filter_ options has been defined in the _command options_ the _suites_ are filtered
63
+ # to only play with the filtered ones.
64
+ def self.filter_suites( models, opts )
65
+ suites = []
85
66
 
86
- config.merge! YAML.load_file( config_file_path )
67
+ if( opts[:suite] )
68
+ suite = BrowserShooter::Utils.find_by_name( models[:suites], opts[:suite] )
87
69
 
88
- config["output_path"] = setup_output_path( config["output_path"] )
70
+ suites = [suite]
89
71
 
90
- config
72
+ elsif( opts[:test] && opts[:browsers] )
73
+ test = BrowserShooter::Utils.find_by_name( models[:tests], opts[:test] )
74
+ browsers = BrowserShooter::Utils.find_by_names( models[:browsers], opts[:browsers] )
75
+ suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers )
76
+
77
+ suites = [suite]
78
+
79
+ elsif( opts[:test] )
80
+ test = BrowserShooter::Utils.find_by_name( models[:tests], opts[:test] )
81
+ browsers = models[:browsers]
82
+ suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers )
83
+
84
+ suites = [suite]
85
+
86
+ else
87
+ suites = models[:suites]
88
+
89
+ end
90
+
91
+ suites
91
92
  end
92
93
 
93
94
  def self.setup_output_path( output_path )
94
- output_path = File.expand_path( "#{output_path}/#{timestamp}" )
95
+ output_path = File.expand_path( "#{output_path}/#{BrowserShooter::Utils.timestamp}" )
95
96
  BrowserShooter::Logger.log( "output_path: #{output_path}" )
96
97
 
97
98
  output_path
@@ -105,8 +106,5 @@ module BrowserShooter
105
106
  end
106
107
  end
107
108
 
108
- def self.timestamp
109
- Time.now.strftime("%Y%m%d%H%M%S")
110
- end
111
109
  end
112
110
  end
@@ -1,7 +1,18 @@
1
1
  module BrowserShooter
2
2
  module Utils
3
3
  def self.timestamp
4
- Time.now.to_i
4
+ Time.now.strftime( "%Y%m%d%H%M%S" )
5
+ end
6
+
7
+ def self.find_by_name( array, name )
8
+ element = array.select{ |e| e.name == name }.first
9
+ raise ArgumentError, "Not element found '#{name}'" if element.nil?
10
+
11
+ element
12
+ end
13
+
14
+ def self.find_by_names( array, names )
15
+ names.map { |name| find_by_name( array, name ) }
5
16
  end
6
17
  end
7
18
  end
@@ -1,3 +1,3 @@
1
1
  module BrowserShooter
2
- VERSION = "0.3.9"
2
+ VERSION = "0.3.11"
3
3
  end
@@ -85,8 +85,29 @@ class ConfiguratorTest < Test::Unit::TestCase
85
85
  assert_equal( "windows-firefox", suites.first.browsers.first.name )
86
86
  end
87
87
 
88
+ def test_filter_suites_with_error
89
+ BrowserShooter::Configurator.stubs( :setup_output_path )
90
+ config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config.yml" )
91
+ models = BrowserShooter::Configurator.build_models( config )
92
+
93
+ opts = { :suite => "not_exists" }
94
+ assert_raise( ArgumentError ) do
95
+ BrowserShooter::Configurator.filter_suites( models, opts )
96
+ end
97
+
98
+ opts = { :test => "not_exists" }
99
+ assert_raise( ArgumentError ) do
100
+ BrowserShooter::Configurator.filter_suites( models, opts )
101
+ end
102
+
103
+ opts = { :test => "google", :browsers => ["not_exists"] }
104
+ assert_raise( ArgumentError ) do
105
+ BrowserShooter::Configurator.filter_suites( models, opts )
106
+ end
107
+ end
108
+
88
109
  def test_load_config
89
- BrowserShooter::Configurator.expects( :timestamp ).returns( "timestamp" )
110
+ BrowserShooter::Utils.expects( :timestamp ).returns( "timestamp" )
90
111
 
91
112
  config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config_simple.yml" )
92
113
 
@@ -97,7 +118,7 @@ class ConfiguratorTest < Test::Unit::TestCase
97
118
  end
98
119
 
99
120
  def test_load_config_with_defaults
100
- BrowserShooter::Configurator.expects( :timestamp ).returns( "timestamp" )
121
+ BrowserShooter::Utils.expects( :timestamp ).returns( "timestamp" )
101
122
 
102
123
  config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config_empty.yml" )
103
124
 
@@ -110,4 +131,22 @@ class ConfiguratorTest < Test::Unit::TestCase
110
131
  Kernel.expects( :require ).with( File.expand_path( "extension2.rb" ) )
111
132
  BrowserShooter::Configurator.load_extensions( ["extension1.rb", "extension2.rb"] )
112
133
  end
134
+
135
+ def test_suite_tests_in_order
136
+ BrowserShooter::Configurator.stubs( :setup_output_path )
137
+ config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config_in_order.yml" )
138
+ models = BrowserShooter::Configurator.build_models( config )
139
+
140
+ assert_equal( 2, models[:suites].first.tests.size )
141
+ assert_equal( "test2", models[:suites].first.tests.first.name )
142
+ end
143
+
144
+ def test_suite_browsers_in_order
145
+ BrowserShooter::Configurator.stubs( :setup_output_path )
146
+ config = BrowserShooter::Configurator.load_config( "#{FIXTURES}/config_in_order.yml" )
147
+ models = BrowserShooter::Configurator.build_models( config )
148
+
149
+ assert_equal( 2, models[:suites].first.browsers.size )
150
+ assert_equal( "browser2", models[:suites].first.browsers.first.name )
151
+ end
113
152
  end
@@ -0,0 +1,21 @@
1
+ tests:
2
+ test1: commands
3
+ test2: commands
4
+
5
+ browsers:
6
+ browser1:
7
+ url: "http://10.211.55.4:4444/wd/hub"
8
+ type: "firefox"
9
+
10
+ browser2:
11
+ url: "http://10.211.55.4:4444/wd/hub"
12
+ type: "iexploreproxy"
13
+
14
+ suites:
15
+ suite1:
16
+ tests:
17
+ - test2
18
+ - test1
19
+ browsers:
20
+ - browser2
21
+ - browser1
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.9
4
+ version: 0.3.11
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-04-02 00:00:00.000000000Z
12
+ date: 2012-04-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70301246657780 !ruby/object:Gem::Requirement
16
+ requirement: &70295546959160 !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: *70301246657780
24
+ version_requirements: *70295546959160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70301246657280 !ruby/object:Gem::Requirement
27
+ requirement: &70295546958660 !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: *70301246657280
35
+ version_requirements: *70295546958660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mocha
38
- requirement: &70301246656900 !ruby/object:Gem::Requirement
38
+ requirement: &70295546958280 !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: *70301246656900
46
+ version_requirements: *70295546958280
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: selenium-webdriver
49
- requirement: &70301246656440 !ruby/object:Gem::Requirement
49
+ requirement: &70295546957820 !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: *70301246656440
57
+ version_requirements: *70295546957820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mixlib-cli
60
- requirement: &70301246656020 !ruby/object:Gem::Requirement
60
+ requirement: &70295546957400 !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: *70301246656020
68
+ version_requirements: *70295546957400
69
69
  description: Selenium RC wraper to create browser screenshots
70
70
  email:
71
71
  - fguillen.mail@gmail.com
@@ -111,6 +111,7 @@ files:
111
111
  - test/configurator_test.rb
112
112
  - test/fixtures/config.yml
113
113
  - test/fixtures/config_empty.yml
114
+ - test/fixtures/config_in_order.yml
114
115
  - test/fixtures/config_simple.yml
115
116
  - test/fixtures/logs/log.csv
116
117
  - test/fixtures/screenshot.base64
@@ -153,6 +154,7 @@ test_files:
153
154
  - test/configurator_test.rb
154
155
  - test/fixtures/config.yml
155
156
  - test/fixtures/config_empty.yml
157
+ - test/fixtures/config_in_order.yml
156
158
  - test/fixtures/config_simple.yml
157
159
  - test/fixtures/logs/log.csv
158
160
  - test/fixtures/screenshot.base64