seleniumrc 0.0.1 → 0.0.2
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/CHANGES +4 -0
- data/README +38 -0
- data/Rakefile +1 -1
- data/lib/seleniumrc.rb +2 -4
- data/lib/seleniumrc/dsl/selenium_dsl.rb +8 -143
- data/lib/seleniumrc/extensions/testrunnermediator.rb +2 -2
- data/lib/seleniumrc/mongrel_selenium_server_runner.rb +9 -7
- data/lib/seleniumrc/selenium_configuration.rb +233 -40
- data/lib/seleniumrc/selenium_driver.rb +193 -0
- data/lib/seleniumrc/selenium_element.rb +31 -37
- data/lib/seleniumrc/selenium_page.rb +16 -16
- data/lib/seleniumrc/selenium_server_runner.rb +1 -1
- data/lib/seleniumrc/selenium_test_case.rb +2 -4
- data/lib/seleniumrc/wait_for.rb +3 -10
- data/lib/seleniumrc/webrick_selenium_server_runner.rb +11 -11
- data/spec/seleniumrc/mongrel_selenium_server_runner_spec.rb +31 -38
- data/spec/seleniumrc/selenese_interpreter_spec.rb +12 -12
- data/spec/seleniumrc/selenium_configuration_spec.rb +350 -12
- data/spec/seleniumrc/selenium_driver_spec.rb +104 -0
- data/spec/seleniumrc/selenium_element_spec.rb +78 -76
- data/spec/seleniumrc/selenium_page_spec.rb +39 -29
- data/spec/seleniumrc/selenium_test_case_spec.rb +631 -673
- data/spec/seleniumrc/selenium_test_case_spec_helper.rb +0 -7
- data/spec/seleniumrc/webrick_selenium_server_runner_spec.rb +14 -13
- data/spec/spec_helper.rb +7 -1
- metadata +4 -7
- data/lib/seleniumrc/app_server_checker.rb +0 -43
- data/lib/seleniumrc/extensions/selenium_driver.rb +0 -33
- data/lib/seleniumrc/selenium_context.rb +0 -226
- data/spec/seleniumrc/app_server_checker_spec.rb +0 -56
- data/spec/seleniumrc/selenium_context_spec.rb +0 -362
@@ -0,0 +1,193 @@
|
|
1
|
+
module Seleniumrc
|
2
|
+
class SeleniumDriver < ::Selenium::SeleniumDriver
|
3
|
+
include WaitFor
|
4
|
+
attr_reader :server_host, :server_port
|
5
|
+
|
6
|
+
def browser_start_command
|
7
|
+
@browserStartCommand
|
8
|
+
end
|
9
|
+
|
10
|
+
def browser_url
|
11
|
+
@browserURL
|
12
|
+
end
|
13
|
+
|
14
|
+
def timeout_in_milliseconds
|
15
|
+
@timeout
|
16
|
+
end
|
17
|
+
|
18
|
+
def insert_javascript_file(uri)
|
19
|
+
js = <<-USEREXTENSIONS
|
20
|
+
var headTag = document.getElementsByTagName("head").item(0);
|
21
|
+
var scriptTag = document.createElement("script");
|
22
|
+
scriptTag.src = "#{uri}";
|
23
|
+
headTag.appendChild( scriptTag );
|
24
|
+
USEREXTENSIONS
|
25
|
+
get_eval(js)
|
26
|
+
end
|
27
|
+
|
28
|
+
def insert_user_extensions
|
29
|
+
insert_javascript_file("/selenium/user-extensions.js")
|
30
|
+
end
|
31
|
+
|
32
|
+
def element(locator)
|
33
|
+
SeleniumElement.new(self, locator)
|
34
|
+
end
|
35
|
+
|
36
|
+
def page
|
37
|
+
SeleniumPage.new(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
#--------- Commands
|
41
|
+
alias_method :confirm, :get_confirmation
|
42
|
+
|
43
|
+
# Type text into a page element
|
44
|
+
def type(locator, value)
|
45
|
+
wait_for_is_element_present(locator)
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
# Reload the current page that the browser is on.
|
50
|
+
def reload
|
51
|
+
get_eval("selenium.browserbot.getCurrentWindow().location.reload()")
|
52
|
+
end
|
53
|
+
|
54
|
+
def click(locator)
|
55
|
+
wait_for_is_element_present(locator)
|
56
|
+
super
|
57
|
+
end
|
58
|
+
alias_method :wait_for_and_click, :click
|
59
|
+
|
60
|
+
def select(select_locator, option_locator)
|
61
|
+
wait_for_is_element_present(select_locator)
|
62
|
+
super
|
63
|
+
end
|
64
|
+
|
65
|
+
# Click a link and wait for the page to load.
|
66
|
+
def click_and_wait(locator, wait_for = default_timeout)
|
67
|
+
click locator
|
68
|
+
wait_for_page_to_load(wait_for)
|
69
|
+
end
|
70
|
+
alias_method :click_and_wait_for_page_to_load, :click_and_wait
|
71
|
+
|
72
|
+
# Click the back button and wait for the page to load.
|
73
|
+
def go_back_and_wait
|
74
|
+
go_back
|
75
|
+
wait_for_page_to_load
|
76
|
+
end
|
77
|
+
|
78
|
+
# Open the home page of the Application and wait for the page to load.
|
79
|
+
def open(url)
|
80
|
+
super
|
81
|
+
wait_for_page_to_load
|
82
|
+
end
|
83
|
+
alias_method :open_and_wait, :open
|
84
|
+
|
85
|
+
# Get the inner html of the located element.
|
86
|
+
def get_inner_html(locator)
|
87
|
+
get_eval(inner_html_js(locator))
|
88
|
+
end
|
89
|
+
|
90
|
+
# Does the element at locator contain the text?
|
91
|
+
def element_contains_text(locator, text)
|
92
|
+
is_element_present(locator) && get_inner_html(locator).include?(text)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Does the element at locator not contain the text?
|
96
|
+
def element_does_not_contain_text(locator, text)
|
97
|
+
return true unless is_element_present(locator)
|
98
|
+
return !get_inner_html(locator).include?(text)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Does locator element have text fragments in a certain order?
|
102
|
+
def is_text_in_order(locator, *text_fragments)
|
103
|
+
container = Hpricot(get_text(locator))
|
104
|
+
|
105
|
+
everything_found = true
|
106
|
+
wasnt_found_message = "Certain fragments weren't found:\n"
|
107
|
+
|
108
|
+
everything_in_order = true
|
109
|
+
wasnt_in_order_message = "Certain fragments were out of order:\n"
|
110
|
+
|
111
|
+
text_fragments.inject([-1, nil]) do |old_results, new_fragment|
|
112
|
+
old_index = old_results[0]
|
113
|
+
old_fragment = old_results[1]
|
114
|
+
new_index = container.inner_html.index(new_fragment)
|
115
|
+
|
116
|
+
unless new_index
|
117
|
+
everything_found = false
|
118
|
+
wasnt_found_message << "Fragment #{new_fragment} was not found\n"
|
119
|
+
end
|
120
|
+
|
121
|
+
if new_index < old_index
|
122
|
+
everything_in_order = false
|
123
|
+
wasnt_in_order_message << "Fragment #{new_fragment} out of order:\n"
|
124
|
+
wasnt_in_order_message << "\texpected '#{old_fragment}'\n"
|
125
|
+
wasnt_in_order_message << "\tto come before '#{new_fragment}'\n"
|
126
|
+
end
|
127
|
+
|
128
|
+
[new_index, new_fragment]
|
129
|
+
end
|
130
|
+
|
131
|
+
wasnt_found_message << "\n\nhtml follows:\n #{container.inner_html}\n"
|
132
|
+
wasnt_in_order_message << "\n\nhtml follows:\n #{container.inner_html}\n"
|
133
|
+
|
134
|
+
unless everything_found && everything_in_order
|
135
|
+
yield(everything_found, wasnt_found_message, everything_in_order, wasnt_in_order_message)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
#----- Waiting for conditions
|
140
|
+
def wait_for_is_element_present(locator, params={})
|
141
|
+
params = {
|
142
|
+
:message => "Expected element '#{locator}' to be present, but it was not"
|
143
|
+
}.merge(params)
|
144
|
+
wait_for(params) do
|
145
|
+
is_element_present(locator)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def wait_for_is_element_not_present(locator, params={})
|
150
|
+
params = {
|
151
|
+
:message => "Expected element '#{locator}' to be absent, but it was not"
|
152
|
+
}.merge(params)
|
153
|
+
wait_for(:message => params[:message]) do
|
154
|
+
!is_element_present(locator)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def wait_for_page_to_load(timeout=default_timeout)
|
159
|
+
super
|
160
|
+
if get_title.include?("Exception caught")
|
161
|
+
flunk "We got a new page, but it was an application exception page.\n\n" + get_html_source
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def wait_for_element_to_contain(locator, text, message=nil, timeout=default_wait_for_time)
|
166
|
+
wait_for(:message => message, :timeout => timeout) do
|
167
|
+
element_contains_text(locator, text)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
alias_method :wait_for_element_to_contain_text, :wait_for_element_to_contain
|
171
|
+
|
172
|
+
# Open the log window on the browser. This is useful to diagnose issues with Selenium Core.
|
173
|
+
def show_log(log_level = "debug")
|
174
|
+
get_eval "LOG.setLogLevelThreshold('#{log_level}')"
|
175
|
+
end
|
176
|
+
|
177
|
+
# Slow down each Selenese step after this method is called.
|
178
|
+
def slow_mode
|
179
|
+
get_eval "slowMode = true"
|
180
|
+
get_eval 'window.document.getElementsByName("FASTMODE")[0].checked = true'
|
181
|
+
end
|
182
|
+
|
183
|
+
# Speeds up each Selenese step to normal speed after this method is called.
|
184
|
+
def fast_mode
|
185
|
+
get_eval "slowMode = false"
|
186
|
+
get_eval 'window.document.getElementsByName("FASTMODE")[0].checked = false'
|
187
|
+
end
|
188
|
+
|
189
|
+
def inner_html_js(locator)
|
190
|
+
%Q|this.page().findElement("#{locator}").innerHTML|
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -1,59 +1,53 @@
|
|
1
1
|
module Seleniumrc
|
2
2
|
class SeleniumElement
|
3
3
|
include WaitFor
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :driver, :locator
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(driver, locator)
|
7
|
+
@driver = driver
|
8
8
|
@locator = locator
|
9
9
|
end
|
10
10
|
|
11
11
|
def is_present(params={})
|
12
|
-
|
13
|
-
wait_for(params) do
|
14
|
-
is_present?
|
15
|
-
end
|
12
|
+
driver.wait_for_is_element_present(locator, params)
|
16
13
|
end
|
17
14
|
def is_present?
|
18
|
-
|
15
|
+
driver.is_element_present(locator)
|
19
16
|
end
|
20
17
|
|
21
18
|
def is_not_present(params={})
|
22
|
-
|
23
|
-
wait_for(:message => params[:message]) do
|
24
|
-
is_not_present?
|
25
|
-
end
|
19
|
+
driver.wait_for_is_element_not_present(locator, params)
|
26
20
|
end
|
27
21
|
def is_not_present?
|
28
|
-
!
|
22
|
+
!driver.is_element_present(locator)
|
29
23
|
end
|
30
24
|
|
31
25
|
def has_value(expected_value)
|
32
26
|
is_present
|
33
|
-
wait_for do |
|
34
|
-
actual_value =
|
35
|
-
|
27
|
+
wait_for do |configuration|
|
28
|
+
actual_value = driver.get_value(locator)
|
29
|
+
configuration.message = "Expected '#{locator}' to be '#{expected_value}' but was '#{actual_value}'"
|
36
30
|
has_value? expected_value, actual_value
|
37
31
|
end
|
38
32
|
end
|
39
|
-
def has_value?(expected_value, actual_value=
|
33
|
+
def has_value?(expected_value, actual_value=driver.get_value(locator))
|
40
34
|
expected_value == actual_value
|
41
35
|
end
|
42
36
|
|
43
37
|
def has_attribute(expected_value)
|
44
38
|
is_present
|
45
|
-
wait_for do |
|
46
|
-
actual =
|
47
|
-
|
39
|
+
wait_for do |configuration|
|
40
|
+
actual = driver.get_attribute(locator) #todo: actual value
|
41
|
+
configuration.message = "Expected attribute '#{locator}' to be '#{expected_value}' but was '#{actual}'"
|
48
42
|
expected_value == actual
|
49
43
|
end
|
50
44
|
end
|
51
45
|
|
52
46
|
def has_selected(expected_value)
|
53
47
|
is_present
|
54
|
-
wait_for do |
|
55
|
-
actual =
|
56
|
-
|
48
|
+
wait_for do |configuration|
|
49
|
+
actual = driver.get_selected_label(locator)
|
50
|
+
configuration.message = "Expected '#{locator}' to be selected with '#{expected_value}' but was '#{actual}"
|
57
51
|
expected_value == actual
|
58
52
|
end
|
59
53
|
end
|
@@ -64,7 +58,7 @@ module Seleniumrc
|
|
64
58
|
:message => "Expected '#{locator}' to be visible, but it wasn't"
|
65
59
|
}.merge(options)
|
66
60
|
wait_for(options) do
|
67
|
-
|
61
|
+
driver.is_visible(locator)
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
@@ -74,29 +68,29 @@ module Seleniumrc
|
|
74
68
|
:message => "Expected '#{locator}' to be hidden, but it wasn't"
|
75
69
|
}.merge(options)
|
76
70
|
wait_for(options) do
|
77
|
-
!
|
71
|
+
!driver.is_visible(locator)
|
78
72
|
end
|
79
73
|
end
|
80
74
|
|
81
75
|
def is_checked
|
82
76
|
is_present
|
83
77
|
wait_for(:message => "Expected '#{locator}' to be checked") do
|
84
|
-
|
78
|
+
driver.is_checked(locator)
|
85
79
|
end
|
86
80
|
end
|
87
81
|
|
88
82
|
def is_not_checked
|
89
83
|
is_present
|
90
84
|
wait_for(:message => "Expected '#{locator}' to be checked") do
|
91
|
-
!
|
85
|
+
!driver.is_checked(locator)
|
92
86
|
end
|
93
87
|
end
|
94
88
|
|
95
89
|
def has_text(expected_text, options={})
|
96
90
|
is_present
|
97
|
-
wait_for(options) do |
|
98
|
-
actual =
|
99
|
-
|
91
|
+
wait_for(options) do |configuration|
|
92
|
+
actual = driver.get_text(locator)
|
93
|
+
configuration.message = "Expected text '#{expected_text}' to be full contents of #{locator} but was '#{actual}')"
|
100
94
|
expected_text == actual
|
101
95
|
end
|
102
96
|
end
|
@@ -122,27 +116,27 @@ module Seleniumrc
|
|
122
116
|
is_present
|
123
117
|
eval_js = "this.page().findElement('#{locator}').nextSibling.id"
|
124
118
|
wait_for(:message => "id '#{locator}' should be next to '#{expected_sibling_id}'") do
|
125
|
-
actual_sibling_id =
|
119
|
+
actual_sibling_id = driver.get_eval(eval_js)
|
126
120
|
expected_sibling_id == actual_sibling_id
|
127
121
|
end
|
128
122
|
end
|
129
123
|
|
130
124
|
def has_text_in_order(*text_fragments)
|
131
125
|
is_present
|
132
|
-
wait_for do |
|
126
|
+
wait_for do |configuration|
|
133
127
|
success = false
|
134
128
|
|
135
|
-
html =
|
129
|
+
html = driver.get_text(locator)
|
136
130
|
results = find_text_order_error_fragments(html, text_fragments)
|
137
131
|
fragments_not_found = results[:fragments_not_found]
|
138
132
|
fragments_out_of_order = results[:fragments_out_of_order]
|
139
133
|
|
140
134
|
if !fragments_not_found.empty?
|
141
|
-
|
135
|
+
configuration.message = "Certain fragments weren't found:\n" <<
|
142
136
|
"#{fragments_not_found.join("\n")}\n" <<
|
143
137
|
"\nhtml follows:\n #{html}\n"
|
144
138
|
elsif !fragments_out_of_order.empty?
|
145
|
-
|
139
|
+
configuration.message = "Certain fragments were out of order:\n" <<
|
146
140
|
"#{fragments_out_of_order.join("\n")}\n" <<
|
147
141
|
"\nhtml follows:\n #{html}\n"
|
148
142
|
else
|
@@ -154,12 +148,12 @@ module Seleniumrc
|
|
154
148
|
end
|
155
149
|
|
156
150
|
def inner_html
|
157
|
-
|
151
|
+
driver.get_inner_html(locator)
|
158
152
|
end
|
159
153
|
|
160
154
|
def ==(other)
|
161
155
|
return false unless other.is_a?(SeleniumElement)
|
162
|
-
return false unless self.
|
156
|
+
return false unless self.driver == other.driver
|
163
157
|
return false unless self.locator == other.locator
|
164
158
|
true
|
165
159
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
module Seleniumrc
|
2
2
|
class SeleniumPage
|
3
3
|
include WaitFor
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :driver
|
5
5
|
PAGE_LOADED_COMMAND = "this.browserbot.getDocument().body ? true : false"
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(driver)
|
8
|
+
@driver = driver
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
wait_for_page_to_load
|
11
|
+
def open(url)
|
12
|
+
driver.open(url)
|
14
13
|
end
|
14
|
+
alias_method :open_and_wait, :open
|
15
15
|
|
16
16
|
def has_title(expected_title, params = {})
|
17
|
-
wait_for(params) do |
|
18
|
-
actual_title =
|
19
|
-
|
17
|
+
wait_for(params) do |configuration|
|
18
|
+
actual_title = driver.get_title
|
19
|
+
configuration.message = "Expected title '#{expected_title}' but was '#{actual_title}'"
|
20
20
|
has_title? expected_title, actual_title
|
21
21
|
end
|
22
22
|
end
|
23
|
-
def has_title?(expected_title, actual_title=
|
23
|
+
def has_title?(expected_title, actual_title=driver.get_title)
|
24
24
|
expected_title == actual_title
|
25
25
|
end
|
26
26
|
|
@@ -33,7 +33,7 @@ module Seleniumrc
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
def is_text_present?(expected_text)
|
36
|
-
page_loaded? &&
|
36
|
+
page_loaded? && driver.is_text_present(expected_text)
|
37
37
|
end
|
38
38
|
|
39
39
|
def is_text_not_present(unexpected_text, options = {})
|
@@ -45,23 +45,23 @@ module Seleniumrc
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
def is_text_not_present?(unexpected_text)
|
48
|
-
page_loaded? && !
|
48
|
+
page_loaded? && !driver.is_text_present(unexpected_text)
|
49
49
|
end
|
50
50
|
|
51
51
|
def page_loaded?
|
52
|
-
|
52
|
+
driver.get_eval(PAGE_LOADED_COMMAND) == true.to_s
|
53
53
|
end
|
54
54
|
|
55
55
|
def url_ends_with(ends_with, options={})
|
56
56
|
options = {
|
57
|
-
:message => "Expected '#{
|
57
|
+
:message => "Expected '#{driver.get_location}' to end with '#{ends_with}'"
|
58
58
|
}.merge(options)
|
59
59
|
wait_for(options) do
|
60
60
|
url_ends_with? ends_with
|
61
61
|
end
|
62
62
|
end
|
63
63
|
def url_ends_with?(ends_with)
|
64
|
-
if
|
64
|
+
if driver.get_location =~ Regexp.new("#{Regexp.escape(ends_with)}$")
|
65
65
|
true
|
66
66
|
else
|
67
67
|
false
|
@@ -70,7 +70,7 @@ module Seleniumrc
|
|
70
70
|
|
71
71
|
def ==(other)
|
72
72
|
return false unless other.is_a?(SeleniumPage)
|
73
|
-
self.
|
73
|
+
self.driver == other.driver
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|