page-object 0.2 → 0.2.1
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/.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
|
@@ -2,12 +2,12 @@ module PageObject
|
|
|
2
2
|
module Elements
|
|
3
3
|
class OrderedList < Element
|
|
4
4
|
include Enumerable
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
def initialize(element, platform)
|
|
7
7
|
@element = element
|
|
8
8
|
include_platform_for platform
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
#
|
|
12
12
|
# iterator that yields with a PageObject::Elements::ListItem
|
|
13
13
|
#
|
|
@@ -15,16 +15,16 @@ module PageObject
|
|
|
15
15
|
#
|
|
16
16
|
def each
|
|
17
17
|
for index in 1..self.items do
|
|
18
|
-
yield self[index-1]
|
|
18
|
+
yield self[index-1]
|
|
19
19
|
end
|
|
20
|
-
end
|
|
21
|
-
|
|
20
|
+
end
|
|
21
|
+
|
|
22
22
|
protected
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
def child_xpath
|
|
25
25
|
".//child::li"
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
def self.watir_finders
|
|
29
29
|
[:class, :id, :index, :xpath]
|
|
30
30
|
end
|
|
@@ -32,16 +32,16 @@ module PageObject
|
|
|
32
32
|
def include_platform_for platform
|
|
33
33
|
super
|
|
34
34
|
if platform[:platform] == :watir
|
|
35
|
-
require 'page-object/platforms/
|
|
36
|
-
self.class.send :include, PageObject::Platforms::
|
|
35
|
+
require 'page-object/platforms/watir/ordered_list'
|
|
36
|
+
self.class.send :include, PageObject::Platforms::Watir::OrderedList
|
|
37
37
|
elsif platform[:platform] == :selenium
|
|
38
|
-
require 'page-object/platforms/
|
|
39
|
-
self.class.send :include, PageObject::Platforms::
|
|
38
|
+
require 'page-object/platforms/selenium/ordered_list'
|
|
39
|
+
self.class.send :include, PageObject::Platforms::Selenium::OrderedList
|
|
40
40
|
else
|
|
41
|
-
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
41
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -12,7 +12,7 @@ module PageObject
|
|
|
12
12
|
def child_xpath
|
|
13
13
|
".//child::option"
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
def self.watir_finders
|
|
17
17
|
super + [:text, :value]
|
|
18
18
|
end
|
|
@@ -20,13 +20,13 @@ module PageObject
|
|
|
20
20
|
def include_platform_for platform
|
|
21
21
|
super
|
|
22
22
|
if platform[:platform] == :watir
|
|
23
|
-
require 'page-object/platforms/
|
|
24
|
-
self.class.send :include, PageObject::Platforms::
|
|
23
|
+
require 'page-object/platforms/watir/select_list'
|
|
24
|
+
self.class.send :include, PageObject::Platforms::Watir::SelectList
|
|
25
25
|
elsif platform[:platform] == :selenium
|
|
26
|
-
require 'page-object/platforms/
|
|
27
|
-
self.class.send :include, PageObject::Platforms::
|
|
26
|
+
require 'page-object/platforms/selenium/select_list'
|
|
27
|
+
self.class.send :include, PageObject::Platforms::Selenium::SelectList
|
|
28
28
|
else
|
|
29
|
-
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
29
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -2,12 +2,12 @@ module PageObject
|
|
|
2
2
|
module Elements
|
|
3
3
|
class Table < Element
|
|
4
4
|
include Enumerable
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
def initialize(element, platform)
|
|
7
7
|
@element = element
|
|
8
8
|
include_platform_for platform
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
#
|
|
12
12
|
# iterator that yields with a PageObject::Elements::TableRow
|
|
13
13
|
#
|
|
@@ -15,26 +15,26 @@ module PageObject
|
|
|
15
15
|
#
|
|
16
16
|
def each
|
|
17
17
|
for index in 1..self.rows do
|
|
18
|
-
yield self[index-1]
|
|
18
|
+
yield self[index-1]
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
protected
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
def child_xpath
|
|
25
25
|
".//child::tr"
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
def include_platform_for platform
|
|
29
29
|
super
|
|
30
30
|
if platform[:platform] == :watir
|
|
31
|
-
require 'page-object/platforms/
|
|
32
|
-
self.class.send :include, PageObject::Platforms::
|
|
31
|
+
require 'page-object/platforms/watir/table'
|
|
32
|
+
self.class.send :include, PageObject::Platforms::Watir::Table
|
|
33
33
|
elsif platform[:platform] == :selenium
|
|
34
|
-
require 'page-object/platforms/
|
|
35
|
-
self.class.send :include, PageObject::Platforms::
|
|
34
|
+
require 'page-object/platforms/selenium/table'
|
|
35
|
+
self.class.send :include, PageObject::Platforms::Selenium::Table
|
|
36
36
|
else
|
|
37
|
-
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
37
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
end
|
|
@@ -7,7 +7,7 @@ module PageObject
|
|
|
7
7
|
@element = element
|
|
8
8
|
include_platform_for platform
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
#
|
|
12
12
|
# iterator that yields with a PageObject::Elements::TableCell
|
|
13
13
|
#
|
|
@@ -15,26 +15,26 @@ module PageObject
|
|
|
15
15
|
#
|
|
16
16
|
def each
|
|
17
17
|
for index in 1..self.columns do
|
|
18
|
-
yield self[index-1]
|
|
18
|
+
yield self[index-1]
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
protected
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
def child_xpath
|
|
25
25
|
".//child::td|th"
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
def include_platform_for platform
|
|
29
29
|
super
|
|
30
30
|
if platform[:platform] == :watir
|
|
31
|
-
require 'page-object/platforms/
|
|
32
|
-
self.class.send :include, PageObject::Platforms::
|
|
31
|
+
require 'page-object/platforms/watir/table_row'
|
|
32
|
+
self.class.send :include, PageObject::Platforms::Watir::TableRow
|
|
33
33
|
elsif platform[:platform] == :selenium
|
|
34
|
-
require 'page-object/platforms/
|
|
35
|
-
self.class.send :include, PageObject::Platforms::
|
|
34
|
+
require 'page-object/platforms/selenium/table_row'
|
|
35
|
+
self.class.send :include, PageObject::Platforms::Selenium::TableRow
|
|
36
36
|
else
|
|
37
|
-
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
37
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
end
|
|
@@ -3,19 +3,19 @@ module PageObject
|
|
|
3
3
|
class TextArea < Element
|
|
4
4
|
|
|
5
5
|
protected
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
def self.watir_finders
|
|
8
8
|
super + [:tag_name]
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
def self.watir_mapping
|
|
12
12
|
super.merge({:css => :tag_name})
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
def self.selenium_finders
|
|
16
16
|
super + [:css]
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def self.selenium_mapping
|
|
20
20
|
super.merge({:tag_name => :css})
|
|
21
21
|
end
|
|
@@ -3,19 +3,19 @@ module PageObject
|
|
|
3
3
|
class TextField < Element
|
|
4
4
|
|
|
5
5
|
protected
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
def self.watir_finders
|
|
8
8
|
super + [:tag_name]
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
def self.watir_mapping
|
|
12
12
|
super.merge({:css => :tag_name})
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
def self.selenium_finders
|
|
16
16
|
super + [:css]
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
def self.selenium_mapping
|
|
20
20
|
super.merge({:tag_name => :css})
|
|
21
21
|
end
|
|
@@ -2,12 +2,12 @@ module PageObject
|
|
|
2
2
|
module Elements
|
|
3
3
|
class UnorderedList < Element
|
|
4
4
|
include Enumerable
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
def initialize(element, platform)
|
|
7
7
|
@element = element
|
|
8
8
|
include_platform_for platform
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
#
|
|
12
12
|
# iterator that yields with a PageObject::Elements::ListItem
|
|
13
13
|
#
|
|
@@ -15,17 +15,17 @@ module PageObject
|
|
|
15
15
|
#
|
|
16
16
|
def each
|
|
17
17
|
for index in 1..self.items do
|
|
18
|
-
yield self[index-1]
|
|
18
|
+
yield self[index-1]
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
|
|
23
23
|
protected
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
def child_xpath
|
|
26
26
|
".//child::li"
|
|
27
27
|
end
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
def self.watir_finders
|
|
30
30
|
[:class, :id, :index, :xpath]
|
|
31
31
|
end
|
|
@@ -33,16 +33,16 @@ module PageObject
|
|
|
33
33
|
def include_platform_for platform
|
|
34
34
|
super
|
|
35
35
|
if platform[:platform] == :watir
|
|
36
|
-
require 'page-object/platforms/
|
|
37
|
-
self.class.send :include, PageObject::Platforms::
|
|
36
|
+
require 'page-object/platforms/watir/unordered_list'
|
|
37
|
+
self.class.send :include, PageObject::Platforms::Watir::UnorderedList
|
|
38
38
|
elsif platform[:platform] == :selenium
|
|
39
|
-
require 'page-object/platforms/
|
|
40
|
-
self.class.send :include, PageObject::Platforms::
|
|
39
|
+
require 'page-object/platforms/selenium/unordered_list'
|
|
40
|
+
self.class.send :include, PageObject::Platforms::Selenium::UnorderedList
|
|
41
41
|
else
|
|
42
|
-
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
42
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
#
|
|
3
|
+
# module which provides a function for determining
|
|
4
|
+
# which platform to provide to the page object
|
|
5
|
+
#
|
|
6
|
+
module LoadsPlatform
|
|
7
|
+
#
|
|
8
|
+
# Determines which platform the Page Object should use based upon browser
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# platform = load_platform(watir_webdriver_browser, PageObject.Adapters.list).send(:new, watir_webdriver_browser)
|
|
12
|
+
#
|
|
13
|
+
# @param [Object] A browser driver that has a supported adapter
|
|
14
|
+
# @param [adapters] a list of adapters that are currently supported
|
|
15
|
+
# @returns [PageObject]
|
|
16
|
+
#
|
|
17
|
+
def load_platform(browser, adapters)
|
|
18
|
+
adapters.each_value { |adapter|
|
|
19
|
+
return adapter.create_page_object(browser) if adapter.is_for?(browser)
|
|
20
|
+
}
|
|
21
|
+
raise 'Unable to pick a platform for the provided browser'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -19,7 +19,7 @@ module PageObject
|
|
|
19
19
|
# end
|
|
20
20
|
#
|
|
21
21
|
module PageFactory
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
#
|
|
24
24
|
# Create and navigate to a page object. The navigation will only work if the
|
|
25
25
|
# 'page_url' method was call on the page object.
|
|
@@ -31,7 +31,7 @@ module PageObject
|
|
|
31
31
|
def visit_page(page_class, &block)
|
|
32
32
|
on_page page_class, true, &block
|
|
33
33
|
end
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
#
|
|
36
36
|
# Create a page object.
|
|
37
37
|
#
|
|
@@ -45,6 +45,6 @@ module PageObject
|
|
|
45
45
|
block.call page if block
|
|
46
46
|
page
|
|
47
47
|
end
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
end
|
|
50
50
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'page-object/loads_platform'
|
|
2
|
+
|
|
3
|
+
module PageObject
|
|
4
|
+
module Platforms
|
|
5
|
+
@@adapters = {}
|
|
6
|
+
|
|
7
|
+
def self.get
|
|
8
|
+
@@adapters
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.register(key, adapter)
|
|
12
|
+
@@adapters[key] = adapter
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
require 'page-object/platforms/watir'
|
|
17
|
+
require 'page-object/platforms/selenium'
|
|
18
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
module Platforms
|
|
3
|
+
module Selenium
|
|
4
|
+
|
|
5
|
+
def self.create_page_object(browser)
|
|
6
|
+
require 'page-object/platforms/selenium/page_object'
|
|
7
|
+
return Object::PageObject::Platforms::Selenium::PageObject.new(browser)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.is_for?(browser)
|
|
11
|
+
browser.is_a? Object::Selenium::WebDriver::Driver
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
PageObject::Platforms.register(:selenium, PageObject::Platforms::Selenium)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
module Platforms
|
|
3
|
+
module Selenium
|
|
4
|
+
module Button
|
|
5
|
+
#
|
|
6
|
+
# Override PageObject::PLatforms::SeleniumElement#text because
|
|
7
|
+
# #text does not reliabably return a value in Selenium
|
|
8
|
+
#
|
|
9
|
+
def text
|
|
10
|
+
raise "text is not available on button element in Selenium"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
module Platforms
|
|
3
|
+
#
|
|
4
|
+
# Selenium implementation of the common functionality found across all elements
|
|
5
|
+
#
|
|
6
|
+
module Selenium
|
|
7
|
+
module Element
|
|
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 = Object::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 = Object::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 = Object::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 = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
|
|
138
|
+
wait.until &block
|
|
139
|
+
end
|
|
140
|
+
#
|
|
141
|
+
# Waits until the block returns true
|
|
142
|
+
#
|
|
143
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
|
144
|
+
# @param [String] the message to display if the event timeouts
|
|
145
|
+
# @param the block to execute when the event occurrs
|
|
146
|
+
#
|
|
147
|
+
def wait_until(timeout=5, message=nil, &block)
|
|
148
|
+
wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
|
|
149
|
+
wait.until &block
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
#
|
|
153
|
+
# Send keystrokes to this element
|
|
154
|
+
#
|
|
155
|
+
# @param [String, Symbol, Array]
|
|
156
|
+
#
|
|
157
|
+
# Examples:
|
|
158
|
+
#
|
|
159
|
+
# element.send_keys "foo" #=> value: 'foo'
|
|
160
|
+
# element.send_keys "tet", :arrow_left, "s" #=> value: 'test'
|
|
161
|
+
# element.send_keys [:control, 'a'], :space #=> value: ' '
|
|
162
|
+
#
|
|
163
|
+
# @see Selenium::WebDriver::Keys::KEYS
|
|
164
|
+
#
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|