easy-automation 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,6 +56,41 @@ You have a lot of [actions](http://selenium.rubyforge.org/rdoc/classes/Selenium/
56
56
 
57
57
  More Reference: http://selenium.rubyforge.org/rdoc/classes/Selenium/
58
58
 
59
+ Runner - Configuring your tests
60
+ ------
61
+ You can change any behaviour using EasyAutomation::Runner.config helper, options:
62
+ EasyAutomation::Runner.configure do |config|
63
+ # Selenium Configurations
64
+ config.url = "http://www.google.com"
65
+ config.browser = "*safari" # "*firefox", "*chrome"
66
+ config.selenium_port = 4444
67
+ config.selenium_timeout = 1000
68
+ #if specified, it won't start selenium RC and will attempt to connect to remote selenium server
69
+ config.selenium_host = "localhost"
70
+
71
+ # Hooks
72
+ config.before :all do
73
+ puts 'Starting Tests'
74
+ end
75
+ config.after :all do
76
+ puts 'Tests finished, halting'
77
+ end
78
+
79
+ config.before :each_test do
80
+ # Do something
81
+ end
82
+ config.after :each_test do
83
+ # Do something
84
+ end
85
+
86
+ config.before :each_suite do
87
+ # Do something
88
+ end
89
+ config.after :each_suite do
90
+ # Do something
91
+ end
92
+ end
93
+
59
94
  Example
60
95
  -------
61
96
  Structure:
@@ -129,6 +164,8 @@ Find some working code under examples folder, to see it search exmple on action,
129
164
  Roadmap
130
165
  -------
131
166
  * More hooks [before|after] [:all|:each] [:test|:suite]
167
+ * Update Selenium gem to use latest selenium-RC and fix weird firefox crashes.
168
+ * Multi browser
132
169
  * Wait for element to be loaded event
133
170
  * Rake integration
134
171
  * Retry on failed tests
@@ -140,6 +177,21 @@ Roadmap
140
177
 
141
178
  Order may matter
142
179
 
180
+
181
+ Version Changes
182
+ --------
183
+
184
+ From 0.0.1 to 0.0.2
185
+ --------
186
+ * Multiple browsers support
187
+ * [before|after] [:all|:each] [:test|:suite] hooks
188
+ * Remote Selenium RC
189
+
190
+ From 0.0.2 to 0.1.0
191
+ -------
192
+ * Retry failed tests
193
+ * Selenium Grid integration
194
+
143
195
  Contributing
144
196
  ------------
145
197
 
@@ -5,7 +5,9 @@ require 'easy_automation/data_elements'
5
5
  require 'easy_automation/load_data'
6
6
  require 'easy_automation/page'
7
7
  require 'easy_automation/runner'
8
+ require 'easy_automation/remote_server'
8
9
  require 'easy_automation/server'
10
+ require 'easy_automation/selenium'
9
11
  require 'easy_automation/suite'
10
12
  require 'easy_automation/test'
11
13
  require 'easy_automation/version'
@@ -8,21 +8,40 @@ module EasyAutomation
8
8
  class Config
9
9
  attr_accessor :selenium_port
10
10
  attr_accessor :selenium_timeout
11
- attr_accessor :browser
11
+ attr_accessor :selenium_host
12
12
  attr_accessor :url
13
+ attr_accessor :current_browser
14
+ attr_accessor :browsers
13
15
  attr_reader :hooks
14
16
 
17
+
15
18
  #
16
19
  # Default settings for selenium RC
17
20
  #
18
21
  def initialize
22
+ @browsers = []
19
23
  @selenium_port = 4444
20
- @selenium_timeout = 1000
21
- @browser = "Firefox"
24
+ @selenium_timeout = 4000
22
25
  @url = "http://www.google.com"
23
26
  @hooks = {:before => {}, :after =>{}}
24
27
  end
25
28
 
29
+ def browser=(browser)
30
+ @browsers = [browser]
31
+ end
32
+
33
+ def add_browser browser
34
+ @browsers << browser
35
+ end
36
+
37
+ def browsers
38
+ @browsers.empty? ? ["* firefox"] : @browsers
39
+ end
40
+
41
+ def current_browser
42
+ @current_browser || @browsers.first
43
+ end
44
+
26
45
  def before hook, &block
27
46
  @hooks[:before].merge!({hook.to_sym => block}) if block_given?
28
47
  end
@@ -35,9 +54,5 @@ module EasyAutomation
35
54
  @hooks[type.to_sym][hook_name.to_sym].call if @hooks[type.to_sym][hook_name.to_sym]
36
55
  end
37
56
 
38
- def load_files pattern
39
- puts '888888888888 ENTRE!!!'
40
- Dir[pattern].each { |f| require f }
41
- end
42
57
  end
43
- end
58
+ end
@@ -6,15 +6,15 @@
6
6
  #
7
7
  module EasyAutomation
8
8
  class DataElements
9
- @elements = {}
10
9
 
11
10
  #
12
11
  # Builds magic functions to handle elements
13
12
  # @params hash key => value
14
13
  #
15
14
  def initialize(elements)
16
- @elements = elements
17
- elements.each do |key, value|
15
+ @elements = {}
16
+ @elements.merge!(elements || {})
17
+ @elements.each do |key, value|
18
18
  if (value.class.to_s == "Array" || value.class.to_s == "Hash")
19
19
  eval (%{
20
20
  def #{key}
@@ -0,0 +1,26 @@
1
+ module EasyAutomation
2
+ class RemoteServer
3
+ def driver(browser_start_command, browser_url, port, timeout)
4
+ ::Selenium::SeleniumDriver.new('localhost', port, browser_start_command, browser_url, timeout * 1000)
5
+ end
6
+
7
+ def open(browser_start_command, browser_url)
8
+ url = URI.parse(browser_url)
9
+ browser = driver(browser_start_command,
10
+ URI::Generic::new(url.scheme, url.userinfo, url.host, url.port, nil, nil, nil, nil, nil),
11
+ Runner.configuration.selenium_port,
12
+ Runner.configuration.selenium_timeout)
13
+ browser.start
14
+ browser.open(url.request_uri)
15
+ page = ::Selenium::WebPage.new(browser)
16
+ page.wait_for_load
17
+ page
18
+ end
19
+
20
+ def start
21
+ end
22
+
23
+ def stop
24
+ end
25
+ end
26
+ end
@@ -26,10 +26,6 @@ module EasyAutomation
26
26
  @configuration
27
27
  end
28
28
 
29
- def server
30
- @selenium_server ||= Server.new
31
- end
32
-
33
29
  def configure
34
30
  yield configuration
35
31
  end
@@ -38,7 +34,10 @@ module EasyAutomation
38
34
  raise RunnerSuiteException.new('Wrong test suite class') unless test_suite.is_a?(Suite)
39
35
  Server.rc.start
40
36
  configuration.execute :before, :all
41
- ::Test::Unit::UI::Console::TestRunner.run test_suite
37
+ configuration.browsers.each do |browser|
38
+ configuration.current_browser = browser
39
+ ::Test::Unit::UI::Console::TestRunner.run test_suite
40
+ end
42
41
  configuration.execute :after, :all
43
42
  Server.rc.stop
44
43
  end
@@ -0,0 +1,17 @@
1
+ require 'net/http'
2
+ # Original code is found on Selenium gem, I just have to modify stop command and specify a newer version of selenium-RC
3
+ # it changed in selenium 1.0.3
4
+ # All credit is thanks to Selenium gem authors
5
+ module Selenium
6
+ class SeleniumServer
7
+ # Stops the Selenium server
8
+ def stop
9
+ Net::HTTP.get('localhost', '/selenium-server/driver/?cmd=shutDownSeleniumServer', @port_number)
10
+ end
11
+
12
+ private
13
+ def SeleniumServer::jar_file
14
+ File.join(File.dirname(__FILE__), '..', 'openqa', 'selenium-server.jar.txt')
15
+ end
16
+ end
17
+ end
@@ -1,8 +1,22 @@
1
1
  module EasyAutomation
2
2
  class Server
3
- def self.rc
4
- @selenium ||= Selenium::Server.new(Runner.configuration.selenium_port,
5
- Runner.configuration.selenium_timeout)
3
+ class << self
4
+ def rc force_reload = false
5
+ if force_reload
6
+ @selenium = build_server
7
+ else
8
+ @selenium ||= build_server
9
+ end
10
+ end
11
+
12
+ def build_server
13
+ if Runner.configuration.selenium_host.nil?
14
+ Selenium::Server.new(Runner.configuration.selenium_port,
15
+ Runner.configuration.selenium_timeout)
16
+ else
17
+ EasyAutomation::RemoteServer.new
18
+ end
19
+ end
6
20
  end
7
21
  end
8
22
  end
@@ -25,7 +25,8 @@ module EasyAutomation
25
25
  # or use a global one.
26
26
  #
27
27
  def setup
28
- @webpage = Server.rc.open(Runner.configuration.browser,
28
+ Runner.configuration.execute :before, :each_test
29
+ @webpage = Server.rc.open(Runner.configuration.current_browser,
29
30
  Runner.configuration.url)
30
31
  @data = LoadData::load_test_data(self.class.to_s, @method_name, @path)
31
32
  end
@@ -35,6 +36,7 @@ module EasyAutomation
35
36
  #
36
37
  def teardown
37
38
  @webpage.close
39
+ Runner.configuration.execute :after, :each_test
38
40
  end
39
41
  end
40
42
  end
@@ -1,3 +1,3 @@
1
1
  module EasyAutomation
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,5 @@
1
+ All the files in this foler are from the "Selenium" project on OpenQA (http://www.openqa.org/selenium-rc/), under the
2
+ Apache License (http://www.openqa.org/selenium-rc/license.action)
3
+
4
+ The selenium-server.jar was renamed to have a txt extension because somehow ruby gem does not like jar extension (Installation
5
+ will fail on buffer error.
@@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
4
4
  describe EasyAutomation::Config do
5
5
  subject {Config}
6
6
 
7
- context "before hooks" do
7
+ context "#hooks" do
8
8
  context "when specifying any hook" do
9
9
  before :each do
10
10
  @config = EasyAutomation::Config.new
@@ -21,4 +21,23 @@ describe EasyAutomation::Config do
21
21
  end
22
22
  end
23
23
  end
24
+
25
+ context "#browsers" do
26
+ context "single browser" do
27
+ it "should allow single browser assignment, backward compatibility" do
28
+ config = EasyAutomation::Config.new
29
+ config.browser = "* chrome"
30
+ config.browsers.size.should == 1
31
+ config.current_browser.should == config.browsers.first
32
+ end
33
+ it "should allow to specify multiples browsers" do
34
+ config = EasyAutomation::Config.new
35
+ config.add_browser "* chrome"
36
+ config.browsers << "* firefox"
37
+ config.add_browser "* safari"
38
+ config.browsers.size.should == 3
39
+ config.current_browser.should == config.browsers.first
40
+ end
41
+ end
42
+ end
24
43
  end
@@ -9,7 +9,7 @@ describe EasyAutomation::Runner do
9
9
  it "should default params" do
10
10
  EasyAutomation::Runner.configuration.selenium_port.should be(4444)
11
11
  EasyAutomation::Runner.configuration.selenium_timeout.should be(1000)
12
- EasyAutomation::Runner.configuration.browser.should == "Firefox"
12
+ EasyAutomation::Runner.configuration.browsers.should == ["* firefox"]
13
13
  EasyAutomation::Runner.configuration.url.should == "http://www.google.com"
14
14
  end
15
15
 
@@ -22,7 +22,7 @@ describe EasyAutomation::Runner do
22
22
  end
23
23
  EasyAutomation::Runner.configuration.selenium_port.should be(44444)
24
24
  EasyAutomation::Runner.configuration.selenium_timeout.should be(40000)
25
- EasyAutomation::Runner.configuration.browser.should == "Chrome"
25
+ EasyAutomation::Runner.configuration.browsers.should == ["Chrome"]
26
26
  EasyAutomation::Runner.configuration.url.should == "http://www.yahoo.com"
27
27
  end
28
28
  end
@@ -32,33 +32,103 @@ describe EasyAutomation::Runner do
32
32
  before :each do
33
33
  @rc = mock(EasyAutomation::Server)
34
34
  EasyAutomation::Server.stub(:rc).and_return(@rc)
35
- Test::Unit::UI::Console::TestRunner.stub(:run).and_return(true)
36
- @rc.should_receive(:start)
37
- @rc.should_receive(:stop)
35
+ Test::Unit::UI::Console::TestRunner.stub(:run).and_return(true)
36
+ @rc.should_receive(:start).at_least(1).times()
37
+ @rc.should_receive(:stop).at_least(1).times()
38
+ EasyAutomation::Runner.configuration.selenium_host = ''
38
39
  end
39
40
  it "should accept EasyAutomation::Suite classes" do
40
41
  suite = EasyAutomation::Suite.new
41
42
  lambda { EasyAutomation::Runner.run suite }.should_not raise_error(EasyAutomation::RunnerSuiteException)
42
43
  end
43
- context "before and after all hooks" do
44
- it "should call before all hook when running suites" do
45
- TestBlockClass.should_receive(:return_the_true)
46
- EasyAutomation::Runner.configure do |config|
47
- config.before :all do
48
- TestBlockClass.return_the_true
49
- end
44
+ it "should call before all hook when running suites" do
45
+ TestBlockClass.should_receive(:before_each_suite)
46
+ EasyAutomation::Runner.configure do |config|
47
+ config.before :all do
48
+ TestBlockClass.before_each_suite
49
+ end
50
+ end
51
+ EasyAutomation::Runner.run EasyAutomation::Suite.new('test')
52
+ end
53
+ it "should call after all hook when running suites" do
54
+ TestBlockClass.should_receive(:after_each_suite).at_least(1).times()
55
+ EasyAutomation::Runner.configure do |config|
56
+ config.after :all do
57
+ TestBlockClass.after_each_suite
58
+ end
59
+ end
60
+ EasyAutomation::Runner.run EasyAutomation::Suite.new('test')
61
+ end
62
+ end
63
+
64
+ context "before and after each test hooks" do
65
+ before :each do
66
+ EasyAutomation::Runner.configure do |config|
67
+ config.before :each_test do
68
+ TestBlockClass.before_each_test
69
+ end
70
+ config.after :each_test do
71
+ TestBlockClass.after_each_test
50
72
  end
51
- EasyAutomation::Runner.run EasyAutomation::Suite.new('test')
52
73
  end
53
- it "should call after all hook when running suites" do
54
- TestBlockClass.should_receive(:return_the_true).at_least(2).times()
74
+ @suite = EasyAutomation::Suite.new('test')
75
+ @suite.add(HomeTest)
76
+ rc = mock(EasyAutomation::Server)
77
+ webpage = mock(Selenium::Server)
78
+ EasyAutomation::Server.stub(:rc).and_return(rc)
79
+ rc.should_receive(:start)
80
+ rc.should_receive(:stop)
81
+ rc.should_receive(:open).and_return(webpage)
82
+ webpage.should_receive(:close).any_number_of_times
83
+ end
84
+ it "should call :before_each_test before any test" do
85
+ TestBlockClass.should_receive(:before_each_test)
86
+ EasyAutomation::Runner.run @suite
87
+ end
88
+ it "should call :after_each_test after any test" do
89
+ TestBlockClass.should_receive(:after_each_test)
90
+ EasyAutomation::Runner.run @suite
91
+ end
92
+ end
93
+
94
+ context "Remote Selenium server" do
95
+ context "when specifying selenium_host" do
96
+ it "should not start selenium server locally" do
97
+ rc = mock(EasyAutomation::RemoteServer)
98
+ rc.should_receive(:start)
99
+ rc.should_receive(:stop)
55
100
  EasyAutomation::Runner.configure do |config|
56
- config.after :all do
57
- TestBlockClass.return_the_true
58
- end
101
+ config.selenium_host = "remote_host"
59
102
  end
103
+ EasyAutomation::RemoteServer.should_receive(:new).and_return(rc)
104
+ EasyAutomation::Server.rc true
105
+ Selenium::Server.should_not_receive(:new)
60
106
  EasyAutomation::Runner.run EasyAutomation::Suite.new('test')
61
107
  end
62
108
  end
63
109
  end
110
+
111
+ context "multiple browsers" do
112
+ before :each do
113
+ rc = mock(EasyAutomation::RemoteServer)
114
+ webpage = mock(Selenium::Server)
115
+ rc.should_receive(:start)
116
+ rc.should_receive(:stop)
117
+ rc.should_receive(:open).any_number_of_times().and_return(webpage)
118
+ webpage.should_receive(:close).any_number_of_times()
119
+ EasyAutomation::RemoteServer.should_receive(:new).and_return(rc)
120
+ end
121
+ it "should run all tests against every single browser specified on config" do
122
+ EasyAutomation::Runner.configure do |config|
123
+ config.selenium_host = "localhost"
124
+ config.add_browser "*firefox"
125
+ config.add_browser "*safari"
126
+ end
127
+ EasyAutomation::Server.rc true
128
+ test_suite = EasyAutomation::Suite.new('test')
129
+ Test::Unit::UI::Console::TestRunner.should_receive(:run).at_least(2).times()
130
+ test_suite.add(HomeTest)
131
+ EasyAutomation::Runner.run test_suite
132
+ end
133
+ end
64
134
  end
@@ -16,14 +16,6 @@ describe EasyAutomation::Suite do
16
16
  lambda{my_suite.add(WrongTest)}.should raise_error(EasyAutomation::SuiteException)
17
17
  end
18
18
  it "should accept suites if they extend from EasyAutomation::Test" do
19
- class TestClass < EasyAutomation::Test
20
- def suite
21
- true
22
- end
23
- def method_name
24
- true
25
- end
26
- end
27
19
  my_suite = EasyAutomation::Suite.new
28
20
  my_suite.add(TestClass)
29
21
  my_suite.suite.size.should be(1)
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
3
 
4
+ puts File.dirname(__FILE__)
4
5
  require File.join(File.dirname(__FILE__), '..', 'lib/easy-automation')
5
6
 
6
7
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -17,4 +18,16 @@ class TestBlockClass
17
18
  def self.return_the_true
18
19
  true
19
20
  end
21
+ def self.before_each_suite
22
+ true
23
+ end
24
+ def self.before_each_test
25
+ true
26
+ end
27
+ def self.after_each_suite
28
+ true
29
+ end
30
+ def self.after_each_test
31
+ true
32
+ end
20
33
  end
@@ -9,4 +9,8 @@ class HomeTest < EasyAutomation::Test
9
9
 
10
10
  def two
11
11
  end
12
+
13
+ def test_hooks
14
+ true
15
+ end
12
16
  end
@@ -0,0 +1,9 @@
1
+ class TestClass < EasyAutomation::Test
2
+ def suite
3
+ true
4
+ end
5
+
6
+ def method_name
7
+ true
8
+ end
9
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-automation
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Edwin Cruz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-14 00:00:00 -07:00
18
+ date: 2011-03-24 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -69,11 +69,16 @@ files:
69
69
  - lib/easy_automation/data_elements.rb
70
70
  - lib/easy_automation/load_data.rb
71
71
  - lib/easy_automation/page.rb
72
+ - lib/easy_automation/remote_server.rb
72
73
  - lib/easy_automation/runner.rb
74
+ - lib/easy_automation/selenium.rb
73
75
  - lib/easy_automation/server.rb
74
76
  - lib/easy_automation/suite.rb
75
77
  - lib/easy_automation/test.rb
76
78
  - lib/easy_automation/version.rb
79
+ - lib/openqa/README
80
+ - lib/openqa/selenium-server.jar.txt
81
+ - lib/openqa/sslSupport/cybervillainsCA.cer
77
82
  - spec/lib/easy-automation/config_spec.rb
78
83
  - spec/lib/easy-automation/page_spec.rb
79
84
  - spec/lib/easy-automation/runner_spec.rb
@@ -85,6 +90,7 @@ files:
85
90
  - spec/support/elements/homepage.yml
86
91
  - spec/support/home_page.rb
87
92
  - spec/support/home_test.rb
93
+ - spec/support/test_class.rb
88
94
  has_rdoc: true
89
95
  homepage: http://rubygems.org/gems/easy-automation
90
96
  licenses: []
@@ -131,3 +137,4 @@ test_files:
131
137
  - spec/support/elements/homepage.yml
132
138
  - spec/support/home_page.rb
133
139
  - spec/support/home_test.rb
140
+ - spec/support/test_class.rb