seleniumrc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/CHANGES +2 -0
  2. data/README +0 -0
  3. data/Rakefile +68 -0
  4. data/lib/seleniumrc/app_server_checker.rb +43 -0
  5. data/lib/seleniumrc/dsl/selenium_dsl.rb +186 -0
  6. data/lib/seleniumrc/dsl/test_unit_dsl.rb +95 -0
  7. data/lib/seleniumrc/extensions/selenium_driver.rb +33 -0
  8. data/lib/seleniumrc/extensions/testrunnermediator.rb +19 -0
  9. data/lib/seleniumrc/mongrel_selenium_server_runner.rb +35 -0
  10. data/lib/seleniumrc/selenium_configuration.rb +78 -0
  11. data/lib/seleniumrc/selenium_context.rb +226 -0
  12. data/lib/seleniumrc/selenium_element.rb +195 -0
  13. data/lib/seleniumrc/selenium_helper.rb +5 -0
  14. data/lib/seleniumrc/selenium_page.rb +76 -0
  15. data/lib/seleniumrc/selenium_server_runner.rb +33 -0
  16. data/lib/seleniumrc/selenium_test_case.rb +95 -0
  17. data/lib/seleniumrc/tasks/selenium_test_task.rb +21 -0
  18. data/lib/seleniumrc/wait_for.rb +47 -0
  19. data/lib/seleniumrc/webrick_selenium_server_runner.rb +33 -0
  20. data/lib/seleniumrc.rb +28 -0
  21. data/spec/seleniumrc/app_server_checker_spec.rb +56 -0
  22. data/spec/seleniumrc/mongrel_selenium_server_runner_spec.rb +42 -0
  23. data/spec/seleniumrc/selenese_interpreter_spec.rb +25 -0
  24. data/spec/seleniumrc/selenium_configuration_spec.rb +21 -0
  25. data/spec/seleniumrc/selenium_context_spec.rb +362 -0
  26. data/spec/seleniumrc/selenium_element_spec.rb +530 -0
  27. data/spec/seleniumrc/selenium_page_spec.rb +226 -0
  28. data/spec/seleniumrc/selenium_server_runner_spec.rb +42 -0
  29. data/spec/seleniumrc/selenium_test_case_class_method_spec.rb +41 -0
  30. data/spec/seleniumrc/selenium_test_case_spec.rb +908 -0
  31. data/spec/seleniumrc/selenium_test_case_spec_helper.rb +23 -0
  32. data/spec/seleniumrc/webrick_selenium_server_runner_spec.rb +116 -0
  33. data/spec/spec_helper.rb +57 -0
  34. data/spec/spec_suite.rb +4 -0
  35. metadata +83 -0
