page-object 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -1
- data/ChangeLog +12 -6
- data/README.md +1 -1
- data/Rakefile +3 -19
- data/features/async.feature +8 -8
- data/features/button.feature +7 -7
- data/features/check_box.feature +8 -8
- data/features/div.feature +7 -6
- data/features/element_attributes.feature +14 -14
- data/features/form.feature +5 -5
- data/features/frames.feature +12 -0
- data/features/hidden_field.feature +5 -5
- data/features/html/frame_1.html +18 -0
- data/features/html/frame_2.html +16 -0
- data/features/html/frames.html +11 -0
- data/features/html/iframes.html +12 -0
- data/features/html/static_elements.html +50 -42
- data/features/html/success.html +5 -5
- data/features/image.feature +11 -11
- data/features/link.feature +1 -1
- data/features/list_item.feature +5 -5
- data/features/ordered_list.feature +6 -6
- data/features/page_level_actions.feature +16 -5
- data/features/radio_button.feature +12 -12
- data/features/select_list.feature +12 -12
- data/features/span.feature +5 -5
- data/features/step_definitions/accessor_steps.rb +2 -2
- data/features/step_definitions/async_steps.rb +1 -1
- data/features/step_definitions/element_steps.rb +1 -1
- data/features/step_definitions/frames_steps.rb +21 -0
- data/features/step_definitions/page_level_actions_steps.rb +24 -2
- data/features/step_definitions/page_traversal_steps.rb +0 -1
- data/features/support/env.rb +20 -6
- data/features/support/page.rb +14 -11
- data/features/support/url_helper.rb +4 -0
- data/features/table.feature +9 -9
- data/features/table_cell.feature +6 -6
- data/features/text_area.feature +6 -6
- data/features/text_field.feature +7 -7
- data/features/unordered_list.feature +6 -6
- data/lib/page-object.rb +40 -16
- data/lib/page-object/accessors.rb +15 -15
- data/lib/page-object/elements.rb +0 -1
- data/lib/page-object/elements/button.rb +24 -24
- data/lib/page-object/elements/div.rb +8 -3
- data/lib/page-object/elements/element.rb +27 -28
- data/lib/page-object/elements/form.rb +7 -7
- data/lib/page-object/elements/hidden_field.rb +5 -5
- data/lib/page-object/elements/image.rb +8 -8
- data/lib/page-object/elements/link.rb +9 -9
- data/lib/page-object/elements/list_item.rb +1 -1
- data/lib/page-object/elements/option.rb +1 -1
- data/lib/page-object/elements/ordered_list.rb +13 -13
- data/lib/page-object/elements/select_list.rb +6 -6
- data/lib/page-object/elements/span.rb +2 -2
- data/lib/page-object/elements/table.rb +11 -11
- data/lib/page-object/elements/table_row.rb +9 -9
- data/lib/page-object/elements/text_area.rb +4 -4
- data/lib/page-object/elements/text_field.rb +4 -4
- data/lib/page-object/elements/unordered_list.rb +13 -13
- data/lib/page-object/loads_platform.rb +24 -0
- data/lib/page-object/page_factory.rb +3 -3
- data/lib/page-object/platforms.rb +18 -0
- data/lib/page-object/platforms/selenium.rb +16 -0
- data/lib/page-object/platforms/selenium/button.rb +15 -0
- data/lib/page-object/platforms/selenium/element.rb +168 -0
- data/lib/page-object/platforms/selenium/form.rb +16 -0
- data/lib/page-object/platforms/selenium/image.rb +28 -0
- data/lib/page-object/platforms/selenium/link.rb +16 -0
- data/lib/page-object/platforms/selenium/ordered_list.rb +33 -0
- data/lib/page-object/platforms/selenium/page_object.rb +524 -0
- data/lib/page-object/platforms/selenium/select_list.rb +32 -0
- data/lib/page-object/platforms/selenium/table.rb +40 -0
- data/lib/page-object/platforms/selenium/table_row.rb +32 -0
- data/lib/page-object/platforms/selenium/unordered_list.rb +33 -0
- data/lib/page-object/platforms/watir.rb +16 -0
- data/lib/page-object/platforms/watir/element.rb +154 -0
- data/lib/page-object/platforms/watir/form.rb +16 -0
- data/lib/page-object/platforms/watir/image.rb +22 -0
- data/lib/page-object/platforms/watir/ordered_list.rb +32 -0
- data/lib/page-object/{watir_page_object.rb → platforms/watir/page_object.rb} +62 -35
- data/lib/page-object/platforms/watir/select_list.rb +33 -0
- data/lib/page-object/platforms/watir/table.rb +27 -0
- data/lib/page-object/platforms/watir/table_row.rb +24 -0
- data/lib/page-object/platforms/watir/unordered_list.rb +33 -0
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +13 -13
- data/spec/page-object/accessors_spec.rb +142 -108
- data/spec/page-object/elements/button_spec.rb +33 -33
- data/spec/page-object/elements/check_box_spec.rb +1 -1
- data/spec/page-object/elements/div_spec.rb +3 -3
- data/spec/page-object/elements/element_spec.rb +51 -41
- data/spec/page-object/elements/form_spec.rb +3 -3
- data/spec/page-object/elements/hidden_field_spec.rb +3 -3
- data/spec/page-object/elements/image_spec.rb +7 -7
- data/spec/page-object/elements/link_spec.rb +8 -8
- data/spec/page-object/elements/list_item_spec.rb +1 -1
- data/spec/page-object/elements/ordered_list_spec.rb +9 -9
- data/spec/page-object/elements/radio_button_spec.rb +1 -1
- data/spec/page-object/elements/select_list_spec.rb +2 -2
- data/spec/page-object/elements/span_spec.rb +1 -1
- data/spec/page-object/elements/table_row_spec.rb +6 -6
- data/spec/page-object/elements/table_spec.rb +9 -9
- data/spec/page-object/elements/text_area_spec.rb +3 -3
- data/spec/page-object/elements/text_field_spec.rb +3 -3
- data/spec/page-object/elements/unordered_list_spec.rb +10 -10
- data/spec/page-object/loads_platform_spec.rb +38 -0
- data/spec/page-object/page-object_spec.rb +70 -10
- data/spec/page-object/page_factory_spec.rb +3 -3
- data/spec/page-object/{selenium_page_object_spec.rb → platforms/selenium/selenium_page_object_spec.rb} +10 -3
- data/spec/page-object/platforms/selenium_spec.rb +26 -0
- data/spec/page-object/platforms/watir_spec.rb +27 -0
- data/spec/spec_helper.rb +18 -5
- metadata +48 -26
- data/lib/page-object/platforms/selenium_button.rb +0 -13
- data/lib/page-object/platforms/selenium_element.rb +0 -142
- data/lib/page-object/platforms/selenium_form.rb +0 -14
- data/lib/page-object/platforms/selenium_image.rb +0 -26
- data/lib/page-object/platforms/selenium_link.rb +0 -13
- data/lib/page-object/platforms/selenium_ordered_list.rb +0 -31
- data/lib/page-object/platforms/selenium_select_list.rb +0 -29
- data/lib/page-object/platforms/selenium_table.rb +0 -38
- data/lib/page-object/platforms/selenium_table_row.rb +0 -29
- data/lib/page-object/platforms/selenium_unordered_list.rb +0 -31
- data/lib/page-object/platforms/watir_element.rb +0 -136
- data/lib/page-object/platforms/watir_form.rb +0 -14
- data/lib/page-object/platforms/watir_image.rb +0 -20
- data/lib/page-object/platforms/watir_ordered_list.rb +0 -30
- data/lib/page-object/platforms/watir_select_list.rb +0 -30
- data/lib/page-object/platforms/watir_table.rb +0 -24
- data/lib/page-object/platforms/watir_table_row.rb +0 -22
- data/lib/page-object/platforms/watir_unordered_list.rb +0 -31
- data/lib/page-object/selenium_page_object.rb +0 -486
@@ -8,7 +8,7 @@ end
|
|
8
8
|
|
9
9
|
class TestWorld
|
10
10
|
include PageObject::PageFactory
|
11
|
-
|
11
|
+
|
12
12
|
attr_accessor :browser
|
13
13
|
end
|
14
14
|
|
@@ -17,14 +17,14 @@ describe PageObject::PageFactory do
|
|
17
17
|
@world = TestWorld.new
|
18
18
|
@world.browser = mock_watir_browser
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "should create a new page object and execute a block" do
|
22
22
|
@world.browser.should_not_receive(:goto)
|
23
23
|
@world.on_page FactoryTestPageObject do |page|
|
24
24
|
page.should be_instance_of FactoryTestPageObject
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "should create and visit a new page" do
|
29
29
|
@world.browser.should_receive(:goto)
|
30
30
|
@world.visit_page FactoryTestPageObject do |page|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'page-object/
|
2
|
+
require 'page-object/platforms/selenium/page_object'
|
3
3
|
require 'page-object/elements'
|
4
4
|
|
5
5
|
class SeleniumTestPageObject
|
6
6
|
include PageObject
|
7
7
|
end
|
8
8
|
|
9
|
-
describe PageObject::
|
9
|
+
describe PageObject::Platforms::Selenium::PageObject do
|
10
10
|
let(:selenium_browser) { mock_selenium_browser }
|
11
11
|
let(:selenium_page_object) { SeleniumTestPageObject.new(selenium_browser) }
|
12
12
|
|
@@ -17,12 +17,19 @@ describe PageObject::SeleniumPageObject do
|
|
17
17
|
selenium_browser.should_receive(:find_element)
|
18
18
|
selenium_page_object.platform.hidden_field_for(:text => 'foo')
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "should add tag_name when identifying by href for anchor" do
|
22
22
|
expected_identifier = {:href => 'foo', :tag_name => 'a'}
|
23
23
|
PageObject::Elements::Link.should_receive(:selenium_identifier_for).with(expected_identifier)
|
24
24
|
selenium_browser.should_receive(:find_element)
|
25
25
|
selenium_page_object.platform.link_for(:href => 'foo')
|
26
26
|
end
|
27
|
+
|
28
|
+
it "should add tag_name when identifying by text for div" do
|
29
|
+
expected_identifier = {:text => 'foo', :tag_name => 'div'}
|
30
|
+
PageObject::Elements::Div.should_receive(:selenium_identifier_for).with(expected_identifier)
|
31
|
+
selenium_browser.should_receive(:find_element)
|
32
|
+
selenium_page_object.platform.div_for(:text => 'foo')
|
33
|
+
end
|
27
34
|
end
|
28
35
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe PageObject::Platforms::Selenium do
|
5
|
+
|
6
|
+
it "should be registered as an adapter" do
|
7
|
+
PageObject::Platforms.get[:selenium].should be PageObject::Platforms::Selenium
|
8
|
+
|
9
|
+
end
|
10
|
+
describe 'create page object' do
|
11
|
+
let(:browser) { double('browser') }
|
12
|
+
let(:subject) { PageObject::Platforms::Selenium.create_page_object(browser) }
|
13
|
+
it "should create a SeleniumPageObject" do
|
14
|
+
subject.should be_kind_of PageObject::Platforms::Selenium::PageObject
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe "is for?" do
|
18
|
+
it "should be true when the browser is a selenium driver" do
|
19
|
+
browser = mock_selenium_browser()
|
20
|
+
PageObject::Platforms::Selenium.is_for?(browser).should == true
|
21
|
+
end
|
22
|
+
it "should be false when the browser is anything else" do
|
23
|
+
PageObject::Platforms::Selenium.is_for?("asdf").should == false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PageObject::Platforms::Watir do
|
4
|
+
it "should be in the PageObjects Adapters list" do
|
5
|
+
PageObject::Platforms.get[:watir].should be PageObject::Platforms::Watir
|
6
|
+
end
|
7
|
+
describe "create page object" do
|
8
|
+
let(:browser) { double('browser') }
|
9
|
+
let(:subject) { PageObject::Platforms::Watir.create_page_object(browser) }
|
10
|
+
it "should create a WatirPageObject" do
|
11
|
+
subject.should be_kind_of PageObject::WatirPageObject
|
12
|
+
end
|
13
|
+
it "should give the watir page object the browser" do
|
14
|
+
subject.browser.should be browser
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe "is for?" do
|
18
|
+
it "should be true when the browser is Watir::Browser" do
|
19
|
+
browser = mock_watir_browser()
|
20
|
+
PageObject::Platforms::Watir.is_for?(browser).should be true
|
21
|
+
end
|
22
|
+
it "should be false at any other point" do
|
23
|
+
browser = 'asdf'
|
24
|
+
PageObject::Platforms::Watir.is_for?('asdf').should be false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,15 +17,28 @@ require 'page-object'
|
|
17
17
|
|
18
18
|
def mock_watir_browser
|
19
19
|
watir_browser = double('watir')
|
20
|
-
watir_browser.
|
20
|
+
watir_browser.stub!(:is_a?).with(anything()).and_return(false)
|
21
|
+
watir_browser.stub!(:is_a?).with(Watir::Browser).and_return(true)
|
21
22
|
watir_browser
|
22
23
|
end
|
23
24
|
|
24
|
-
|
25
|
+
|
25
26
|
def mock_selenium_browser
|
26
27
|
selenium_browser = double('selenium')
|
27
|
-
selenium_browser.
|
28
|
-
selenium_browser.
|
28
|
+
selenium_browser.stub!(:is_a?).with(Watir::Browser).and_return(false)
|
29
|
+
selenium_browser.stub!(:is_a?).with(Selenium::WebDriver::Driver).and_return(true)
|
29
30
|
selenium_browser
|
30
31
|
end
|
31
|
-
|
32
|
+
|
33
|
+
|
34
|
+
def mock_adapter(browser, page_object)
|
35
|
+
adapter = double('adapter')
|
36
|
+
adapter.stub!(:is_for?).with(anything()).and_return false
|
37
|
+
adapter.stub!(:is_for?).with(browser).and_return true
|
38
|
+
adapter.stub!(:create_page_object).and_return page_object
|
39
|
+
adapter
|
40
|
+
end
|
41
|
+
|
42
|
+
def mock_adapters(adapters)
|
43
|
+
PageObject::Platforms.stub!(:get).and_return adapters
|
44
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: page-object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeff Morgan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-29 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: watir-webdriver
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.2.
|
23
|
+
version: 0.2.8
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 2.
|
34
|
+
version: 2.2.0
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id002
|
37
37
|
- !ruby/object:Gem::Dependency
|
@@ -93,7 +93,12 @@ files:
|
|
93
93
|
- features/div.feature
|
94
94
|
- features/element_attributes.feature
|
95
95
|
- features/form.feature
|
96
|
+
- features/frames.feature
|
96
97
|
- features/hidden_field.feature
|
98
|
+
- features/html/frame_1.html
|
99
|
+
- features/html/frame_2.html
|
100
|
+
- features/html/frames.html
|
101
|
+
- features/html/iframes.html
|
97
102
|
- features/html/images/circle.png
|
98
103
|
- features/html/static_elements.html
|
99
104
|
- features/html/success.html
|
@@ -108,6 +113,7 @@ files:
|
|
108
113
|
- features/step_definitions/accessor_steps.rb
|
109
114
|
- features/step_definitions/async_steps.rb
|
110
115
|
- features/step_definitions/element_steps.rb
|
116
|
+
- features/step_definitions/frames_steps.rb
|
111
117
|
- features/step_definitions/page_level_actions_steps.rb
|
112
118
|
- features/step_definitions/page_traversal_steps.rb
|
113
119
|
- features/step_definitions/table_steps.rb
|
@@ -142,28 +148,32 @@ files:
|
|
142
148
|
- lib/page-object/elements/text_area.rb
|
143
149
|
- lib/page-object/elements/text_field.rb
|
144
150
|
- lib/page-object/elements/unordered_list.rb
|
151
|
+
- lib/page-object/loads_platform.rb
|
145
152
|
- lib/page-object/page_factory.rb
|
146
|
-
- lib/page-object/platforms
|
147
|
-
- lib/page-object/platforms/
|
148
|
-
- lib/page-object/platforms/
|
149
|
-
- lib/page-object/platforms/
|
150
|
-
- lib/page-object/platforms/
|
151
|
-
- lib/page-object/platforms/
|
152
|
-
- lib/page-object/platforms/
|
153
|
-
- lib/page-object/platforms/
|
154
|
-
- lib/page-object/platforms/
|
155
|
-
- lib/page-object/platforms/
|
156
|
-
- lib/page-object/platforms/
|
157
|
-
- lib/page-object/platforms/
|
158
|
-
- lib/page-object/platforms/
|
159
|
-
- lib/page-object/platforms/
|
160
|
-
- lib/page-object/platforms/
|
161
|
-
- lib/page-object/platforms/
|
162
|
-
- lib/page-object/platforms/
|
163
|
-
- lib/page-object/platforms/
|
164
|
-
- lib/page-object/
|
153
|
+
- lib/page-object/platforms.rb
|
154
|
+
- lib/page-object/platforms/selenium.rb
|
155
|
+
- lib/page-object/platforms/selenium/button.rb
|
156
|
+
- lib/page-object/platforms/selenium/element.rb
|
157
|
+
- lib/page-object/platforms/selenium/form.rb
|
158
|
+
- lib/page-object/platforms/selenium/image.rb
|
159
|
+
- lib/page-object/platforms/selenium/link.rb
|
160
|
+
- lib/page-object/platforms/selenium/ordered_list.rb
|
161
|
+
- lib/page-object/platforms/selenium/page_object.rb
|
162
|
+
- lib/page-object/platforms/selenium/select_list.rb
|
163
|
+
- lib/page-object/platforms/selenium/table.rb
|
164
|
+
- lib/page-object/platforms/selenium/table_row.rb
|
165
|
+
- lib/page-object/platforms/selenium/unordered_list.rb
|
166
|
+
- lib/page-object/platforms/watir.rb
|
167
|
+
- lib/page-object/platforms/watir/element.rb
|
168
|
+
- lib/page-object/platforms/watir/form.rb
|
169
|
+
- lib/page-object/platforms/watir/image.rb
|
170
|
+
- lib/page-object/platforms/watir/ordered_list.rb
|
171
|
+
- lib/page-object/platforms/watir/page_object.rb
|
172
|
+
- lib/page-object/platforms/watir/select_list.rb
|
173
|
+
- lib/page-object/platforms/watir/table.rb
|
174
|
+
- lib/page-object/platforms/watir/table_row.rb
|
175
|
+
- lib/page-object/platforms/watir/unordered_list.rb
|
165
176
|
- lib/page-object/version.rb
|
166
|
-
- lib/page-object/watir_page_object.rb
|
167
177
|
- page-object.gemspec
|
168
178
|
- spec/page-object/accessors_spec.rb
|
169
179
|
- spec/page-object/elements/button_spec.rb
|
@@ -184,9 +194,12 @@ files:
|
|
184
194
|
- spec/page-object/elements/text_area_spec.rb
|
185
195
|
- spec/page-object/elements/text_field_spec.rb
|
186
196
|
- spec/page-object/elements/unordered_list_spec.rb
|
197
|
+
- spec/page-object/loads_platform_spec.rb
|
187
198
|
- spec/page-object/page-object_spec.rb
|
188
199
|
- spec/page-object/page_factory_spec.rb
|
189
|
-
- spec/page-object/selenium_page_object_spec.rb
|
200
|
+
- spec/page-object/platforms/selenium/selenium_page_object_spec.rb
|
201
|
+
- spec/page-object/platforms/selenium_spec.rb
|
202
|
+
- spec/page-object/platforms/watir_spec.rb
|
190
203
|
- spec/spec_helper.rb
|
191
204
|
homepage: http://github.com/cheezy/page-object
|
192
205
|
licenses: []
|
@@ -222,7 +235,12 @@ test_files:
|
|
222
235
|
- features/div.feature
|
223
236
|
- features/element_attributes.feature
|
224
237
|
- features/form.feature
|
238
|
+
- features/frames.feature
|
225
239
|
- features/hidden_field.feature
|
240
|
+
- features/html/frame_1.html
|
241
|
+
- features/html/frame_2.html
|
242
|
+
- features/html/frames.html
|
243
|
+
- features/html/iframes.html
|
226
244
|
- features/html/images/circle.png
|
227
245
|
- features/html/static_elements.html
|
228
246
|
- features/html/success.html
|
@@ -237,6 +255,7 @@ test_files:
|
|
237
255
|
- features/step_definitions/accessor_steps.rb
|
238
256
|
- features/step_definitions/async_steps.rb
|
239
257
|
- features/step_definitions/element_steps.rb
|
258
|
+
- features/step_definitions/frames_steps.rb
|
240
259
|
- features/step_definitions/page_level_actions_steps.rb
|
241
260
|
- features/step_definitions/page_traversal_steps.rb
|
242
261
|
- features/step_definitions/table_steps.rb
|
@@ -267,7 +286,10 @@ test_files:
|
|
267
286
|
- spec/page-object/elements/text_area_spec.rb
|
268
287
|
- spec/page-object/elements/text_field_spec.rb
|
269
288
|
- spec/page-object/elements/unordered_list_spec.rb
|
289
|
+
- spec/page-object/loads_platform_spec.rb
|
270
290
|
- spec/page-object/page-object_spec.rb
|
271
291
|
- spec/page-object/page_factory_spec.rb
|
272
|
-
- spec/page-object/selenium_page_object_spec.rb
|
292
|
+
- spec/page-object/platforms/selenium/selenium_page_object_spec.rb
|
293
|
+
- spec/page-object/platforms/selenium_spec.rb
|
294
|
+
- spec/page-object/platforms/watir_spec.rb
|
273
295
|
- spec/spec_helper.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module PageObject
|
2
|
-
module Platforms
|
3
|
-
module SeleniumButton
|
4
|
-
#
|
5
|
-
# Override PageObject::PLatforms::SeleniumElement#text because
|
6
|
-
# #text does not reliabably return a value in Selenium
|
7
|
-
#
|
8
|
-
def text
|
9
|
-
raise "text is not available on button element in Selenium"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,142 +0,0 @@
|
|
1
|
-
|
2
|
-
module PageObject
|
3
|
-
module Platforms
|
4
|
-
#
|
5
|
-
# Selenium implementation of the common functionality found across all elements
|
6
|
-
#
|
7
|
-
module SeleniumElement
|
8
|
-
|
9
|
-
#
|
10
|
-
# return true if an element is visible
|
11
|
-
#
|
12
|
-
def visible?
|
13
|
-
@element.displayed?
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# return true if an element exists
|
18
|
-
#
|
19
|
-
def exists?
|
20
|
-
nil != @element
|
21
|
-
end
|
22
|
-
|
23
|
-
#
|
24
|
-
# Get the text for the element
|
25
|
-
#
|
26
|
-
# @return [String]
|
27
|
-
#
|
28
|
-
def text
|
29
|
-
@element.text
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# Get the value of this element
|
34
|
-
#
|
35
|
-
# @return [String]
|
36
|
-
#
|
37
|
-
def value
|
38
|
-
@element.attribute('value')
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# compare this element to another to determine if they are equal
|
43
|
-
#
|
44
|
-
def ==(other)
|
45
|
-
@element == other.element
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
# Get the tag name of this element
|
50
|
-
#
|
51
|
-
# @return [String]
|
52
|
-
#
|
53
|
-
def tag_name
|
54
|
-
@element.tag_name
|
55
|
-
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# Get the value of a the given attribute of the element. Will return the current value, even if
|
59
|
-
# this has been modified after the page has been loaded. More exactly, this method will return
|
60
|
-
# the value of the given attribute, unless that attribute is not present, in which case the
|
61
|
-
# value of the property with the same name is returned. If neither value is set, nil is
|
62
|
-
# returned. The "style" attribute is converted as best can be to a text representation with a
|
63
|
-
# trailing semi-colon. The following are deemed to be "boolean" attributes, and will
|
64
|
-
# return either "true" or "false":
|
65
|
-
#
|
66
|
-
# async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
|
67
|
-
# defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,
|
68
|
-
# iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate,
|
69
|
-
# nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking,
|
70
|
-
# selected, spellcheck, truespeed, willvalidate
|
71
|
-
#
|
72
|
-
# Finally, the following commonly mis-capitalized attribute/property names are evaluated as
|
73
|
-
# expected:
|
74
|
-
#
|
75
|
-
# class, readonly
|
76
|
-
#
|
77
|
-
# @param [String]
|
78
|
-
# attribute name
|
79
|
-
# @return [String,nil]
|
80
|
-
# attribute value
|
81
|
-
#
|
82
|
-
def attribute(attribute_name)
|
83
|
-
@element.attribute attribute_name
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Click this element
|
88
|
-
#
|
89
|
-
def click
|
90
|
-
@element.click
|
91
|
-
end
|
92
|
-
|
93
|
-
#
|
94
|
-
# Waits until the element is present
|
95
|
-
#
|
96
|
-
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
97
|
-
#
|
98
|
-
def when_present(timeout=5)
|
99
|
-
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
|
100
|
-
wait.until do
|
101
|
-
self.exists?
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
#
|
106
|
-
# Waits until the element is visible
|
107
|
-
#
|
108
|
-
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
109
|
-
#
|
110
|
-
def when_visible(timeout=5)
|
111
|
-
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
|
112
|
-
wait.until do
|
113
|
-
self.visible?
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
#
|
118
|
-
# Waits until the element is not visible
|
119
|
-
#
|
120
|
-
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
121
|
-
#
|
122
|
-
def when_not_visible(timeout=5)
|
123
|
-
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
|
124
|
-
wait.until do
|
125
|
-
not self.visible?
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
#
|
130
|
-
# Waits until the block returns true
|
131
|
-
#
|
132
|
-
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
133
|
-
# @param [String] the message to display if the event timeouts
|
134
|
-
# @param the block to execute when the event occurrs
|
135
|
-
#
|
136
|
-
def wait_until(timeout=5, message=nil, &block)
|
137
|
-
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
|
138
|
-
wait.until &block
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|