terminus_spec 0.5.0

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.
Files changed (64) hide show
  1. data/.gitignore +26 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +2 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +7 -0
  6. data/HISTORY.md +54 -0
  7. data/LICENSE +20 -0
  8. data/README.md +13 -0
  9. data/Rakefile +43 -0
  10. data/cucumber.yml +6 -0
  11. data/lib/terminus_spec.rb +200 -0
  12. data/lib/terminus_spec/factory.rb +27 -0
  13. data/lib/terminus_spec/generators.rb +80 -0
  14. data/lib/terminus_spec/locators.rb +23 -0
  15. data/lib/terminus_spec/logger.rb +7 -0
  16. data/lib/terminus_spec/matchers.rb +41 -0
  17. data/lib/terminus_spec/platform_selenium.rb +18 -0
  18. data/lib/terminus_spec/platform_selenium/platform_object.rb +214 -0
  19. data/lib/terminus_spec/platform_selenium/web_objects/all.rb +98 -0
  20. data/lib/terminus_spec/platform_selenium/web_objects/button.rb +13 -0
  21. data/lib/terminus_spec/platform_selenium/web_objects/link.rb +13 -0
  22. data/lib/terminus_spec/platform_selenium/web_objects/text_field.rb +14 -0
  23. data/lib/terminus_spec/platform_watir.rb +18 -0
  24. data/lib/terminus_spec/platform_watir/platform_object.rb +190 -0
  25. data/lib/terminus_spec/platform_watir/web_objects/all.rb +88 -0
  26. data/lib/terminus_spec/platform_watir/web_objects/text_field.rb +13 -0
  27. data/lib/terminus_spec/platforms.rb +25 -0
  28. data/lib/terminus_spec/version.rb +3 -0
  29. data/lib/terminus_spec/web_objects/all.rb +172 -0
  30. data/lib/terminus_spec/web_objects/button.rb +32 -0
  31. data/lib/terminus_spec/web_objects/link.rb +40 -0
  32. data/lib/terminus_spec/web_objects/text_field.rb +45 -0
  33. data/spec/spec_helper.rb +37 -0
  34. data/spec/terminus_spec/factory_spec.rb +40 -0
  35. data/spec/terminus_spec/generators_spec.rb +179 -0
  36. data/spec/terminus_spec/locators_spec.rb +30 -0
  37. data/spec/terminus_spec/platform_selenium_spec.rb +28 -0
  38. data/spec/terminus_spec/platform_watir_spec.rb +32 -0
  39. data/spec/terminus_spec/platforms_spec.rb +43 -0
  40. data/spec/terminus_spec/terminus_spec.rb +271 -0
  41. data/spec/terminus_spec/web_objects/all_spec.rb +87 -0
  42. data/spec/terminus_spec/web_objects/button_spec.rb +35 -0
  43. data/spec/terminus_spec/web_objects/link_spec.rb +46 -0
  44. data/spec/terminus_spec/web_objects/text_field_spec.rb +48 -0
  45. data/spec/terminus_spec/webobject_selenium_spec.rb +154 -0
  46. data/spec/terminus_spec/webobject_watir_spec.rb +120 -0
  47. data/specs/app/favicon.ico +0 -0
  48. data/specs/app/images/mass_extinction.jpg +0 -0
  49. data/specs/app/index.html +20 -0
  50. data/specs/app/modal_1.html +41 -0
  51. data/specs/app/modal_2.html +29 -0
  52. data/specs/app/server.rb +25 -0
  53. data/specs/app/style.css +18 -0
  54. data/specs/app/success_1.html +12 -0
  55. data/specs/app/success_2.html +12 -0
  56. data/specs/app/test_event.html +39 -0
  57. data/specs/app/test_form.html +114 -0
  58. data/specs/app/test_frame.html +15 -0
  59. data/specs/app/test_iframe.html +15 -0
  60. data/specs/app/test_static.html +92 -0
  61. data/specs/engine/borg.rb +27 -0
  62. data/specs/engine/hooks.rb +23 -0
  63. data/terminus_spec.gemspec +31 -0
  64. metadata +198 -0
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ class TestPageForLoading
4
+ include TerminusSpec::Platforms
5
+ end
6
+
7
+ describe TestPageForLoading do
8
+ let(:platform) { TestPageForLoading.new() }
9
+ let(:drivers) { {} }
10
+
11
+ context "if a chrome browser is associated with a chrome platform" do
12
+ let(:chrome_browser) { double('browser') }
13
+ before { drivers[:chrome_browser] = mock_driver(chrome_browser, :chrome_platform) }
14
+
15
+ it "then the chrome platform will be established for the chrome browser" do
16
+ platform.platform_for(chrome_browser, drivers).should == :chrome_platform
17
+ end
18
+
19
+ context "if a firefox browser is associated with a firefox platform" do
20
+ let(:firefox_browser) { double('browser') }
21
+ before { drivers[:firefox_browser] = mock_driver(firefox_browser, :firefox_platform) }
22
+
23
+ it "then the chrome platform will still be established for the chrome browser" do
24
+ platform.platform_for(chrome_browser, drivers).should == :chrome_platform
25
+ end
26
+ end
27
+ end
28
+
29
+ context "if a firefox browser is associated with a firefox platform" do
30
+ let(:firefox_browser) { double('browser') }
31
+ before { drivers[:firefox_browser] = mock_driver(firefox_browser, :firefox_platform) }
32
+
33
+ it "then the firefox platform will be established for the firefox browser" do
34
+ platform.platform_for(firefox_browser, drivers).should == :firefox_platform
35
+ end
36
+ end
37
+
38
+ context "if an unknown browser object is associated with a platform" do
39
+ it "it should raise an exception" do
40
+ expect { platform.platform_for("false_browser") }.to raise_error
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,271 @@
1
+ require 'spec_helper'
2
+
3
+ class PageTester
4
+ include TerminusSpec
5
+ end
6
+
7
+ class PlatformObject
8
+ end
9
+
10
+ describe TerminusSpec do
11
+ let(:watir_browser) { mock_browser_with_watir }
12
+ let(:watir_page) { PageTester.new(watir_browser) }
13
+ let(:selenium_browser) { mock_browser_with_selenium }
14
+ let(:selenium_page) { PageTester.new(selenium_browser) }
15
+
16
+ context "is included with a page using watir-webdriver" do
17
+ it "so it should use a watir platform object" do
18
+ watir_page.platform.should be_kind_of TerminusSpec::Platforms::WatirWebDriver::PlatformObject
19
+ end
20
+ end
21
+
22
+ context "is included with a page using selenium-webdriver" do
23
+ it "so it should use a selenium platform object" do
24
+ selenium_page.platform.should be_kind_of TerminusSpec::Platforms::SeleniumWebDriver::PlatformObject
25
+ end
26
+ end
27
+
28
+ context "is included with page using an unrecognized browser" do
29
+ it "so it should raise an exception" do
30
+ expect { PageTester.new("false_browser") }.to raise_error
31
+ end
32
+ end
33
+
34
+ context "is included with a page using an unassociated custom driver" do
35
+ let(:custom_driver) { mock_driver(:custom_browser, PlatformObject) }
36
+ it "so it should raise an exception" do
37
+ expect { custom_page = PageTester.new(:custom_browser) }.to raise_error
38
+ end
39
+ end
40
+
41
+ context "is included with a page using an associated custom driver" do
42
+ let(:custom_driver) { mock_driver(:custom_browser, PlatformObject) }
43
+ it "so it should use a custom platform object" do
44
+ mock_drivers_list({:custom_driver => custom_driver})
45
+ custom_page = PageTester.new(:custom_browser)
46
+ custom_page.platform.should be custom_driver.create_platform_object_for
47
+ end
48
+ end
49
+
50
+ describe "(in terms of browser-level page functionality)" do
51
+ context "when using any platform" do
52
+ it "an individual page can provide its own setup logic" do
53
+ class TestPage
54
+ include TerminusSpec
55
+
56
+ def setup_page
57
+ @setup_page = true
58
+ end
59
+ end
60
+
61
+ @page = TestPage.new(watir_browser)
62
+ @page.setup_page.should be_true
63
+ end
64
+
65
+ it "a window will get two tries to be attached to" do
66
+ watir_page.platform.should_receive(:attach_to_window).once.and_throw "exception"
67
+ watir_page.platform.should_receive(:attach_to_window)
68
+ watir_page.attach_to_window("contentPane")
69
+ end
70
+ end
71
+
72
+ context "when using the watir platform" do
73
+ it "a page can be navigated to" do
74
+ watir_browser.should_receive(:goto).with("testerstories.com")
75
+ watir_page.navigate_to("testerstories.com")
76
+ end
77
+
78
+ it "the title of the page is accessible" do
79
+ watir_browser.should_receive(:title).and_return("Page Title")
80
+ watir_page.title.should == "Page Title"
81
+ end
82
+
83
+ it "the text of the page is accessible" do
84
+ watir_browser.should_receive(:text).and_return("page text")
85
+ watir_page.text.should == "page text"
86
+ end
87
+
88
+ it "the markup of the page is accessible" do
89
+ watir_browser.should_receive(:html).and_return("<html>HTML page text</html>")
90
+ watir_page.html.should == "<html>HTML page text</html>"
91
+ end
92
+
93
+ it "the current web address of the page is accessible" do
94
+ watir_browser.should_receive(:url).and_return("http://testerstories.com/?p=355")
95
+ watir_page.current_url.should == "http://testerstories.com/?p=355"
96
+ end
97
+
98
+ it "the current page can be refreshed" do
99
+ watir_browser.should_receive(:refresh)
100
+ watir_page.refresh
101
+ end
102
+
103
+ it "the preceding page in history can be navigated to" do
104
+ watir_browser.should_receive(:back)
105
+ watir_page.back
106
+ end
107
+
108
+ it "the succeeding page in history can be navigated to" do
109
+ watir_browser.should_receive(:forward)
110
+ watir_page.forward
111
+ end
112
+
113
+ it "the browser cookies can be cleared" do
114
+ watir_browser.should_receive(:clear_cookies)
115
+ watir_page.clear_cookies
116
+ end
117
+
118
+ it "the current page can be captured in a screenshot" do
119
+ watir_browser.should_receive(:wd).and_return(watir_browser)
120
+ watir_browser.should_receive(:save_screenshot)
121
+ watir_page.save_screenshot("testing.png")
122
+ end
123
+
124
+ it "a condition on the page can be waited for" do
125
+ watir_browser.should_receive(:wait_until).with(5, "Timeout")
126
+ watir_page.wait_until(5, "Timeout")
127
+ end
128
+
129
+ it "alert popup message boxes can be handled" do
130
+ watir_browser.should_receive(:wd).twice.and_return(watir_browser)
131
+ watir_browser.should_receive(:execute_script).twice
132
+ watir_page.will_alert do
133
+ end
134
+ end
135
+
136
+ it "confirm popup message boxes can be handled" do
137
+ watir_browser.should_receive(:wd).twice.and_return(watir_browser)
138
+ watir_browser.should_receive(:execute_script).twice
139
+ watir_page.will_confirm(true) do
140
+ end
141
+ end
142
+
143
+ it "prompt popup message boxes can be handled" do
144
+ watir_browser.should_receive(:wd).twice.and_return(watir_browser)
145
+ watir_browser.should_receive(:execute_script).twice
146
+ watir_page.will_prompt("Question") do
147
+ end
148
+ end
149
+
150
+ it "a window can be attached to by using the title" do
151
+ watir_browser.should_receive(:window).with(:title => /Display\ Results/).and_return(watir_browser)
152
+ watir_browser.should_receive(:use)
153
+ watir_page.attach_to_window(:title => "Display Results")
154
+ end
155
+
156
+ it "a window can be attached to by using the url" do
157
+ watir_browser.should_receive(:window).with(:url => /results\.html/).and_return(watir_browser)
158
+ watir_browser.should_receive(:use)
159
+ watir_page.attach_to_window(:url => "results.html")
160
+ end
161
+
162
+ it "a modal dialog can be treated as a window" do
163
+ watir_browser.should_receive(:execute_script)
164
+ watir_page.will_be_modal {}
165
+ end
166
+ end
167
+
168
+ context "when using the selenium platform" do
169
+ it "a page can be navigated to" do
170
+ selenium_browser.stub_chain(:navigate, :to).with("testerstories.com")
171
+ selenium_page.navigate_to("testerstories.com")
172
+ end
173
+
174
+ it "the title of the page is accessible" do
175
+ selenium_browser.should_receive(:title).and_return("Page Title")
176
+ selenium_page.title.should == "Page Title"
177
+ end
178
+
179
+ it "the text of the page is accessible" do
180
+ selenium_browser.stub_chain(:find_element, :text).and_return("page text")
181
+ selenium_page.text.should == "page text"
182
+ end
183
+
184
+ it "the markup of the page is accessible" do
185
+ selenium_browser.should_receive(:page_source).and_return("<html>HTML page text</html>")
186
+ selenium_page.html.should == "<html>HTML page text</html>"
187
+ end
188
+
189
+ it "the current web address of the page is accessible" do
190
+ selenium_browser.should_receive(:current_url).and_return("http://testerstories.com/?p=355")
191
+ selenium_page.current_url.should == "http://testerstories.com/?p=355"
192
+ end
193
+
194
+ it "the current page can be refreshed" do
195
+ selenium_browser.should_receive(:navigate).and_return(selenium_browser)
196
+ selenium_browser.should_receive(:refresh)
197
+ selenium_page.refresh
198
+ end
199
+
200
+ it "the preceding page in history can be navigated to" do
201
+ selenium_browser.should_receive(:navigate).and_return(selenium_browser)
202
+ selenium_browser.should_receive(:back)
203
+ selenium_page.back
204
+ end
205
+
206
+ it "the succeeding page in history can be navigated to" do
207
+ selenium_browser.should_receive(:navigate).and_return(selenium_browser)
208
+ selenium_browser.should_receive(:forward)
209
+ selenium_page.forward
210
+ end
211
+
212
+ it "the browser cookies can be cleared" do
213
+ selenium_browser.should_receive(:manage).and_return(selenium_browser)
214
+ selenium_browser.should_receive(:delete_all_cookies)
215
+ selenium_page.clear_cookies
216
+ end
217
+
218
+ it "the current page can be captured in a screenshot" do
219
+ selenium_browser.should_receive(:save_screenshot)
220
+ selenium_page.save_screenshot("testing.png")
221
+ end
222
+
223
+ it "a condition on the page can be waited for" do
224
+ wait = double('wait')
225
+ Selenium::WebDriver::Wait.should_receive(:new).with({:timeout=>5, :message=>'Timeout'}).and_return(wait)
226
+ wait.should_receive(:until)
227
+ selenium_page.wait_until(5, 'Timeout')
228
+ end
229
+
230
+ it "alert popup message boxes can be handled" do
231
+ selenium_browser.should_receive(:execute_script).twice
232
+ selenium_page.will_alert do
233
+ end
234
+ end
235
+
236
+ it "confirm popup message boxes can be handled" do
237
+ selenium_browser.should_receive(:execute_script).twice
238
+ selenium_page.will_confirm(true) do
239
+ end
240
+ end
241
+
242
+ it "prompt popup message boxes can be handled" do
243
+ selenium_browser.should_receive(:execute_script).twice
244
+ selenium_page.will_prompt("Question") do
245
+ end
246
+ end
247
+
248
+ it "a window can be attached to by using the title" do
249
+ selenium_browser.should_receive(:window_handles).and_return(["result"])
250
+ selenium_browser.should_receive(:switch_to).twice.and_return(selenium_browser)
251
+ selenium_browser.should_receive(:window).twice.with("result").and_return(selenium_browser)
252
+ selenium_browser.should_receive(:title).and_return("Display Results")
253
+ selenium_page.attach_to_window(:title => "Display Results")
254
+ end
255
+
256
+ it "a window can be attached to by using the url" do
257
+ selenium_browser.should_receive(:window_handles).and_return(["result"])
258
+ selenium_browser.should_receive(:switch_to).twice.and_return(selenium_browser)
259
+ selenium_browser.should_receive(:window).twice.with("result").and_return(selenium_browser)
260
+ selenium_browser.should_receive(:current_url).and_return("results.html")
261
+ selenium_page.attach_to_window(:url => "results.html")
262
+ end
263
+
264
+ it "a modal dialog can be treated as a window" do
265
+ selenium_browser.should_receive(:execute_script)
266
+ selenium_page.will_be_modal {}
267
+ end
268
+ end
269
+ end
270
+
271
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+ require "terminus_spec/web_objects/all"
3
+
4
+ describe "there are common methods for all web objects" do
5
+ context "and all objects may have to handle an unknown request" do
6
+ it "so the request should be delegated to the platform object" do
7
+ watir_driver = double('watir')
8
+ watir_web_object = TerminusSpec::WebObjects::WebObject.new(watir_driver, :platform => :watir_webdriver)
9
+ watir_driver.should_receive(:do_this)
10
+ watir_web_object.do_this
11
+ end
12
+ end
13
+
14
+ context "and it will be necessary to build locators for Watir" do
15
+ it "so it must be possible to use xpath where objects by name is not supported" do
16
+ ['table', 'span', 'div', 'td', 'li', 'ol', 'ul'].each do |tag|
17
+ locator = {:tag_name => tag, :name => 'testing'}
18
+ result = TerminusSpec::WebObjects::WebObject.have_watir_find_object_with locator
19
+ result[:xpath].should == ".//#{tag}[@name='testing']"
20
+ end
21
+ end
22
+ end
23
+
24
+ context "and it will be necesary to build locators for Selenium" do
25
+
26
+ def display_objects
27
+ ['textarea', 'select', 'a', 'div', 'span', 'table', 'td', 'img', 'form', 'li', 'ul', 'ol']
28
+ end
29
+
30
+ def input_objects
31
+ ['text', 'hidden', 'checkbox', 'radio']
32
+ end
33
+
34
+ it "so it must be possible to use xpath when an index is provided for display objects" do
35
+ display_objects.each do |tag|
36
+ locator = {:tag_name => tag, :index => 1}
37
+ key, value = TerminusSpec::WebObjects::WebObject.have_selenium_find_object_with locator
38
+ key.should == :xpath
39
+ value.should == ".//#{tag}[2]"
40
+ end
41
+ end
42
+
43
+ it "so it must be possible to use xpath when an index is provided for input objects" do
44
+ input_objects.each do |tag|
45
+ locator = {:tag_name => 'input', :type => tag, :index => 1}
46
+ key, value = TerminusSpec::WebObjects::WebObject.have_selenium_find_object_with locator
47
+ key.should == :xpath
48
+ value.should include ".//input[@type='#{tag}'][2]"
49
+ end
50
+ end
51
+
52
+ it "so it must be possible to use xpath when locating display objects by name and index" do
53
+ display_objects.each do |tag|
54
+ locator = {:tag_name => tag, :name => 'testing', :index => 0}
55
+ key, value = TerminusSpec::WebObjects::WebObject.have_selenium_find_object_with locator
56
+ key.should == :xpath
57
+ value.should == ".//#{tag}[@name='testing'][1]"
58
+ end
59
+ end
60
+
61
+ it "so it must be possible to use xpath when locating input objects by name and index" do
62
+ input_objects.each do |type|
63
+ locator = {:tag_name => 'input', :type => "#{type}", :name => 'testing', :index => 0}
64
+ key, value = TerminusSpec::WebObjects::WebObject.have_selenium_find_object_with locator
65
+ key.should == :xpath
66
+ value.should include ".//input[@type='#{type}' and @name='testing'][1]"
67
+ end
68
+ end
69
+
70
+ it "so it must be possible to use xpath when locating display objects by name and class" do
71
+ display_objects.each do |tag|
72
+ locator = {:tag_name => tag, :name => 'test', :class => 'ing'}
73
+ key, value = TerminusSpec::WebObjects::WebObject.have_selenium_find_object_with locator
74
+ key.should == :xpath
75
+ value.should == ".//#{tag}[@name='test' and @class='ing']"
76
+ end
77
+ end
78
+
79
+ it "so it must be possible to use xpath when locating input objects by name and class" do
80
+ input_objects.each do |type|
81
+ locator = {:tag_name => 'input', :type => "#{type}", :name => 'test', :class => 'ing'}
82
+ key, value = TerminusSpec::WebObjects::WebObject.have_selenium_find_object_with locator
83
+ value.should include ".//input[@type='#{type}' and @name='test' and @class='ing']"
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require "terminus_spec/web_objects/all"
3
+ require "terminus_spec/web_objects/button"
4
+
5
+ describe TerminusSpec::WebObjects::Button do
6
+ let(:button) { TerminusSpec::WebObjects::Button }
7
+
8
+ describe "when mapping how to identify a web object" do
9
+ it "it should be able to map watir locators" do
10
+ [:class, :id, :index, :name, :value, :xpath].each do |type|
11
+ locator = button.have_watir_find_object_with type => 'value'
12
+ locator.keys.first.should == type
13
+ end
14
+ end
15
+
16
+ it "it should be able to map selenium locators" do
17
+ [:class, :id, :index, :name, :value, :xpath].each do |type|
18
+ key, value = button.have_selenium_find_object_with type => 'value'
19
+ key.should == type
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "when performing an action on a web object" do
25
+ let(:button_object) { double('button_object') }
26
+
27
+ context "and when selenium is the driver" do
28
+ it "then it should return an error when asked for text" do
29
+ button = TerminusSpec::WebObjects::Button.new(button_object, :platform => :selenium_webdriver)
30
+ lambda { button.text }.should raise_error
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require "terminus_spec/web_objects/all"
3
+ require "terminus_spec/web_objects/link"
4
+
5
+ describe TerminusSpec::WebObjects::Link do
6
+ let(:link) { TerminusSpec::WebObjects::Link }
7
+
8
+ describe "when mapping how to identify a web object" do
9
+ it "it should be able to map watir locators" do
10
+ [:class, :href, :id, :index, :name, :text, :xpath].each do |type|
11
+ locator = link.have_watir_find_object_with type => 'value'
12
+ locator.keys.first.should == type
13
+ end
14
+ end
15
+
16
+ it "it should be able to map selenium locators" do
17
+ [:class, :id, :link, :link_text, :name, :xpath, :index].each do |type|
18
+ key, value = link.have_selenium_find_object_with type => 'value'
19
+ key.should == type
20
+ end
21
+ end
22
+
23
+ it "it should be able to map watir selectors to selenium locators" do
24
+ key, value = link.have_selenium_find_object_with :text => 'value'
25
+ key.should == :link_text
26
+ end
27
+
28
+ it "it should be able to map selenium selectors to watir locators" do
29
+ [:link, :link_text].each do |type|
30
+ locator = link.have_watir_find_object_with type => 'value'
31
+ locator.keys.first.should == :text
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "when performing an action on a web object" do
37
+ let(:link_object) { double('link_object') }
38
+
39
+ context "and when selenium is the driver" do
40
+ it "then it should return an error when asked for a value" do
41
+ link = TerminusSpec::WebObjects::Link.new(link_object, :platform => :selenium_webdriver)
42
+ lambda { link.value }.should raise_error
43
+ end
44
+ end
45
+ end
46
+ end