polonium 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +1 -0
- data/Rakefile +1 -1
- data/lib/polonium/adapters/rspec.rb +21 -0
- data/lib/polonium/{extensions/testrunnermediator.rb → adapters/test_unit.rb} +1 -1
- data/lib/polonium/configuration.rb +35 -33
- data/lib/polonium/dsl/selenium_dsl.rb +6 -3
- data/lib/polonium/dsl/test_unit_dsl.rb +4 -1
- data/lib/polonium/element.rb +13 -12
- data/lib/polonium/page.rb +14 -4
- data/lib/polonium/test_case.rb +3 -37
- data/lib/polonium/values_match.rb +9 -0
- data/lib/polonium.rb +6 -1
- data/spec/main_spec_suite.rb +11 -0
- data/spec/polonium/{selenium_configuration_spec.rb → configuration_spec.rb} +0 -0
- data/spec/polonium/{selenium_driver_spec.rb → driver_spec.rb} +0 -0
- data/spec/polonium/element_spec.rb +601 -0
- data/spec/polonium/{selenium_page_spec.rb → page_spec.rb} +95 -60
- data/spec/polonium/{selenium_server_runner_spec.rb → server_runner_spec.rb} +0 -0
- data/spec/polonium/test_case_class_method_spec.rb +14 -0
- data/spec/polonium/{selenium_test_case_spec.rb → test_case_spec.rb} +16 -7
- data/spec/polonium/{selenium_test_case_spec_helper.rb → test_case_spec_helper.rb} +1 -1
- data/spec/polonium/values_match_spec.rb +30 -0
- data/spec/rspec/options_spec.rb +30 -0
- data/spec/rspec/rspec_spec_helper.rb +1 -0
- data/spec/rspec_spec_suite.rb +11 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_suite.rb +17 -4
- data/spec/test_unit/test_unit_spec_helper.rb +1 -0
- data/spec/{polonium/extensions → test_unit}/testrunnermediator_spec.rb +1 -1
- data/spec/test_unit_spec_suite.rb +11 -0
- metadata +21 -12
- data/spec/polonium/selenium_element_spec.rb +0 -551
- data/spec/polonium/selenium_test_case_class_method_spec.rb +0 -41
data/CHANGES
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Spec::Runner::Options
|
2
|
+
attr_accessor :selenium_configuration, :selenium_app_runner
|
3
|
+
|
4
|
+
def run_examples_with_selenium_runner(*args)
|
5
|
+
success = run_examples_without_selenium_runner(*args)
|
6
|
+
selenium_app_runner.stop
|
7
|
+
selenium_configuration.stop_driver_if_necessary(success)
|
8
|
+
success
|
9
|
+
end
|
10
|
+
alias_method_chain :run_examples, :selenium_runner
|
11
|
+
end
|
12
|
+
|
13
|
+
rspec_options.selenium_configuration = Polonium::Configuration.instance
|
14
|
+
rspec_options.selenium_app_runner = nil
|
15
|
+
|
16
|
+
Spec::Example::ExampleMethods.before(:all) do
|
17
|
+
unless rspec_options.selenium_app_runner
|
18
|
+
rspec_options.selenium_app_runner = rspec_options.selenium_configuration.create_server_runner
|
19
|
+
rspec_options.selenium_app_runner.start
|
20
|
+
end
|
21
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class Test::Unit::UI::TestRunnerMediator
|
2
|
-
alias_method :run_suite_without_seleniumrc, :run_suite
|
3
2
|
def run_suite_with_seleniumrc
|
4
3
|
start_app_server
|
5
4
|
result = run_suite_without_seleniumrc
|
6
5
|
stop_app_server(result)
|
7
6
|
result
|
8
7
|
end
|
8
|
+
alias_method :run_suite_without_seleniumrc, :run_suite
|
9
9
|
alias_method :run_suite, :run_suite_with_seleniumrc
|
10
10
|
|
11
11
|
protected
|
@@ -49,8 +49,8 @@ module Polonium
|
|
49
49
|
|
50
50
|
private
|
51
51
|
def establish_environment
|
52
|
-
|
53
|
-
|
52
|
+
instance.rails_env = env['RAILS_ENV'] if env.include?('RAILS_ENV')
|
53
|
+
instance.rails_root = Object.const_get(:RAILS_ROOT) if Object.const_defined?(:RAILS_ROOT)
|
54
54
|
[
|
55
55
|
'selenium_server_host',
|
56
56
|
'selenium_server_port',
|
@@ -61,7 +61,7 @@ module Polonium
|
|
61
61
|
'external_app_server_port'
|
62
62
|
].each do |env_key|
|
63
63
|
if env.include?(env_key)
|
64
|
-
|
64
|
+
instance.send("#{env_key}=", env[env_key])
|
65
65
|
end
|
66
66
|
end
|
67
67
|
[
|
@@ -69,35 +69,37 @@ module Polonium
|
|
69
69
|
'verify_remote_app_server_is_running'
|
70
70
|
].each do |env_key|
|
71
71
|
if env.include?(env_key)
|
72
|
-
|
72
|
+
instance.send("#{env_key}=", env[env_key].to_s != false.to_s)
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
instance.browser = env['browser'] if env.include?('browser')
|
76
76
|
end
|
77
77
|
|
78
78
|
def env
|
79
|
-
|
79
|
+
instance.env
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
83
|
+
attr_accessor(
|
84
|
+
:configuration,
|
85
|
+
:env,
|
86
|
+
:rails_env,
|
87
|
+
:rails_root,
|
88
|
+
:browser,
|
89
|
+
:driver,
|
90
|
+
:browser_mode,
|
91
|
+
:selenium_server_host,
|
92
|
+
:selenium_server_port,
|
93
|
+
:app_server_engine,
|
94
|
+
:internal_app_server_host,
|
95
|
+
:internal_app_server_port,
|
96
|
+
:external_app_server_host,
|
97
|
+
:external_app_server_port,
|
98
|
+
:server_engine,
|
99
|
+
:keep_browser_open_on_failure,
|
100
|
+
:verify_remote_app_server_is_running,
|
101
|
+
:app_server_initialization
|
102
|
+
)
|
101
103
|
|
102
104
|
def initialize
|
103
105
|
self.verify_remote_app_server_is_running = true
|
@@ -164,7 +166,7 @@ module Polonium
|
|
164
166
|
@driver ||= create_and_initialize_driver
|
165
167
|
end
|
166
168
|
|
167
|
-
def stop_driver_if_necessary(suite_passed)
|
169
|
+
def stop_driver_if_necessary(suite_passed) #:nodoc:
|
168
170
|
failure_has_occurred unless suite_passed
|
169
171
|
if @driver && stop_driver?(suite_passed)
|
170
172
|
@driver.stop
|
@@ -172,19 +174,19 @@ module Polonium
|
|
172
174
|
end
|
173
175
|
end
|
174
176
|
|
175
|
-
def stop_driver?(passed)
|
177
|
+
def stop_driver?(passed) #:nodoc:
|
176
178
|
return true if passed
|
177
179
|
return !keep_browser_open_on_failure
|
178
180
|
end
|
179
181
|
|
180
|
-
def create_and_initialize_driver
|
182
|
+
def create_and_initialize_driver #:nodoc:
|
181
183
|
driver = create_driver
|
182
184
|
driver.start
|
183
185
|
notify_after_driver_started(driver)
|
184
186
|
driver
|
185
187
|
end
|
186
188
|
|
187
|
-
def create_driver
|
189
|
+
def create_driver #:nodoc:
|
188
190
|
return ::Polonium::Driver.new(
|
189
191
|
selenium_server_host,
|
190
192
|
selenium_server_port,
|
@@ -194,7 +196,7 @@ module Polonium
|
|
194
196
|
)
|
195
197
|
end
|
196
198
|
|
197
|
-
def create_server_runner
|
199
|
+
def create_server_runner #:nodoc:
|
198
200
|
case @app_server_engine.to_sym
|
199
201
|
when :mongrel
|
200
202
|
create_mongrel_runner
|
@@ -205,7 +207,7 @@ module Polonium
|
|
205
207
|
end
|
206
208
|
end
|
207
209
|
|
208
|
-
def create_webrick_runner
|
210
|
+
def create_webrick_runner #:nodoc:
|
209
211
|
require 'webrick_server'
|
210
212
|
runner = WebrickSeleniumServerRunner.new
|
211
213
|
runner.configuration = self
|
@@ -216,7 +218,7 @@ module Polonium
|
|
216
218
|
runner
|
217
219
|
end
|
218
220
|
|
219
|
-
def create_webrick_server
|
221
|
+
def create_webrick_server #:nodoc:
|
220
222
|
WEBrick::HTTPServer.new({
|
221
223
|
:Port => @internal_app_server_port,
|
222
224
|
:BindAddress => @internal_app_server_host,
|
@@ -231,14 +233,14 @@ module Polonium
|
|
231
233
|
Logger.new(StringIO.new)
|
232
234
|
end
|
233
235
|
|
234
|
-
def create_mongrel_runner
|
236
|
+
def create_mongrel_runner #:nodoc:
|
235
237
|
runner = MongrelSeleniumServerRunner.new
|
236
238
|
runner.configuration = self
|
237
239
|
runner.thread_class = Thread
|
238
240
|
runner
|
239
241
|
end
|
240
242
|
|
241
|
-
def create_mongrel_configurator
|
243
|
+
def create_mongrel_configurator #:nodoc:
|
242
244
|
dir = File.dirname(__FILE__)
|
243
245
|
require 'mongrel/rails'
|
244
246
|
settings = {
|
@@ -21,11 +21,14 @@ module Polonium
|
|
21
21
|
end
|
22
22
|
|
23
23
|
protected
|
24
|
-
|
25
|
-
|
24
|
+
def method_missing(method_name, *args, &block)
|
25
|
+
selenium_driver.__send__(method_name, *args, &block)
|
26
26
|
end
|
27
|
+
delegate :open,
|
28
|
+
:type,
|
29
|
+
:to => :selenium_driver
|
27
30
|
|
28
|
-
def
|
31
|
+
def stop_driver?
|
29
32
|
return false unless configuration.test_browser_mode?
|
30
33
|
configuration.stop_driver?(passed?)
|
31
34
|
end
|
@@ -30,7 +30,6 @@ module Polonium
|
|
30
30
|
deprecate :assert_location_ends_in, :assert_location_ends_with
|
31
31
|
|
32
32
|
element_assertion :value
|
33
|
-
element_assertion :attribute # yes, it's a little weird... in this case element is really an attribute
|
34
33
|
element_assertion :selected
|
35
34
|
element_assertion :checked
|
36
35
|
element_assertion :not_checked
|
@@ -42,6 +41,10 @@ module Polonium
|
|
42
41
|
element_assertion :visible
|
43
42
|
element_assertion :not_visible
|
44
43
|
|
44
|
+
def assert_attribute(element_locator, attribute_name, expected_value)
|
45
|
+
element(element_locator).assert_attribute(attribute_name, expected_value)
|
46
|
+
end
|
47
|
+
|
45
48
|
# Assert and wait for locator element to contain text.
|
46
49
|
def assert_element_contains(locator, text, options = {})
|
47
50
|
element(locator).assert_contains(text, options)
|
data/lib/polonium/element.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Polonium
|
2
2
|
class Element
|
3
|
-
include WaitFor
|
3
|
+
include WaitFor, ValuesMatch
|
4
4
|
attr_reader :driver, :locator
|
5
5
|
|
6
6
|
def initialize(driver, locator)
|
@@ -25,12 +25,13 @@ module Polonium
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def assert_attribute(expected_value)
|
28
|
+
def assert_attribute(expected_name, expected_value)
|
29
29
|
assert_element_present
|
30
|
+
attr_locator = "#{locator}@#{expected_name}"
|
30
31
|
wait_for do |configuration|
|
31
|
-
actual = driver.get_attribute(
|
32
|
-
configuration.message = "Expected attribute '#{
|
33
|
-
|
32
|
+
actual = driver.get_attribute(attr_locator) #todo: actual value
|
33
|
+
configuration.message = "Expected attribute '#{attr_locator}' to be '#{expected_value}' but was '#{actual}'"
|
34
|
+
values_match? actual, expected_value
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
@@ -39,7 +40,7 @@ module Polonium
|
|
39
40
|
wait_for do |configuration|
|
40
41
|
actual = driver.get_selected_label(locator)
|
41
42
|
configuration.message = "Expected '#{locator}' to be selected with '#{expected_value}' but was '#{actual}"
|
42
|
-
|
43
|
+
values_match? actual, expected_value
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -72,7 +73,7 @@ module Polonium
|
|
72
73
|
|
73
74
|
def assert_not_checked
|
74
75
|
assert_element_present
|
75
|
-
wait_for(:message => "Expected '#{locator}' to be checked") do
|
76
|
+
wait_for(:message => "Expected '#{locator}' to not be checked") do
|
76
77
|
!driver.is_checked(locator)
|
77
78
|
end
|
78
79
|
end
|
@@ -82,7 +83,7 @@ module Polonium
|
|
82
83
|
wait_for(options) do |configuration|
|
83
84
|
actual = driver.get_text(locator)
|
84
85
|
configuration.message = "Expected text '#{expected_text}' to be full contents of #{locator} but was '#{actual}')"
|
85
|
-
|
86
|
+
values_match? actual, expected_text
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
@@ -100,7 +101,7 @@ module Polonium
|
|
100
101
|
def assert_does_not_contain(expected_text, options={})
|
101
102
|
assert_element_present
|
102
103
|
wait_for(options) do
|
103
|
-
!
|
104
|
+
!contains?(expected_text)
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
@@ -157,7 +158,7 @@ module Polonium
|
|
157
158
|
end
|
158
159
|
|
159
160
|
def contains?(text)
|
160
|
-
inner_html.
|
161
|
+
inner_html.match(text) ? true : false
|
161
162
|
end
|
162
163
|
|
163
164
|
def ==(other)
|
@@ -176,7 +177,7 @@ module Polonium
|
|
176
177
|
super
|
177
178
|
end
|
178
179
|
end
|
179
|
-
|
180
|
+
|
180
181
|
def find_text_order_error_fragments(html, text_fragments)
|
181
182
|
fragments_not_found = []
|
182
183
|
fragments_out_of_order = []
|
@@ -204,4 +205,4 @@ module Polonium
|
|
204
205
|
}
|
205
206
|
end
|
206
207
|
end
|
207
|
-
end
|
208
|
+
end
|
data/lib/polonium/page.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Polonium
|
2
2
|
class Page
|
3
|
-
include WaitFor
|
3
|
+
include WaitFor, ValuesMatch
|
4
4
|
attr_reader :driver
|
5
5
|
PAGE_LOADED_COMMAND = "this.browserbot.getDocument().body ? true : false"
|
6
6
|
|
@@ -17,7 +17,7 @@ module Polonium
|
|
17
17
|
wait_for(params) do |configuration|
|
18
18
|
actual_title = title
|
19
19
|
configuration.message = "Expected title '#{expected_title}' but was '#{actual_title}'"
|
20
|
-
expected_title
|
20
|
+
values_match?(actual_title, expected_title)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
def title
|
@@ -33,7 +33,12 @@ module Polonium
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
def is_text_present?(expected_text)
|
36
|
-
|
36
|
+
if expected_text.is_a?(Regexp)
|
37
|
+
text_finder = "regexp:#{expected_text.source}"
|
38
|
+
else
|
39
|
+
text_finder = expected_text
|
40
|
+
end
|
41
|
+
page_loaded? && driver.is_text_present(text_finder)
|
37
42
|
end
|
38
43
|
|
39
44
|
def assert_text_not_present(unexpected_text, options = {})
|
@@ -45,7 +50,12 @@ module Polonium
|
|
45
50
|
end
|
46
51
|
end
|
47
52
|
def is_text_not_present?(unexpected_text)
|
48
|
-
|
53
|
+
if unexpected_text.is_a?(Regexp)
|
54
|
+
text_finder = "regexp:#{unexpected_text.source}"
|
55
|
+
else
|
56
|
+
text_finder = unexpected_text
|
57
|
+
end
|
58
|
+
page_loaded? && !driver.is_text_present(text_finder)
|
49
59
|
end
|
50
60
|
|
51
61
|
def page_loaded?
|
data/lib/polonium/test_case.rb
CHANGED
@@ -2,46 +2,12 @@ module Polonium
|
|
2
2
|
# The Test Case class that runs your Selenium tests.
|
3
3
|
# You are able to use all methods provided by Selenium::SeleneseInterpreter with some additions.
|
4
4
|
class TestCase < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def subclasses
|
7
|
-
@subclasses ||= []
|
8
|
-
end
|
9
|
-
|
10
|
-
def inherited(subclass)
|
11
|
-
# keep a list of all subclasses on the fly, so we can run them all later from the Runner
|
12
|
-
subclasses << subclass unless subclasses.include?(subclass)
|
13
|
-
super
|
14
|
-
end
|
15
|
-
|
16
|
-
def all_subclasses_as_suite(configuration)
|
17
|
-
suite = Test::Unit::TestSuite.new
|
18
|
-
all_descendant_classes.each do |test_case_class|
|
19
|
-
test_case_class.suite.tests.each do |test_case|
|
20
|
-
test_case.configuration = configuration
|
21
|
-
suite << test_case
|
22
|
-
end
|
23
|
-
end
|
24
|
-
suite
|
25
|
-
end
|
26
|
-
|
27
|
-
def all_descendant_classes
|
28
|
-
extract_subclasses(self)
|
29
|
-
end
|
30
|
-
|
31
|
-
def extract_subclasses(parent_class)
|
32
|
-
classes = []
|
33
|
-
parent_class.subclasses.each do |subclass|
|
34
|
-
classes << subclass
|
35
|
-
classes.push(*extract_subclasses(subclass))
|
36
|
-
end
|
37
|
-
classes
|
38
|
-
end
|
39
|
-
|
5
|
+
class << self
|
40
6
|
unless Object.const_defined?(:RAILS_ROOT)
|
41
7
|
attr_accessor :use_transactional_fixtures, :use_instantiated_fixtures
|
42
8
|
end
|
43
9
|
end
|
44
|
-
|
10
|
+
undef_method 'default_test' if instance_methods.include?('default_test')
|
45
11
|
|
46
12
|
self.use_transactional_fixtures = false
|
47
13
|
self.use_instantiated_fixtures = true
|
@@ -71,7 +37,7 @@ module Polonium
|
|
71
37
|
end
|
72
38
|
|
73
39
|
def teardown
|
74
|
-
selenium_driver.stop if
|
40
|
+
selenium_driver.stop if stop_driver?
|
75
41
|
super
|
76
42
|
if @beginning
|
77
43
|
duration = (time_class.now - @beginning).to_f
|
data/lib/polonium.rb
CHANGED
@@ -11,7 +11,6 @@ require 'test/unit/ui/testrunnermediator'
|
|
11
11
|
|
12
12
|
require "selenium"
|
13
13
|
require "polonium/extensions/module"
|
14
|
-
require "polonium/extensions/testrunnermediator"
|
15
14
|
require "polonium/wait_for"
|
16
15
|
require "polonium/driver"
|
17
16
|
require "polonium/server_runner"
|
@@ -20,9 +19,15 @@ require "polonium/webrick_selenium_server_runner"
|
|
20
19
|
require "polonium/dsl/selenium_dsl"
|
21
20
|
require "polonium/dsl/test_unit_dsl"
|
22
21
|
require "polonium/configuration"
|
22
|
+
require "polonium/values_match"
|
23
23
|
require "polonium/page"
|
24
24
|
require "polonium/element"
|
25
25
|
require "polonium/test_case"
|
26
26
|
require "polonium/tasks/selenium_test_task"
|
27
27
|
|
28
28
|
require 'webrick_server' if self.class.const_defined? :RAILS_ROOT
|
29
|
+
|
30
|
+
require "polonium/adapters/test_unit"
|
31
|
+
if Object.const_defined?(:Spec)
|
32
|
+
require "polonium/adapters/rspec"
|
33
|
+
end
|
File without changes
|
File without changes
|