@@ -0,0 +1,226 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ module Seleniumrc
4
+ describe SeleniumPage, :shared => true do
5
+ include SeleniumTestCaseSpec
6
+
7
+ before do
8
+ @selenium = "Selenium"
9
+ @page = SeleniumPage.new(@selenium)
10
+ page_loaded
11
+ end
12
+
13
+ def page_loaded
14
+ stub(@selenium).get_eval(SeleniumPage::PAGE_LOADED_COMMAND) {"true"}
15
+ end
16
+
17
+ def page_not_loaded
18
+ stub(@selenium).get_eval(SeleniumPage::PAGE_LOADED_COMMAND) {"false"}
19
+ end
20
+ end
21
+
22
+ describe SeleniumPage, "#initialize" do
23
+ it_should_behave_like "Seleniumrc::SeleniumPage"
24
+
25
+ it "sets the selenium object" do
26
+ @page.selenium.should == @selenium
27
+ end
28
+ end
29
+
30
+ describe SeleniumPage, "#open_and_wait" do
31
+ it_should_behave_like "Seleniumrc::SeleniumPage"
32
+
33
+ it "opens the url and waits for the page to load" do
34
+ mock(@selenium) do |o|
35
+ o.open("/users/list")
36
+ o.wait_for_page_to_load(@page.default_timeout)
37
+ o.get_title {"Users in the project"}
38
+ end
39
+ @page.open_and_wait("/users/list")
40
+ end
41
+
42
+ it "fails when titles contains Exception caught" do
43
+ mock(@selenium) do |o|
44
+ o.open("/users/list")
45
+ o.wait_for_page_to_load(@page.default_timeout)
46
+ o.get_title {"Exception caught"}
47
+ end
48
+ proc do
49
+ @page.open_and_wait("/users/list")
50
+ end.should raise_error
51
+ end
52
+ end
53
+
54
+ describe SeleniumPage, "#has_title" do
55
+ it_should_behave_like "Seleniumrc::SeleniumPage"
56
+
57
+ it "passes when title is expected" do
58
+ ticks = ["no page", "no page", "no page", "my page"]
59
+ mock(@selenium).get_title do
60
+ ticks.shift
61
+ end.times(4)
62
+ @page.has_title("my page")
63
+ end
64
+
65
+ it "fails when element is not present" do
66
+ stub(@selenium).get_title {"no page"}
67
+ proc do
68
+ @page.has_title("my page")
69
+ end.should raise_error("Expected title 'my page' but was 'no page' (after 5 sec)")
70
+ end
71
+ end
72
+
73
+ describe SeleniumPage, "#has_title?" do
74
+ it_should_behave_like "Seleniumrc::SeleniumPage"
75
+
76
+ it "returns true when passed in title is the page title" do
77
+ mock(@selenium).get_title {"my page"}
78
+ @page.has_title?("my page").should be_true
79
+ end
80
+
81
+ it "returns false when passed in title is not the page title" do
82
+ mock(@selenium).get_title {"no page"}
83
+ @page.has_title?("my page").should be_false
84
+ end
85
+ end
86
+
87
+ describe SeleniumPage, "#is_text_present" do
88
+ it_should_behave_like "Seleniumrc::SeleniumPage"
89
+
90
+ it "passes when title is expected" do
91
+ ticks = [false, false, false, true]
92
+ mock(@selenium).is_text_present("my page") do
93
+ ticks.shift
94
+ end.times(4)
95
+ @page.is_text_present("my page")
96
+ end
97
+
98
+ it "fails when page is not loaded" do
99
+ page_not_loaded
100
+ proc do
101
+ @page.is_text_present("my page")
102
+ end.should raise_error("Expected 'my page' to be present, but it wasn't (after 5 sec)")
103
+ end
104
+
105
+ it "fails when element is not present" do
106
+ stub(@selenium).is_text_present("my page") {false}
107
+ proc do
108
+ @page.is_text_present("my page")
109
+ end.should raise_error("Expected 'my page' to be present, but it wasn't (after 5 sec)")
110
+ end
111
+ end
112
+
113
+ describe SeleniumPage, "#is_text_present?" do
114
+ it_should_behave_like "Seleniumrc::SeleniumPage"
115
+
116
+ it "returns true when title is expected" do
117
+ mock(@selenium).is_text_present("my page") {true}
118
+ @page.is_text_present?("my page").should be_true
119
+ end
120
+
121
+ it "fails when element is not present" do
122
+ mock(@selenium).is_text_present("my page") {false}
123
+ @page.is_text_present?("my page").should be_false
124
+ end
125
+ end
126
+
127
+ describe SeleniumPage, "#is_text_not_present" do
128
+ it_should_behave_like "Seleniumrc::SeleniumPage"
129
+
130
+ it "passes when text is not present" do
131
+ ticks = [true, true, true, false]
132
+ mock(@selenium).is_text_present("my page") do
133
+ ticks.shift
134
+ end.times(4)
135
+ @page.is_text_not_present("my page")
136
+ end
137
+
138
+ it "fails when page not loaded" do
139
+ page_not_loaded
140
+ proc do
141
+ @page.is_text_not_present("my page")
142
+ end.should raise_error("Expected 'my page' to be absent, but it wasn't (after 5 sec)")
143
+ end
144
+
145
+ it "fails when text is present" do
146
+ stub(@selenium).is_text_present("my page") {true}
147
+ proc do
148
+ @page.is_text_not_present("my page")
149
+ end.should raise_error("Expected 'my page' to be absent, but it wasn't (after 5 sec)")
150
+ end
151
+ end
152
+
153
+ describe SeleniumPage, "#is_text_not_present?" do
154
+ it_should_behave_like "Seleniumrc::SeleniumPage"
155
+
156
+ it "returns true when text is not present" do
157
+ mock(@selenium).is_text_present("my page") {false}
158
+ @page.is_text_not_present?("my page").should be_true
159
+ end
160
+
161
+ it "returns false when text is present" do
162
+ mock(@selenium).is_text_present("my page") {true}
163
+ @page.is_text_not_present?("my page").should be_false
164
+ end
165
+ end
166
+
167
+ describe SeleniumPage, "#url_ends_with" do
168
+ it_should_behave_like "Seleniumrc::SeleniumPage"
169
+
170
+ before do
171
+ @ends_with = "foobar.com?arg1=2"
172
+ end
173
+
174
+ it "passes when title is expected" do
175
+ ticks = [
176
+ "http://no.com",
177
+ "http://no.com",
178
+ "http://no.com",
179
+ "http://foobar.com?arg1=2"
180
+ ]
181
+ mock(@selenium).get_location do
182
+ ticks.shift
183
+ end.times(4)
184
+ @page.url_ends_with(@ends_with)
185
+ end
186
+
187
+ it "fails when element is not present" do
188
+ stub(@selenium).get_location {"http://no.com"}
189
+ proc do
190
+ @page.url_ends_with(@ends_with)
191
+ end.should raise_error("Expected 'http://no.com' to end with '#{@ends_with}' (after 5 sec)")
192
+ end
193
+ end
194
+
195
+ describe SeleniumPage, "#url_ends_with?" do
196
+ it_should_behave_like "Seleniumrc::SeleniumPage"
197
+
198
+ before do
199
+ @ends_with = "foobar.com?arg1=2"
200
+ end
201
+
202
+ it "passes when title is expected" do
203
+ mock(@selenium).get_location {"http://foobar.com?arg1=2"}
204
+ @page.url_ends_with?(@ends_with).should be_true
205
+ end
206
+
207
+ it "fails when element is not present" do
208
+ mock(@selenium).get_location {"http://no.com"}
209
+ @page.url_ends_with?(@ends_with).should be_false
210
+ end
211
+ end
212
+
213
+ describe SeleniumPage, "#page_loaded?" do
214
+ it_should_behave_like "Seleniumrc::SeleniumPage"
215
+
216
+ it "when page loaded command returns 'true', returns true" do
217
+ page_loaded
218
+ @page.should be_page_loaded
219
+ end
220
+
221
+ it "when page loaded command returns 'false', returns false" do
222
+ page_not_loaded
223
+ @page.should_not be_page_loaded
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ module Seleniumrc
4
+ describe SeleniumServerRunner do
5
+ before(:each) do
6
+ @runner = Seleniumrc::SeleniumServerRunner.new
7
+ class << @runner
8
+ public :start_server, :stop_server
9
+ end
10
+ end
11
+
12
+ it "should initialize started? to be false" do
13
+ @runner.started?.should == false
14
+ end
15
+
16
+ it "start method should start new thread and set started" do
17
+ start_server_called = false
18
+ (class << @runner; self; end).class_eval do
19
+ define_method :start_server do; start_server_called = true; end
20
+ end
21
+ def @runner.stop_server; end
22
+ mock_thread_class = "mock_thread_class"
23
+ mock(mock_thread_class).start {|block| block.call}
24
+ @runner.thread_class = mock_thread_class
25
+
26
+ @runner.start
27
+ start_server_called.should equal(true)
28
+ @runner.started?.should equal(true)
29
+ end
30
+
31
+ it "stop method should set started? to false" do
32
+ def @runner.stop_server; end
33
+ @runner.instance_eval {@started = true}
34
+ @runner.stop
35
+ @runner.started?.should == false
36
+ end
37
+
38
+ it "start_server method should raise a NotImplementedError by default" do
39
+ proc {@runner.start_server}.should raise_error(NotImplementedError)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ module Seleniumrc
4
+ describe SeleniumTestCase, "Class methods" do
5
+ include SeleniumTestCaseSpec
6
+ it "should maintain a subclass array" do
7
+ test_class = Class.new
8
+ test_class.extend Seleniumrc::SeleniumTestCase::ClassMethods
9
+
10
+ subclass1 = Class.new(test_class)
11
+ subclass2 = Class.new(test_class)
12
+
13
+ test_class.subclasses.should == [subclass1, subclass2]
14
+ end
15
+
16
+ it "should not use transactional fixtures by default" do
17
+ Seleniumrc::SeleniumTestCase.use_transactional_fixtures.should == false
18
+ end
19
+
20
+ it "should use instantiated fixtures by default" do
21
+ Seleniumrc::SeleniumTestCase.use_instantiated_fixtures.should == true
22
+ end
23
+
24
+ class Parent < Seleniumrc::SeleniumTestCase
25
+ end
26
+ class Child1 < Parent
27
+ end
28
+ class Child2 < Parent
29
+ end
30
+ class Grandchild1 < Child1
31
+ end
32
+ class Grandchild2 < Child2
33
+ end
34
+ class Grandchild3 < Child2
35
+ end
36
+
37
+ it "should recursively gather all subclasses" do
38
+ Parent.all_descendant_classes.should == ([Child1, Grandchild1, Child2, Grandchild2, Grandchild3])
39
+ end
40
+ end
41
+ end