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
@@ -2,20 +2,22 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
2
2
|
|
3
3
|
module Seleniumrc
|
4
4
|
describe SeleniumPage, :shared => true do
|
5
|
+
it_should_behave_like "Selenium"
|
5
6
|
include SeleniumTestCaseSpec
|
7
|
+
attr_reader :driver
|
6
8
|
|
7
9
|
before do
|
8
|
-
@
|
9
|
-
@page = SeleniumPage.new(
|
10
|
+
@driver = ::Seleniumrc::SeleniumDriver.new('http://test.host', 4000, "*firefox", 'http://test.host')
|
11
|
+
@page = SeleniumPage.new(driver)
|
10
12
|
page_loaded
|
11
13
|
end
|
12
14
|
|
13
15
|
def page_loaded
|
14
|
-
stub(
|
16
|
+
stub(driver).get_eval(SeleniumPage::PAGE_LOADED_COMMAND) {"true"}
|
15
17
|
end
|
16
18
|
|
17
19
|
def page_not_loaded
|
18
|
-
stub(
|
20
|
+
stub(driver).get_eval(SeleniumPage::PAGE_LOADED_COMMAND) {"false"}
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -23,7 +25,7 @@ describe SeleniumPage, "#initialize" do
|
|
23
25
|
it_should_behave_like "Seleniumrc::SeleniumPage"
|
24
26
|
|
25
27
|
it "sets the selenium object" do
|
26
|
-
@page.
|
28
|
+
@page.driver.should == driver
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -31,19 +33,27 @@ describe SeleniumPage, "#open_and_wait" do
|
|
31
33
|
it_should_behave_like "Seleniumrc::SeleniumPage"
|
32
34
|
|
33
35
|
it "opens the url and waits for the page to load" do
|
34
|
-
mock(
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
mock(driver) do |m|
|
37
|
+
m.do_command("open", ["/users/list"]) {result}
|
38
|
+
m.do_command("waitForPageToLoad", [@page.default_timeout]) do
|
39
|
+
result
|
40
|
+
end
|
41
|
+
m.do_command("getTitle", []) do
|
42
|
+
result("Users in the project")
|
43
|
+
end
|
38
44
|
end
|
39
45
|
@page.open_and_wait("/users/list")
|
40
46
|
end
|
41
47
|
|
42
48
|
it "fails when titles contains Exception caught" do
|
43
|
-
mock(
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
mock(driver) do |m|
|
50
|
+
m.do_command("open", ["/users/list"]) {result}
|
51
|
+
m.do_command("waitForPageToLoad", [@page.default_timeout]) do
|
52
|
+
result
|
53
|
+
end
|
54
|
+
m.do_command("getTitle", []) do
|
55
|
+
result("Exception caught")
|
56
|
+
end
|
47
57
|
end
|
48
58
|
proc do
|
49
59
|
@page.open_and_wait("/users/list")
|
@@ -56,14 +66,14 @@ describe SeleniumPage, "#has_title" do
|
|
56
66
|
|
57
67
|
it "passes when title is expected" do
|
58
68
|
ticks = ["no page", "no page", "no page", "my page"]
|
59
|
-
mock(
|
69
|
+
mock(driver).get_title do
|
60
70
|
ticks.shift
|
61
71
|
end.times(4)
|
62
72
|
@page.has_title("my page")
|
63
73
|
end
|
64
74
|
|
65
75
|
it "fails when element is not present" do
|
66
|
-
stub(
|
76
|
+
stub(driver).get_title {"no page"}
|
67
77
|
proc do
|
68
78
|
@page.has_title("my page")
|
69
79
|
end.should raise_error("Expected title 'my page' but was 'no page' (after 5 sec)")
|
@@ -74,12 +84,12 @@ describe SeleniumPage, "#has_title?" do
|
|
74
84
|
it_should_behave_like "Seleniumrc::SeleniumPage"
|
75
85
|
|
76
86
|
it "returns true when passed in title is the page title" do
|
77
|
-
mock(
|
87
|
+
mock(driver).get_title {"my page"}
|
78
88
|
@page.has_title?("my page").should be_true
|
79
89
|
end
|
80
90
|
|
81
91
|
it "returns false when passed in title is not the page title" do
|
82
|
-
mock(
|
92
|
+
mock(driver).get_title {"no page"}
|
83
93
|
@page.has_title?("my page").should be_false
|
84
94
|
end
|
85
95
|
end
|
@@ -89,7 +99,7 @@ describe SeleniumPage, "#is_text_present" do
|
|
89
99
|
|
90
100
|
it "passes when title is expected" do
|
91
101
|
ticks = [false, false, false, true]
|
92
|
-
mock(
|
102
|
+
mock(driver).is_text_present("my page") do
|
93
103
|
ticks.shift
|
94
104
|
end.times(4)
|
95
105
|
@page.is_text_present("my page")
|
@@ -103,7 +113,7 @@ describe SeleniumPage, "#is_text_present" do
|
|
103
113
|
end
|
104
114
|
|
105
115
|
it "fails when element is not present" do
|
106
|
-
stub(
|
116
|
+
stub(driver).is_text_present("my page") {false}
|
107
117
|
proc do
|
108
118
|
@page.is_text_present("my page")
|
109
119
|
end.should raise_error("Expected 'my page' to be present, but it wasn't (after 5 sec)")
|
@@ -114,12 +124,12 @@ describe SeleniumPage, "#is_text_present?" do
|
|
114
124
|
it_should_behave_like "Seleniumrc::SeleniumPage"
|
115
125
|
|
116
126
|
it "returns true when title is expected" do
|
117
|
-
mock(
|
127
|
+
mock(driver).is_text_present("my page") {true}
|
118
128
|
@page.is_text_present?("my page").should be_true
|
119
129
|
end
|
120
130
|
|
121
131
|
it "fails when element is not present" do
|
122
|
-
mock(
|
132
|
+
mock(driver).is_text_present("my page") {false}
|
123
133
|
@page.is_text_present?("my page").should be_false
|
124
134
|
end
|
125
135
|
end
|
@@ -129,7 +139,7 @@ describe SeleniumPage, "#is_text_not_present" do
|
|
129
139
|
|
130
140
|
it "passes when text is not present" do
|
131
141
|
ticks = [true, true, true, false]
|
132
|
-
mock(
|
142
|
+
mock(driver).is_text_present("my page") do
|
133
143
|
ticks.shift
|
134
144
|
end.times(4)
|
135
145
|
@page.is_text_not_present("my page")
|
@@ -143,7 +153,7 @@ describe SeleniumPage, "#is_text_not_present" do
|
|
143
153
|
end
|
144
154
|
|
145
155
|
it "fails when text is present" do
|
146
|
-
stub(
|
156
|
+
stub(driver).is_text_present("my page") {true}
|
147
157
|
proc do
|
148
158
|
@page.is_text_not_present("my page")
|
149
159
|
end.should raise_error("Expected 'my page' to be absent, but it wasn't (after 5 sec)")
|
@@ -154,12 +164,12 @@ describe SeleniumPage, "#is_text_not_present?" do
|
|
154
164
|
it_should_behave_like "Seleniumrc::SeleniumPage"
|
155
165
|
|
156
166
|
it "returns true when text is not present" do
|
157
|
-
mock(
|
167
|
+
mock(driver).is_text_present("my page") {false}
|
158
168
|
@page.is_text_not_present?("my page").should be_true
|
159
169
|
end
|
160
170
|
|
161
171
|
it "returns false when text is present" do
|
162
|
-
mock(
|
172
|
+
mock(driver).is_text_present("my page") {true}
|
163
173
|
@page.is_text_not_present?("my page").should be_false
|
164
174
|
end
|
165
175
|
end
|
@@ -178,14 +188,14 @@ describe SeleniumPage, "#url_ends_with" do
|
|
178
188
|
"http://no.com",
|
179
189
|
"http://foobar.com?arg1=2"
|
180
190
|
]
|
181
|
-
mock(
|
191
|
+
mock(driver).get_location do
|
182
192
|
ticks.shift
|
183
193
|
end.times(4)
|
184
194
|
@page.url_ends_with(@ends_with)
|
185
195
|
end
|
186
196
|
|
187
197
|
it "fails when element is not present" do
|
188
|
-
stub(
|
198
|
+
stub(driver).get_location {"http://no.com"}
|
189
199
|
proc do
|
190
200
|
@page.url_ends_with(@ends_with)
|
191
201
|
end.should raise_error("Expected 'http://no.com' to end with '#{@ends_with}' (after 5 sec)")
|
@@ -200,12 +210,12 @@ describe SeleniumPage, "#url_ends_with?" do
|
|
200
210
|
end
|
201
211
|
|
202
212
|
it "passes when title is expected" do
|
203
|
-
mock(
|
213
|
+
mock(driver).get_location {"http://foobar.com?arg1=2"}
|
204
214
|
@page.url_ends_with?(@ends_with).should be_true
|
205
215
|
end
|
206
216
|
|
207
217
|
it "fails when element is not present" do
|
208
|
-
mock(
|
218
|
+
mock(driver).get_location {"http://no.com"}
|
209
219
|
@page.url_ends_with?(@ends_with).should be_false
|
210
220
|
end
|
211
221
|
end
|
@@ -1,908 +1,866 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
module Seleniumrc
|
4
|
-
describe SeleniumTestCase, :shared => true do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def sample_text
|
20
|
-
"test text"
|
21
|
-
end
|
22
|
-
|
23
|
-
def stub_selenium_configuration
|
24
|
-
@context = SeleniumContext.new
|
25
|
-
@context.external_app_server_host = "test.com"
|
26
|
-
@context.external_app_server_port = 80
|
27
|
-
|
28
|
-
stub(SeleniumConfiguration.instance).returns(@context)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe SeleniumTestCase, "#setup" do
|
33
|
-
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
34
|
-
|
35
|
-
it "should not allow transactional fixtures" do
|
36
|
-
stub(@test_case.class).use_transactional_fixtures.returns true
|
37
|
-
|
38
|
-
expected_message = "Cannot use transactional fixtures if ActiveRecord concurrency is turned on (which is required for Selenium tests to work)."
|
39
|
-
proc {@test_case.setup}.should raise_error(RuntimeError, expected_message)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe SeleniumTestCase, "#wait_for" do
|
44
|
-
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
45
|
-
|
46
|
-
it "should pass when the block returns true within time limit" do
|
47
|
-
@test_case.wait_for(:timeout => 2) do
|
48
|
-
true
|
4
|
+
describe SeleniumTestCase, :shared => true do
|
5
|
+
it_should_behave_like "Selenium"
|
6
|
+
include SeleniumTestCaseSpec
|
7
|
+
attr_reader :driver, :test_case, :configuration
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
stub_selenium_configuration
|
11
|
+
@test_case = SeleniumTestCaseSpec::MySeleniumTestCase.new
|
12
|
+
@driver = ::Seleniumrc::SeleniumDriver.new('http://test.host', 4000, "*firefox", 'http://test.host')
|
13
|
+
test_case.selenium_driver = driver
|
14
|
+
stub(driver).do_command("getEval", [SeleniumPage::PAGE_LOADED_COMMAND]) do
|
15
|
+
result(true)
|
16
|
+
end
|
49
17
|
end
|
50
|
-
end
|
51
18
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end.should raise_error(Test::Unit::AssertionFailedError, "Timeout exceeded (after 2 sec)")
|
56
|
-
end
|
57
|
-
end
|
19
|
+
def sample_locator
|
20
|
+
"sample_locator"
|
21
|
+
end
|
58
22
|
|
59
|
-
|
60
|
-
|
23
|
+
def sample_text
|
24
|
+
"test text"
|
25
|
+
end
|
61
26
|
|
62
|
-
|
63
|
-
|
27
|
+
def stub_selenium_configuration
|
28
|
+
@configuration = SeleniumConfiguration.new
|
29
|
+
configuration.external_app_server_host = "test.com"
|
30
|
+
configuration.external_app_server_port = 80
|
64
31
|
|
65
|
-
|
66
|
-
stub(base_selenium).get_eval("this.page().findElement(\"#{sample_locator}\").innerHTML") do
|
67
|
-
sample_text
|
32
|
+
stub(SeleniumConfiguration.instance) {configuration}
|
68
33
|
end
|
69
|
-
|
70
|
-
@test_case.wait_for_element_to_contain(sample_locator, sample_text)
|
71
34
|
end
|
72
35
|
|
73
|
-
|
74
|
-
|
36
|
+
describe SeleniumTestCase, "#setup" do
|
37
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
75
38
|
|
76
|
-
|
39
|
+
it "should not allow transactional fixtures" do
|
40
|
+
test_case.class.use_transactional_fixtures = true
|
77
41
|
|
78
|
-
|
79
|
-
|
80
|
-
|
42
|
+
expected_message = "Cannot use transactional fixtures if ActiveRecord concurrency is turned on (which is required for Selenium tests to work)."
|
43
|
+
proc do
|
44
|
+
test_case.setup
|
45
|
+
end.should raise_error(RuntimeError, expected_message)
|
46
|
+
end
|
81
47
|
end
|
82
48
|
|
83
|
-
|
84
|
-
|
49
|
+
describe SeleniumTestCase, "#wait_for" do
|
50
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
85
51
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
52
|
+
it "should pass when the block returns true within time limit" do
|
53
|
+
test_case.wait_for(:timeout => 2) do
|
54
|
+
true
|
55
|
+
end
|
56
|
+
end
|
90
57
|
|
91
|
-
|
92
|
-
|
93
|
-
|
58
|
+
it "should raise a AssertionFailedError when block times out" do
|
59
|
+
proc do
|
60
|
+
test_case.wait_for(:timeout => 2) {false}
|
61
|
+
end.should raise_error(Test::Unit::AssertionFailedError, "Timeout exceeded (after 2 sec)")
|
62
|
+
end
|
94
63
|
end
|
95
|
-
end
|
96
64
|
|
97
|
-
describe SeleniumTestCase, "#default_timeout" do
|
98
|
-
|
65
|
+
describe SeleniumTestCase, "#default_timeout" do
|
66
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
99
67
|
|
100
|
-
|
101
|
-
|
68
|
+
it "default_timeout should be 20 seconds" do
|
69
|
+
test_case.default_timeout.should == 20000
|
70
|
+
end
|
102
71
|
end
|
103
|
-
end
|
104
72
|
|
105
|
-
describe SeleniumTestCase, "#open_home_page" do
|
106
|
-
|
73
|
+
describe SeleniumTestCase, "#open_home_page" do
|
74
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
107
75
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
@test_case.open_home_page
|
76
|
+
it "opens home page" do
|
77
|
+
mock(driver).open("http://localhost:4000")
|
78
|
+
test_case.open_home_page
|
79
|
+
end
|
114
80
|
end
|
115
|
-
end
|
116
81
|
|
117
|
-
describe SeleniumTestCase, "#
|
118
|
-
|
82
|
+
describe SeleniumTestCase, "#assert_title" do
|
83
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
119
84
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
page
|
85
|
+
it "when title is expected, passes" do
|
86
|
+
mock(driver).do_command("getTitle", []) {result("my page")}
|
87
|
+
test_case.assert_title("my page")
|
124
88
|
end
|
125
|
-
end
|
126
89
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
90
|
+
it "when title is not expected, fails" do
|
91
|
+
stub(driver).do_command("getTitle", []) {result("no page")}
|
92
|
+
proc do
|
93
|
+
test_case.assert_title("my page")
|
94
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
132
95
|
end
|
133
|
-
@test_case.open_and_wait("/users/list")
|
134
96
|
end
|
135
|
-
end
|
136
97
|
|
137
|
-
describe SeleniumTestCase, "#
|
138
|
-
|
98
|
+
describe SeleniumTestCase, "#assert_text_present" do
|
99
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
139
100
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
101
|
+
before do
|
102
|
+
mock.proxy(SeleniumPage).new(driver) do |page|
|
103
|
+
mock.proxy(page).is_text_present("my page", {})
|
104
|
+
page
|
105
|
+
end
|
144
106
|
end
|
145
|
-
end
|
146
107
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
stub(base_selenium).get_title {"no page"}
|
154
|
-
proc do
|
155
|
-
@test_case.assert_title("my page")
|
156
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe SeleniumTestCase, "#assert_text_present" do
|
161
|
-
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
162
|
-
|
163
|
-
before do
|
164
|
-
mock.proxy(SeleniumPage).new(base_selenium) do |page|
|
165
|
-
mock.proxy(page).is_text_present("my page", {})
|
166
|
-
page
|
108
|
+
it "passes when text is in page" do
|
109
|
+
ticks = [false, false, false, true]
|
110
|
+
mock(driver).is_text_present("my page") do
|
111
|
+
ticks.shift
|
112
|
+
end.times(4)
|
113
|
+
test_case.assert_text_present("my page")
|
167
114
|
end
|
168
|
-
end
|
169
115
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
it "fails when text is not in page" do
|
179
|
-
stub(base_selenium).is_text_present("my page") {false}
|
180
|
-
proc do
|
181
|
-
@test_case.assert_text_present("my page")
|
182
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
116
|
+
it "fails when text is not in page" do
|
117
|
+
stub(driver).is_text_present("my page") {false}
|
118
|
+
proc do
|
119
|
+
test_case.assert_text_present("my page")
|
120
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
121
|
+
end
|
183
122
|
end
|
184
|
-
end
|
185
123
|
|
186
|
-
describe SeleniumTestCase, "#assert_text_not_present" do
|
187
|
-
|
124
|
+
describe SeleniumTestCase, "#assert_text_not_present" do
|
125
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
188
126
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
127
|
+
before do
|
128
|
+
mock.proxy(SeleniumPage).new(driver) do |page|
|
129
|
+
mock.proxy(page).is_text_not_present("my page", {})
|
130
|
+
page
|
131
|
+
end
|
193
132
|
end
|
194
|
-
end
|
195
133
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
134
|
+
it "passes when text is not in page" do
|
135
|
+
ticks = [true, true, true, false]
|
136
|
+
mock(driver).is_text_present("my page") do
|
137
|
+
ticks.shift
|
138
|
+
end.times(4)
|
139
|
+
test_case.assert_text_not_present("my page")
|
140
|
+
end
|
203
141
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
142
|
+
it "fails when text is in page" do
|
143
|
+
stub(driver).is_text_present("my page") {true}
|
144
|
+
proc do
|
145
|
+
test_case.assert_text_not_present("my page")
|
146
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
147
|
+
end
|
209
148
|
end
|
210
|
-
end
|
211
149
|
|
212
|
-
describe SeleniumTestCase, "#assert_location_ends_in" do
|
213
|
-
|
150
|
+
describe SeleniumTestCase, "#assert_location_ends_in" do
|
151
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
214
152
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
153
|
+
before do
|
154
|
+
@ends_with = "foobar.com?arg1=2"
|
155
|
+
mock.proxy(SeleniumPage).new(driver) do |page|
|
156
|
+
mock.proxy(page).url_ends_with(@ends_with, {})
|
157
|
+
page
|
158
|
+
end
|
220
159
|
end
|
221
|
-
end
|
222
160
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
161
|
+
it "passes when the url ends with the passed in value" do
|
162
|
+
ticks = [
|
163
|
+
"http://no.com",
|
164
|
+
"http://no.com",
|
165
|
+
"http://no.com",
|
166
|
+
"http://foobar.com?arg1=2"
|
167
|
+
]
|
168
|
+
mock(driver).get_location do
|
169
|
+
ticks.shift
|
170
|
+
end.times(4)
|
171
|
+
test_case.assert_location_ends_in(@ends_with)
|
172
|
+
end
|
235
173
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
174
|
+
it "fails when the url does not end with the passed in value" do
|
175
|
+
stub(driver).get_location {"http://no.com"}
|
176
|
+
proc do
|
177
|
+
test_case.assert_location_ends_in(@ends_with)
|
178
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
179
|
+
end
|
241
180
|
end
|
242
|
-
end
|
243
181
|
|
244
|
-
describe SeleniumTestCase, "#assert_element_present" do
|
245
|
-
|
182
|
+
describe SeleniumTestCase, "#assert_element_present" do
|
183
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
246
184
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
185
|
+
before do
|
186
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
187
|
+
mock.proxy(element).is_present({})
|
188
|
+
element
|
189
|
+
end
|
251
190
|
end
|
252
|
-
end
|
253
191
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
192
|
+
it "passes when element is present" do
|
193
|
+
ticks = [false, false, false, true]
|
194
|
+
mock(driver).do_command("isElementPresent", [sample_locator]).times(4) do
|
195
|
+
result(ticks.shift)
|
196
|
+
end
|
197
|
+
test_case.assert_element_present(sample_locator)
|
260
198
|
end
|
261
|
-
@test_case.assert_element_present(sample_locator)
|
262
|
-
end
|
263
199
|
|
264
|
-
|
265
|
-
|
266
|
-
|
200
|
+
it "fails when element is not present" do
|
201
|
+
stub(driver).do_command("isElementPresent", [sample_locator]) do
|
202
|
+
result(false)
|
203
|
+
end
|
204
|
+
proc do
|
205
|
+
test_case.assert_element_present(sample_locator)
|
206
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
267
207
|
end
|
268
|
-
proc do
|
269
|
-
@test_case.assert_element_present(sample_locator)
|
270
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
271
208
|
end
|
272
|
-
end
|
273
209
|
|
274
|
-
describe SeleniumTestCase, "#assert_element_not_present" do
|
275
|
-
|
210
|
+
describe SeleniumTestCase, "#assert_element_not_present" do
|
211
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
276
212
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
213
|
+
before do
|
214
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
215
|
+
mock.proxy(element).is_not_present({})
|
216
|
+
element
|
217
|
+
end
|
281
218
|
end
|
282
|
-
end
|
283
219
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
220
|
+
it "passes when element is not present" do
|
221
|
+
ticks = [true, true, true, false]
|
222
|
+
mock(driver) do |o|
|
223
|
+
o.is_element_present(sample_locator) do
|
224
|
+
ticks.shift
|
225
|
+
end.times(4)
|
226
|
+
end
|
227
|
+
test_case.assert_element_not_present(sample_locator)
|
290
228
|
end
|
291
|
-
@test_case.assert_element_not_present(sample_locator)
|
292
|
-
end
|
293
229
|
|
294
|
-
|
295
|
-
|
296
|
-
|
230
|
+
it "fails when element is present" do
|
231
|
+
stub(driver) do |o|
|
232
|
+
o.is_element_present(sample_locator) {true}
|
233
|
+
end
|
234
|
+
proc do
|
235
|
+
test_case.assert_element_not_present(sample_locator)
|
236
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
297
237
|
end
|
298
|
-
proc do
|
299
|
-
@test_case.assert_element_not_present(sample_locator)
|
300
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
301
238
|
end
|
302
|
-
end
|
303
239
|
|
304
|
-
describe SeleniumTestCase, "#assert_value" do
|
305
|
-
|
240
|
+
describe SeleniumTestCase, "#assert_value" do
|
241
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
306
242
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
243
|
+
before do
|
244
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
245
|
+
mock.proxy(element).has_value("passed in value")
|
246
|
+
element
|
247
|
+
end
|
311
248
|
end
|
312
|
-
end
|
313
249
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
250
|
+
it "passes when value is expected" do
|
251
|
+
mock(driver) do |o|
|
252
|
+
o.is_element_present(sample_locator) {true}
|
253
|
+
o.get_value(sample_locator) {"passed in value"}
|
254
|
+
end
|
255
|
+
test_case.assert_value(sample_locator, "passed in value")
|
318
256
|
end
|
319
|
-
@test_case.assert_value(sample_locator, "passed in value")
|
320
|
-
end
|
321
257
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
258
|
+
it "fails when value is not expected" do
|
259
|
+
stub(driver) do |o|
|
260
|
+
o.is_element_present(sample_locator) {true}
|
261
|
+
o.get_value(sample_locator) {"another value"}
|
262
|
+
end
|
263
|
+
proc do
|
264
|
+
test_case.assert_value(sample_locator, "passed in value")
|
265
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
326
266
|
end
|
327
|
-
proc do
|
328
|
-
@test_case.assert_value(sample_locator, "passed in value")
|
329
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
330
267
|
end
|
331
|
-
end
|
332
268
|
|
333
|
-
describe SeleniumTestCase, "#assert_element_contains" do
|
334
|
-
|
269
|
+
describe SeleniumTestCase, "#assert_element_contains" do
|
270
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
335
271
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
272
|
+
before do
|
273
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
274
|
+
mock.proxy(element).contains_text("passed in value", {})
|
275
|
+
element
|
276
|
+
end
|
277
|
+
@evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
|
340
278
|
end
|
341
|
-
@evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
|
342
|
-
end
|
343
279
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
280
|
+
it "passes when text is in the element's inner_html" do
|
281
|
+
mock(driver) do |o|
|
282
|
+
o.is_element_present(sample_locator) {true}
|
283
|
+
o.get_eval(@evaled_js) do
|
284
|
+
"html passed in value html"
|
285
|
+
end
|
349
286
|
end
|
287
|
+
test_case.assert_element_contains(sample_locator, "passed in value")
|
350
288
|
end
|
351
|
-
@test_case.assert_element_contains(sample_locator, "passed in value")
|
352
|
-
end
|
353
289
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
290
|
+
it "fails when text is not in the element's inner_html" do
|
291
|
+
stub(driver) do |o|
|
292
|
+
o.is_element_present(sample_locator) {true}
|
293
|
+
o.get_eval(@evaled_js) {"another value"}
|
294
|
+
end
|
295
|
+
proc do
|
296
|
+
test_case.assert_element_contains(sample_locator, "passed in value")
|
297
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
358
298
|
end
|
359
|
-
proc do
|
360
|
-
@test_case.assert_element_contains(sample_locator, "passed in value")
|
361
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
362
299
|
end
|
363
|
-
end
|
364
300
|
|
365
|
-
describe SeleniumTestCase, "#element_does_not_contain_text" do
|
366
|
-
|
367
|
-
|
368
|
-
it "returns true when element is not on the page" do
|
369
|
-
locator = "id=element_id"
|
370
|
-
expected_text = "foobar"
|
371
|
-
mock(base_selenium).is_element_present.with(locator).returns(false)
|
301
|
+
describe SeleniumTestCase, "#element_does_not_contain_text" do
|
302
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
372
303
|
|
373
|
-
|
374
|
-
|
304
|
+
it "when element is not on the page, returns true" do
|
305
|
+
locator = "id=element_id"
|
306
|
+
expected_text = "foobar"
|
307
|
+
mock(driver).is_element_present(locator) {false}
|
375
308
|
|
376
|
-
|
377
|
-
|
378
|
-
inner_html = "Some text that does not contain the expected_text"
|
379
|
-
expected_text = "foobar"
|
380
|
-
mock(base_selenium).is_element_present.with(locator).returns(true)
|
381
|
-
mock(@test_case).get_inner_html.with(locator).returns(inner_html)
|
309
|
+
test_case.element_does_not_contain_text(locator, expected_text).should == true
|
310
|
+
end
|
382
311
|
|
383
|
-
|
384
|
-
|
312
|
+
it "when element is on page and inner_html does not contain text, returns true" do
|
313
|
+
locator = "id=element_id"
|
314
|
+
inner_html = "Some text that does not contain the expected_text"
|
315
|
+
expected_text = "foobar"
|
316
|
+
mock(driver).do_command("isElementPresent", [locator]) do
|
317
|
+
result(true)
|
318
|
+
end
|
319
|
+
mock(driver).do_command("getEval", [driver.inner_html_js(locator)]) do
|
320
|
+
inner_html
|
321
|
+
end
|
385
322
|
|
386
|
-
|
387
|
-
|
388
|
-
inner_html = "foobar foobar foobar"
|
389
|
-
expected_text = "foobar"
|
390
|
-
mock(base_selenium).is_element_present.with(locator).returns(true)
|
391
|
-
mock(@test_case).get_inner_html.with(locator).returns(inner_html)
|
323
|
+
test_case.element_does_not_contain_text(locator, expected_text).should == true
|
324
|
+
end
|
392
325
|
|
393
|
-
|
326
|
+
it "when element is on page and inner_html does contain text, returns false" do
|
327
|
+
locator = "id=element_id"
|
328
|
+
inner_html = "foobar foobar foobar"
|
329
|
+
expected_text = "foobar"
|
330
|
+
mock(driver).do_command("isElementPresent", [locator]) do
|
331
|
+
result(true)
|
332
|
+
end
|
333
|
+
mock(driver).do_command("getEval", [driver.inner_html_js(locator)]) do
|
334
|
+
inner_html
|
335
|
+
end
|
336
|
+
|
337
|
+
test_case.element_does_not_contain_text(locator, expected_text).should == false
|
338
|
+
end
|
394
339
|
end
|
395
|
-
end
|
396
340
|
|
397
|
-
describe SeleniumTestCase, "#assert_element_does_not_contain_text" do
|
398
|
-
|
341
|
+
describe SeleniumTestCase, "#assert_element_does_not_contain_text" do
|
342
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
399
343
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
344
|
+
before do
|
345
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
346
|
+
mock.proxy(element).does_not_contain_text("passed in value", {})
|
347
|
+
element
|
348
|
+
end
|
349
|
+
@evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
|
404
350
|
end
|
405
|
-
@evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
|
406
|
-
end
|
407
351
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
352
|
+
it "passes when text is not in the element's inner_html" do
|
353
|
+
mock(driver) do |o|
|
354
|
+
o.is_element_present(sample_locator) {true}
|
355
|
+
o.get_eval(@evaled_js) do
|
356
|
+
"another value"
|
357
|
+
end
|
413
358
|
end
|
359
|
+
test_case.assert_element_does_not_contain_text(sample_locator, "passed in value")
|
414
360
|
end
|
415
|
-
@test_case.assert_element_does_not_contain_text(sample_locator, "passed in value")
|
416
|
-
end
|
417
361
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
362
|
+
it "fails when text is in the element's inner_html" do
|
363
|
+
stub(driver) do |o|
|
364
|
+
o.is_element_present(sample_locator) {true}
|
365
|
+
o.get_eval(@evaled_js) {"html passed in value html"}
|
366
|
+
end
|
367
|
+
proc do
|
368
|
+
test_case.assert_element_does_not_contain_text(sample_locator, "passed in value")
|
369
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
422
370
|
end
|
423
|
-
proc do
|
424
|
-
@test_case.assert_element_does_not_contain_text(sample_locator, "passed in value")
|
425
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
426
371
|
end
|
427
|
-
end
|
428
372
|
|
429
|
-
describe SeleniumTestCase, "#element_does_not_contain_text" do
|
430
|
-
|
373
|
+
describe SeleniumTestCase, "#element_does_not_contain_text" do
|
374
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
431
375
|
|
432
|
-
|
433
|
-
|
434
|
-
|
376
|
+
it "checks if text is in order" do
|
377
|
+
locator = "id=foo"
|
378
|
+
stub(@driver).get_text(locator).returns("one\ntwo\nthree\n")
|
435
379
|
|
436
|
-
|
380
|
+
test_case.is_text_in_order locator, "one", "two", "three"
|
381
|
+
end
|
437
382
|
end
|
438
|
-
end
|
439
383
|
|
440
|
-
describe SeleniumTestCase, "#assert_attribute" do
|
441
|
-
|
384
|
+
describe SeleniumTestCase, "#assert_attribute" do
|
385
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
442
386
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
387
|
+
before do
|
388
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
389
|
+
mock.proxy(element).has_attribute("passed in value")
|
390
|
+
element
|
391
|
+
end
|
447
392
|
end
|
448
|
-
end
|
449
393
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
394
|
+
it "passes when attribute is expected" do
|
395
|
+
mock(driver) do |o|
|
396
|
+
o.is_element_present(sample_locator) {true}
|
397
|
+
o.get_attribute(sample_locator) {"passed in value"}
|
398
|
+
end
|
399
|
+
test_case.assert_attribute(sample_locator, "passed in value")
|
454
400
|
end
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
401
|
+
|
402
|
+
it "fails when attribute is not expected" do
|
403
|
+
stub(driver) do |o|
|
404
|
+
o.is_element_present(sample_locator) {true}
|
405
|
+
o.get_attribute(sample_locator) {"another value"}
|
406
|
+
end
|
407
|
+
proc do
|
408
|
+
test_case.assert_attribute(sample_locator, "passed in value")
|
409
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
462
410
|
end
|
463
|
-
proc do
|
464
|
-
@test_case.assert_attribute(sample_locator, "passed in value")
|
465
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
466
411
|
end
|
467
|
-
end
|
468
412
|
|
469
|
-
describe SeleniumTestCase, "#assert_selected" do
|
470
|
-
|
413
|
+
describe SeleniumTestCase, "#assert_selected" do
|
414
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
471
415
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
416
|
+
before do
|
417
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
418
|
+
mock.proxy(element).has_selected("passed_in_element")
|
419
|
+
element
|
420
|
+
end
|
476
421
|
end
|
477
|
-
end
|
478
422
|
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
423
|
+
it "passes when selected is expected" do
|
424
|
+
mock(driver) do |o|
|
425
|
+
o.is_element_present(sample_locator) {true}
|
426
|
+
o.get_selected_label(sample_locator) {"passed_in_element"}
|
427
|
+
end
|
428
|
+
test_case.assert_selected(sample_locator, "passed_in_element")
|
483
429
|
end
|
484
|
-
@test_case.assert_selected(sample_locator, "passed_in_element")
|
485
|
-
end
|
486
430
|
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
431
|
+
it "fails when selected is not expected" do
|
432
|
+
stub(driver) do |o|
|
433
|
+
o.is_element_present(sample_locator) {true}
|
434
|
+
o.get_selected_label(sample_locator) {"another_element"}
|
435
|
+
end
|
436
|
+
proc do
|
437
|
+
test_case.assert_selected(sample_locator, "passed_in_element")
|
438
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
491
439
|
end
|
492
|
-
|
493
|
-
@test_case.assert_selected(sample_locator, "passed_in_element")
|
494
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
495
|
-
end
|
496
|
-
end
|
440
|
+
end
|
497
441
|
|
498
|
-
describe SeleniumTestCase, "#assert_checked" do
|
499
|
-
|
442
|
+
describe SeleniumTestCase, "#assert_checked" do
|
443
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
500
444
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
445
|
+
before do
|
446
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
447
|
+
mock.proxy(element).is_checked
|
448
|
+
element
|
449
|
+
end
|
505
450
|
end
|
506
|
-
end
|
507
451
|
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
452
|
+
it "passes when checked" do
|
453
|
+
mock(driver) do |o|
|
454
|
+
o.is_element_present(sample_locator) {true}
|
455
|
+
o.is_checked(sample_locator) {true}
|
456
|
+
end
|
457
|
+
test_case.assert_checked(sample_locator)
|
512
458
|
end
|
513
|
-
@test_case.assert_checked(sample_locator)
|
514
|
-
end
|
515
459
|
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
460
|
+
it "fails when not checked" do
|
461
|
+
stub(driver) do |o|
|
462
|
+
o.is_element_present(sample_locator) {true}
|
463
|
+
o.is_checked(sample_locator) {false}
|
464
|
+
end
|
465
|
+
proc do
|
466
|
+
test_case.assert_checked(sample_locator)
|
467
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
520
468
|
end
|
521
|
-
proc do
|
522
|
-
@test_case.assert_checked(sample_locator)
|
523
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
524
469
|
end
|
525
|
-
end
|
526
470
|
|
527
|
-
describe SeleniumTestCase, "#assert_not_checked" do
|
528
|
-
|
471
|
+
describe SeleniumTestCase, "#assert_not_checked" do
|
472
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
529
473
|
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
474
|
+
before do
|
475
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
476
|
+
mock.proxy(element).is_not_checked
|
477
|
+
element
|
478
|
+
end
|
534
479
|
end
|
535
|
-
end
|
536
480
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
481
|
+
it "passes when not checked" do
|
482
|
+
mock(driver) do |o|
|
483
|
+
o.is_element_present(sample_locator) {true}
|
484
|
+
o.is_checked(sample_locator) {false}
|
485
|
+
end
|
486
|
+
test_case.assert_not_checked(sample_locator)
|
541
487
|
end
|
542
|
-
@test_case.assert_not_checked(sample_locator)
|
543
|
-
end
|
544
488
|
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
489
|
+
it "fails when checked" do
|
490
|
+
stub(driver) do |o|
|
491
|
+
o.is_element_present(sample_locator) {true}
|
492
|
+
o.is_checked(sample_locator) {true}
|
493
|
+
end
|
494
|
+
proc do
|
495
|
+
test_case.assert_not_checked(sample_locator)
|
496
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
549
497
|
end
|
550
|
-
proc do
|
551
|
-
@test_case.assert_not_checked(sample_locator)
|
552
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
553
498
|
end
|
554
|
-
end
|
555
499
|
|
556
|
-
describe SeleniumTestCase, "#assert_text" do
|
557
|
-
|
500
|
+
describe SeleniumTestCase, "#assert_text" do
|
501
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
558
502
|
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
503
|
+
before do
|
504
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
505
|
+
mock.proxy(element).has_text("expected text", {})
|
506
|
+
element
|
507
|
+
end
|
563
508
|
end
|
564
|
-
end
|
565
509
|
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
510
|
+
it "passes when text is expected" do
|
511
|
+
mock(driver) do |o|
|
512
|
+
o.is_element_present(sample_locator) {true}
|
513
|
+
o.get_text(sample_locator) {"expected text"}
|
514
|
+
end
|
515
|
+
test_case.assert_text(sample_locator, "expected text")
|
570
516
|
end
|
571
|
-
@test_case.assert_text(sample_locator, "expected text")
|
572
|
-
end
|
573
517
|
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
518
|
+
it "fails when text is not expected" do
|
519
|
+
stub(driver) do |o|
|
520
|
+
o.is_element_present(sample_locator) {true}
|
521
|
+
o.get_text(sample_locator) {"unexpected text"}
|
522
|
+
end
|
523
|
+
proc do
|
524
|
+
test_case.assert_text(sample_locator, "expected text")
|
525
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
578
526
|
end
|
579
|
-
proc do
|
580
|
-
@test_case.assert_text(sample_locator, "expected text")
|
581
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
582
527
|
end
|
583
|
-
end
|
584
528
|
|
585
|
-
describe SeleniumTestCase, "#assert_visible" do
|
586
|
-
|
529
|
+
describe SeleniumTestCase, "#assert_visible" do
|
530
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
587
531
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
532
|
+
before do
|
533
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
534
|
+
mock.proxy(element).is_visible({})
|
535
|
+
element
|
536
|
+
end
|
592
537
|
end
|
593
|
-
end
|
594
538
|
|
595
|
-
|
596
|
-
|
597
|
-
|
539
|
+
it "passes when element is visible" do
|
540
|
+
mock(driver).is_element_present(sample_locator) {true}
|
541
|
+
mock(driver).is_visible(sample_locator) {true}
|
598
542
|
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
543
|
+
test_case.assert_visible(sample_locator)
|
544
|
+
end
|
545
|
+
|
546
|
+
it "fails when element is not visible" do
|
547
|
+
mock(driver).is_element_present(sample_locator) {true}
|
548
|
+
stub(driver).is_visible.returns {false}
|
605
549
|
|
606
|
-
|
607
|
-
|
608
|
-
|
550
|
+
proc {
|
551
|
+
test_case.assert_visible(sample_locator)
|
552
|
+
}.should raise_error(Test::Unit::AssertionFailedError)
|
553
|
+
end
|
609
554
|
end
|
610
|
-
end
|
611
555
|
|
612
|
-
describe SeleniumTestCase, "#assert_not_visible" do
|
613
|
-
|
556
|
+
describe SeleniumTestCase, "#assert_not_visible" do
|
557
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
614
558
|
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
559
|
+
before do
|
560
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
561
|
+
mock.proxy(element).is_not_visible({})
|
562
|
+
element
|
563
|
+
end
|
619
564
|
end
|
620
|
-
end
|
621
565
|
|
622
|
-
|
623
|
-
|
624
|
-
|
566
|
+
it "passes when element is present and is not visible" do
|
567
|
+
mock(driver).is_element_present(sample_locator) {true}
|
568
|
+
mock(driver).is_visible(sample_locator) {false}
|
625
569
|
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
570
|
+
test_case.assert_not_visible(sample_locator)
|
571
|
+
end
|
572
|
+
|
573
|
+
it "fails when element is visible" do
|
574
|
+
mock(driver).is_element_present(sample_locator) {true}
|
575
|
+
stub(driver).is_visible(sample_locator) {true}
|
632
576
|
|
633
|
-
|
634
|
-
|
635
|
-
|
577
|
+
proc {
|
578
|
+
test_case.assert_not_visible(sample_locator)
|
579
|
+
}.should raise_error(Test::Unit::AssertionFailedError)
|
580
|
+
end
|
636
581
|
end
|
637
|
-
end
|
638
582
|
|
639
|
-
describe SeleniumTestCase, "#assert_next_sibling" do
|
640
|
-
|
583
|
+
describe SeleniumTestCase, "#assert_next_sibling" do
|
584
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
641
585
|
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
586
|
+
before do
|
587
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator) do |element|
|
588
|
+
mock.proxy(element).has_next_sibling("next_sibling", {})
|
589
|
+
element
|
590
|
+
end
|
591
|
+
@evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
|
646
592
|
end
|
647
|
-
@evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
|
648
|
-
end
|
649
593
|
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
594
|
+
it "passes when passed next sibling id" do
|
595
|
+
mock(driver) do |o|
|
596
|
+
o.is_element_present(sample_locator) {true}
|
597
|
+
o.get_eval(@evaled_js) {"next_sibling"}
|
598
|
+
end
|
599
|
+
test_case.assert_next_sibling(sample_locator, "next_sibling")
|
654
600
|
end
|
655
|
-
@test_case.assert_next_sibling(sample_locator, "next_sibling")
|
656
|
-
end
|
657
601
|
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
602
|
+
it "fails when not passed next sibling id" do
|
603
|
+
stub(driver) do |o|
|
604
|
+
o.is_element_present(sample_locator) {true}
|
605
|
+
o.get_eval(@evaled_js) {"wrong_sibling"}
|
606
|
+
end
|
607
|
+
proc do
|
608
|
+
test_case.assert_next_sibling(sample_locator, "next_sibling")
|
609
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
662
610
|
end
|
663
|
-
proc do
|
664
|
-
@test_case.assert_next_sibling(sample_locator, "next_sibling")
|
665
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
666
611
|
end
|
667
|
-
end
|
668
612
|
|
669
|
-
describe SeleniumTestCase, "#assert_text_in_order" do
|
670
|
-
|
613
|
+
describe SeleniumTestCase, "#assert_text_in_order" do
|
614
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
671
615
|
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
616
|
+
before do
|
617
|
+
mock.proxy(SeleniumElement).new(driver, sample_locator)
|
618
|
+
@evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
|
619
|
+
end
|
676
620
|
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
621
|
+
it "passes when text is in order" do
|
622
|
+
mock(driver) do |o|
|
623
|
+
o.is_element_present(sample_locator) {true}
|
624
|
+
o.get_text(sample_locator) {"one\ntwo\nthree\n"}
|
625
|
+
end
|
626
|
+
test_case.assert_text_in_order sample_locator, "one", "two", "three"
|
681
627
|
end
|
682
|
-
@test_case.assert_text_in_order sample_locator, "one", "two", "three"
|
683
|
-
end
|
684
628
|
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
629
|
+
it "fails when element is present and text is not in order" do
|
630
|
+
stub(driver) do |o|
|
631
|
+
o.is_element_present(sample_locator) {true}
|
632
|
+
o.get_text(sample_locator) {"<html>one\ntext not in order\n</html>"}
|
633
|
+
end
|
634
|
+
proc do
|
635
|
+
test_case.assert_text_in_order sample_locator, "one", "two", "three"
|
636
|
+
end.should raise_error(Test::Unit::AssertionFailedError)
|
689
637
|
end
|
690
|
-
proc do
|
691
|
-
@test_case.assert_text_in_order sample_locator, "one", "two", "three"
|
692
|
-
end.should raise_error(Test::Unit::AssertionFailedError)
|
693
638
|
end
|
694
|
-
end
|
695
639
|
|
696
|
-
describe SeleniumTestCase, "#type" do
|
697
|
-
|
640
|
+
describe SeleniumTestCase, "#type" do
|
641
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
698
642
|
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
643
|
+
it "types when element is present and types" do
|
644
|
+
is_element_present_results = [false, true]
|
645
|
+
mock(driver).do_command("isElementPresent", ["id=foobar"]).twice do
|
646
|
+
result(is_element_present_results.shift)
|
647
|
+
end
|
648
|
+
mock(driver).do_command("type", ["id=foobar", "The Text"]) do
|
649
|
+
result()
|
650
|
+
end
|
703
651
|
|
704
|
-
|
705
|
-
|
652
|
+
test_case.type "id=foobar", "The Text"
|
653
|
+
end
|
706
654
|
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
655
|
+
it "fails when element is not present" do
|
656
|
+
mock(driver).do_command("isElementPresent", ["id=foobar"]).times(4) do
|
657
|
+
result(false)
|
658
|
+
end
|
659
|
+
dont_allow(driver).do_command("type", ["id=foobar", "The Text"])
|
712
660
|
|
713
|
-
|
714
|
-
|
715
|
-
|
661
|
+
proc {
|
662
|
+
test_case.type "id=foobar", "The Text"
|
663
|
+
}.should raise_error(Test::Unit::AssertionFailedError)
|
664
|
+
end
|
716
665
|
end
|
717
|
-
end
|
718
666
|
|
719
|
-
describe SeleniumTestCase, "#click" do
|
720
|
-
|
667
|
+
describe SeleniumTestCase, "#click" do
|
668
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
721
669
|
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
670
|
+
it "click when element is present and types" do
|
671
|
+
is_element_present_results = [false, true]
|
672
|
+
mock(driver).do_command("isElementPresent", ["id=foobar"]).twice do
|
673
|
+
result(is_element_present_results.shift)
|
674
|
+
end
|
675
|
+
mock(driver).do_command("click", ["id=foobar"]) {result}
|
726
676
|
|
727
|
-
|
728
|
-
|
677
|
+
test_case.click "id=foobar"
|
678
|
+
end
|
729
679
|
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
680
|
+
it "fails when element is not present" do
|
681
|
+
is_element_present_results = [false, false, false, false]
|
682
|
+
mock(driver).do_command("isElementPresent", ["id=foobar"]).times(4) do
|
683
|
+
result(is_element_present_results.shift)
|
684
|
+
end
|
685
|
+
dont_allow(driver).do_command("click", [])
|
735
686
|
|
736
|
-
|
737
|
-
|
738
|
-
|
687
|
+
proc {
|
688
|
+
test_case.click "id=foobar"
|
689
|
+
}.should raise_error(Test::Unit::AssertionFailedError)
|
690
|
+
end
|
739
691
|
end
|
740
|
-
end
|
741
692
|
|
742
|
-
describe SeleniumTestCase, "#select" do
|
743
|
-
|
693
|
+
describe SeleniumTestCase, "#select" do
|
694
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
744
695
|
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
696
|
+
it "types when element is present and types" do
|
697
|
+
is_element_present_results = [false, true]
|
698
|
+
mock(driver).do_command("isElementPresent", ["id=foobar"]).twice do
|
699
|
+
result is_element_present_results.shift
|
700
|
+
end
|
701
|
+
mock(driver).do_command("select", ["id=foobar", "value=3"]) {result}
|
749
702
|
|
750
|
-
|
751
|
-
|
703
|
+
test_case.select "id=foobar", "value=3"
|
704
|
+
end
|
752
705
|
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
706
|
+
it "fails when element is not present" do
|
707
|
+
mock(driver).do_command("isElementPresent", ["id=foobar"]).times(4) do
|
708
|
+
result false
|
709
|
+
end
|
710
|
+
dont_allow(driver).do_command("select", ["id=foobar", "value=3"])
|
758
711
|
|
759
|
-
|
760
|
-
|
761
|
-
|
712
|
+
proc {
|
713
|
+
test_case.select "id=foobar", "value=3"
|
714
|
+
}.should raise_error(Test::Unit::AssertionFailedError)
|
715
|
+
end
|
762
716
|
end
|
763
|
-
end
|
764
717
|
|
765
|
-
describe SeleniumTestCase, "#wait_for_and_click" do
|
766
|
-
|
718
|
+
describe SeleniumTestCase, "#wait_for_and_click" do
|
719
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
767
720
|
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
721
|
+
it "click when element is present and types" do
|
722
|
+
is_element_present_results = [false, true]
|
723
|
+
mock(driver).do_command("isElementPresent", ["id=foobar"]).twice do
|
724
|
+
result is_element_present_results.shift
|
725
|
+
end
|
726
|
+
mock(driver).do_command("click", ["id=foobar"]) {result}
|
772
727
|
|
773
|
-
|
774
|
-
|
728
|
+
test_case.wait_for_and_click "id=foobar"
|
729
|
+
end
|
775
730
|
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
731
|
+
it "fails when element is not present" do
|
732
|
+
is_element_present_results = [false, false, false, false]
|
733
|
+
mock(driver).is_element_present("id=foobar").times(4) do
|
734
|
+
is_element_present_results.shift
|
735
|
+
end
|
736
|
+
dont_allow(driver).click
|
781
737
|
|
782
|
-
|
783
|
-
|
784
|
-
|
738
|
+
proc {
|
739
|
+
test_case.wait_for_and_click "id=foobar"
|
740
|
+
}.should raise_error(Test::Unit::AssertionFailedError)
|
741
|
+
end
|
785
742
|
end
|
786
|
-
end
|
787
743
|
|
788
|
-
describe SeleniumTestCase, "#page" do
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
744
|
+
describe SeleniumTestCase, "#page" do
|
745
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
746
|
+
|
747
|
+
it "returns page" do
|
748
|
+
test_case.page.should == SeleniumPage.new(driver)
|
749
|
+
end
|
793
750
|
end
|
794
|
-
end
|
795
751
|
|
796
|
-
describe "SeleniumTestCase in test browser mode and test fails" do
|
797
|
-
|
752
|
+
describe "SeleniumTestCase in test browser mode and test fails" do
|
753
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
798
754
|
|
799
|
-
|
800
|
-
|
801
|
-
|
755
|
+
it "should stop driver when configuration says to stop test" do
|
756
|
+
test_case.configuration = configuration = Seleniumrc::SeleniumConfiguration.new
|
757
|
+
configuration.test_browser_mode
|
802
758
|
|
803
|
-
|
804
|
-
|
759
|
+
stub(test_case).passed? {false}
|
760
|
+
configuration.keep_browser_open_on_failure = false
|
805
761
|
|
806
|
-
|
807
|
-
|
762
|
+
mock(driver).stop.once
|
763
|
+
test_case.selenium_driver = driver
|
808
764
|
|
809
|
-
|
810
|
-
|
765
|
+
test_case.teardown
|
766
|
+
end
|
811
767
|
|
812
|
-
|
813
|
-
|
814
|
-
|
768
|
+
it "should not stop driver when configuration says not to stop test" do
|
769
|
+
test_case.configuration = "Seleniumrc::SeleniumConfiguration"
|
770
|
+
mock(test_case.configuration).test_browser_mode?.returns(true)
|
815
771
|
|
816
|
-
|
817
|
-
|
772
|
+
stub(test_case).passed? {false}
|
773
|
+
mock(test_case.configuration).stop_driver?(false) {false}
|
818
774
|
|
819
|
-
|
775
|
+
test_case.selenium_driver = driver
|
820
776
|
|
821
|
-
|
777
|
+
test_case.teardown
|
778
|
+
end
|
822
779
|
end
|
823
|
-
end
|
824
780
|
|
825
|
-
describe "SeleniumTestCase in test browser mode and test pass" do
|
826
|
-
|
781
|
+
describe "SeleniumTestCase in test browser mode and test pass" do
|
782
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
827
783
|
|
828
|
-
|
829
|
-
|
830
|
-
|
784
|
+
it "should stop driver when configuration says to stop test" do
|
785
|
+
test_case.configuration = "Seleniumrc::SeleniumConfiguration"
|
786
|
+
mock(test_case.configuration).test_browser_mode?.returns(true)
|
831
787
|
|
832
|
-
|
833
|
-
|
788
|
+
stub(test_case).passed?.returns(true)
|
789
|
+
mock(test_case.configuration).stop_driver?(true) {true}
|
834
790
|
|
835
|
-
|
836
|
-
|
791
|
+
mock(driver).stop.once
|
792
|
+
test_case.selenium_driver = driver
|
837
793
|
|
838
|
-
|
839
|
-
|
794
|
+
test_case.teardown
|
795
|
+
end
|
840
796
|
|
841
|
-
|
842
|
-
|
843
|
-
|
797
|
+
it "should not stop driver when configuration says not to stop test" do
|
798
|
+
test_case.configuration = "Seleniumrc::SeleniumConfiguration"
|
799
|
+
mock(test_case.configuration).test_browser_mode?.returns(true)
|
844
800
|
|
845
|
-
|
846
|
-
|
801
|
+
stub(test_case).passed?.returns(true)
|
802
|
+
mock(test_case.configuration).stop_driver?(true) {false}
|
847
803
|
|
848
|
-
|
804
|
+
test_case.selenium_driver = driver
|
849
805
|
|
850
|
-
|
806
|
+
test_case.teardown
|
807
|
+
end
|
851
808
|
end
|
852
|
-
end
|
853
809
|
|
854
|
-
describe "SeleniumTestCase not in suite browser mode" do
|
855
|
-
|
810
|
+
describe "SeleniumTestCase not in suite browser mode" do
|
811
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
856
812
|
|
857
|
-
|
858
|
-
|
859
|
-
|
813
|
+
it "should not stop driver when tests fail" do
|
814
|
+
test_case.configuration = "Seleniumrc::SeleniumConfiguration"
|
815
|
+
mock(test_case.configuration).test_browser_mode? {false}
|
860
816
|
|
861
|
-
|
817
|
+
def test_case.passed?;
|
818
|
+
false;
|
819
|
+
end
|
862
820
|
|
863
|
-
|
821
|
+
test_case.selenium_driver = driver
|
864
822
|
|
865
|
-
|
866
|
-
|
823
|
+
test_case.teardown
|
824
|
+
end
|
867
825
|
|
868
|
-
|
869
|
-
|
870
|
-
|
826
|
+
it "should stop driver when tests pass" do
|
827
|
+
test_case.configuration = "Seleniumrc::SeleniumConfiguration"
|
828
|
+
mock(test_case.configuration).test_browser_mode? {false}
|
871
829
|
|
872
|
-
|
830
|
+
stub(test_case).passed?.returns(true)
|
873
831
|
|
874
|
-
|
832
|
+
test_case.selenium_driver = driver
|
875
833
|
|
876
|
-
|
877
|
-
|
878
|
-
end
|
834
|
+
test_case.teardown
|
835
|
+
end
|
836
|
+
end
|
879
837
|
|
880
|
-
describe "SeleniumTestCase in test browser mode and test pass" do
|
881
|
-
|
838
|
+
describe "SeleniumTestCase in test browser mode and test pass" do
|
839
|
+
it_should_behave_like "Seleniumrc::SeleniumTestCase"
|
882
840
|
|
883
|
-
|
884
|
-
|
885
|
-
|
841
|
+
it "should stop driver when configuration says to stop test" do
|
842
|
+
test_case.configuration = "Seleniumrc::SeleniumConfiguration"
|
843
|
+
mock(test_case.configuration).test_browser_mode?.returns(true)
|
886
844
|
|
887
|
-
|
888
|
-
|
845
|
+
stub(test_case).passed?.returns(true)
|
846
|
+
mock(test_case.configuration).stop_driver?(true) {true}
|
889
847
|
|
890
|
-
|
891
|
-
|
848
|
+
mock(driver).stop.once
|
849
|
+
test_case.selenium_driver = driver
|
892
850
|
|
893
|
-
|
894
|
-
|
851
|
+
test_case.teardown
|
852
|
+
end
|
895
853
|
|
896
|
-
|
897
|
-
|
898
|
-
|
854
|
+
it "should not stop driver when configuration says not to stop test" do
|
855
|
+
test_case.configuration = "Seleniumrc::SeleniumConfiguration"
|
856
|
+
mock(test_case.configuration).test_browser_mode? {true}
|
899
857
|
|
900
|
-
|
901
|
-
|
858
|
+
stub(test_case).passed?.returns(true)
|
859
|
+
mock(test_case.configuration).stop_driver?(true) {false}
|
902
860
|
|
903
|
-
|
861
|
+
test_case.selenium_driver = driver
|
904
862
|
|
905
|
-
|
863
|
+
test_case.teardown
|
864
|
+
end
|
906
865
|
end
|
907
866
|
end
|
908
|
-
end
|