watir-nokogiri 1.0.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.
- data/LICENSE +22 -0
- data/README.md +65 -0
- data/lib/watir-nokogiri.rb +69 -0
- data/lib/watir-nokogiri/aliases.rb +6 -0
- data/lib/watir-nokogiri/attribute_helper.rb +145 -0
- data/lib/watir-nokogiri/cell_container.rb +31 -0
- data/lib/watir-nokogiri/container.rb +50 -0
- data/lib/watir-nokogiri/document.rb +171 -0
- data/lib/watir-nokogiri/element_collection.rb +93 -0
- data/lib/watir-nokogiri/elements/button.rb +71 -0
- data/lib/watir-nokogiri/elements/checkbox.rb +61 -0
- data/lib/watir-nokogiri/elements/dlist.rb +12 -0
- data/lib/watir-nokogiri/elements/element.rb +319 -0
- data/lib/watir-nokogiri/elements/file_field.rb +45 -0
- data/lib/watir-nokogiri/elements/font.rb +11 -0
- data/lib/watir-nokogiri/elements/form.rb +17 -0
- data/lib/watir-nokogiri/elements/frame.rb +75 -0
- data/lib/watir-nokogiri/elements/generated.rb +2662 -0
- data/lib/watir-nokogiri/elements/hidden.rb +24 -0
- data/lib/watir-nokogiri/elements/image.rb +59 -0
- data/lib/watir-nokogiri/elements/input.rb +34 -0
- data/lib/watir-nokogiri/elements/link.rb +7 -0
- data/lib/watir-nokogiri/elements/option.rb +83 -0
- data/lib/watir-nokogiri/elements/radio.rb +44 -0
- data/lib/watir-nokogiri/elements/select.rb +126 -0
- data/lib/watir-nokogiri/elements/table.rb +44 -0
- data/lib/watir-nokogiri/elements/table_cell.rb +36 -0
- data/lib/watir-nokogiri/elements/table_row.rb +46 -0
- data/lib/watir-nokogiri/elements/table_section.rb +15 -0
- data/lib/watir-nokogiri/elements/text_area.rb +22 -0
- data/lib/watir-nokogiri/elements/text_field.rb +44 -0
- data/lib/watir-nokogiri/exception.rb +20 -0
- data/lib/watir-nokogiri/locators/button_locator.rb +54 -0
- data/lib/watir-nokogiri/locators/child_cell_locator.rb +24 -0
- data/lib/watir-nokogiri/locators/child_row_locator.rb +29 -0
- data/lib/watir-nokogiri/locators/element_locator.rb +298 -0
- data/lib/watir-nokogiri/locators/text_area_locator.rb +20 -0
- data/lib/watir-nokogiri/locators/text_field_locator.rb +71 -0
- data/lib/watir-nokogiri/row_container.rb +42 -0
- data/lib/watir-nokogiri/user_editable.rb +38 -0
- data/lib/watir-nokogiri/version.rb +3 -0
- data/lib/watir-nokogiri/xpath_support.rb +22 -0
- metadata +102 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WatirNokogiri
|
3
|
+
class Hidden < Input
|
4
|
+
def visible?
|
5
|
+
false
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Container
|
10
|
+
def hidden(*args)
|
11
|
+
Hidden.new(self, extract_selector(args).merge(:tag_name => "input", :type => "hidden"))
|
12
|
+
end
|
13
|
+
|
14
|
+
def hiddens(*args)
|
15
|
+
HiddenCollection.new(self, extract_selector(args).merge(:tag_name => "input", :type => "hidden"))
|
16
|
+
end
|
17
|
+
end # Container
|
18
|
+
|
19
|
+
class HiddenCollection < InputCollection
|
20
|
+
def element_class
|
21
|
+
Hidden
|
22
|
+
end
|
23
|
+
end # HiddenCollection
|
24
|
+
end # Nokogiri
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WatirNokogiri
|
3
|
+
class Image < HTMLElement
|
4
|
+
|
5
|
+
#
|
6
|
+
# Returns true if image is loaded.
|
7
|
+
#
|
8
|
+
# @return [Boolean]
|
9
|
+
#
|
10
|
+
|
11
|
+
def loaded?
|
12
|
+
assert_exists
|
13
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Returns the image's width in pixels.
|
18
|
+
#
|
19
|
+
# @return [Fixnum] width
|
20
|
+
#
|
21
|
+
|
22
|
+
def width
|
23
|
+
assert_exists
|
24
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# Returns the image's height in pixels.
|
29
|
+
#
|
30
|
+
# @return [Fixnum] width
|
31
|
+
#
|
32
|
+
|
33
|
+
def height
|
34
|
+
assert_exists
|
35
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
36
|
+
end
|
37
|
+
|
38
|
+
def file_created_date
|
39
|
+
assert_exists
|
40
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
41
|
+
end
|
42
|
+
|
43
|
+
def file_size
|
44
|
+
assert_exists
|
45
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
46
|
+
end
|
47
|
+
|
48
|
+
def save(path)
|
49
|
+
assert_exists
|
50
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
51
|
+
end
|
52
|
+
|
53
|
+
end # Image
|
54
|
+
|
55
|
+
module Container
|
56
|
+
alias_method :image, :img
|
57
|
+
alias_method :images, :imgs
|
58
|
+
end # Container
|
59
|
+
end # WatirNokogiri
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WatirNokogiri
|
3
|
+
class Input < HTMLElement
|
4
|
+
|
5
|
+
alias_method :readonly?, :read_only?
|
6
|
+
|
7
|
+
#
|
8
|
+
# Returns true if input is enabled.
|
9
|
+
#
|
10
|
+
# @return [Boolean]
|
11
|
+
#
|
12
|
+
|
13
|
+
def enabled?
|
14
|
+
!disabled?
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Return the type attribute of the element, or 'text' if the attribute is invalid.
|
19
|
+
# TODO: discuss.
|
20
|
+
#
|
21
|
+
# @return [String]
|
22
|
+
#
|
23
|
+
|
24
|
+
def type
|
25
|
+
assert_exists
|
26
|
+
value = @element.get_attribute("type").to_s
|
27
|
+
|
28
|
+
# we return 'text' if the type is invalid
|
29
|
+
# not sure if we really should do this
|
30
|
+
TextFieldLocator::NON_TEXT_TYPES.include?(value) ? value : 'text'
|
31
|
+
end
|
32
|
+
|
33
|
+
end # Input
|
34
|
+
end # WatirNokogiri
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WatirNokogiri
|
3
|
+
|
4
|
+
#
|
5
|
+
# Represents an option in a select list.
|
6
|
+
#
|
7
|
+
|
8
|
+
class Option < HTMLElement
|
9
|
+
|
10
|
+
#
|
11
|
+
# Selects this option.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# browser.select(:id => "foo").options.first.select
|
15
|
+
#
|
16
|
+
|
17
|
+
def select
|
18
|
+
assert_exists
|
19
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Toggles the selected state of this option.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# browser.select(:id => "foo").options.first.toggle
|
27
|
+
#
|
28
|
+
|
29
|
+
def toggle
|
30
|
+
assert_exists
|
31
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Clears (i.e. toggles selected state) option.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# browser.select(:id => "foo").options.first.clear
|
39
|
+
#
|
40
|
+
|
41
|
+
def clear
|
42
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Is this option selected?
|
47
|
+
#
|
48
|
+
# @return [Boolean]
|
49
|
+
#
|
50
|
+
|
51
|
+
def selected?
|
52
|
+
assert_exists
|
53
|
+
!@element.get_attribute('selected').nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Returns the text of option.
|
58
|
+
#
|
59
|
+
# Note that the text is either one of the following respectively:
|
60
|
+
# * label attribute
|
61
|
+
# * text attribute
|
62
|
+
# * inner element text
|
63
|
+
#
|
64
|
+
# @return [String]
|
65
|
+
#
|
66
|
+
|
67
|
+
def text
|
68
|
+
assert_exists
|
69
|
+
|
70
|
+
# A little unintuitive - we'll return the 'label' or 'text' attribute if
|
71
|
+
# they exist, otherwise the inner text of the element
|
72
|
+
|
73
|
+
attribute = [:label, :text].find { |a| attribute? a }
|
74
|
+
|
75
|
+
if attribute
|
76
|
+
@element.get_attribute(attribute)
|
77
|
+
else
|
78
|
+
@element.text
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end # Option
|
83
|
+
end # WatirNokogiri
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WatirNokogiri
|
3
|
+
class Radio < Input
|
4
|
+
|
5
|
+
#
|
6
|
+
# Selects this radio button.
|
7
|
+
#
|
8
|
+
|
9
|
+
def set
|
10
|
+
assert_exists
|
11
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# Is this radio set?
|
16
|
+
#
|
17
|
+
# @return [Boolean]
|
18
|
+
#
|
19
|
+
|
20
|
+
def set?
|
21
|
+
assert_exists
|
22
|
+
!@element.get_attribute('checked').nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
end # Radio
|
26
|
+
|
27
|
+
module Container
|
28
|
+
def radio(*args)
|
29
|
+
Radio.new(self, extract_selector(args).merge(:tag_name => "input", :type => "radio"))
|
30
|
+
end
|
31
|
+
|
32
|
+
def radios(*args)
|
33
|
+
RadioCollection.new(self, extract_selector(args).merge(:tag_name => "input", :type => "radio" ))
|
34
|
+
end
|
35
|
+
end # Container
|
36
|
+
|
37
|
+
class RadioCollection < InputCollection
|
38
|
+
private
|
39
|
+
|
40
|
+
def element_class
|
41
|
+
Radio
|
42
|
+
end
|
43
|
+
end # RadioCollection
|
44
|
+
end # WatirNokogiri
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WatirNokogiri
|
3
|
+
class Select < HTMLElement
|
4
|
+
include WatirNokogiri::Exception
|
5
|
+
|
6
|
+
#
|
7
|
+
# Returns true if this element is enabled
|
8
|
+
#
|
9
|
+
# @return [Boolean]
|
10
|
+
#
|
11
|
+
|
12
|
+
def enabled?
|
13
|
+
!disabled?
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Clears all selected options.
|
18
|
+
#
|
19
|
+
|
20
|
+
def clear
|
21
|
+
assert_exists
|
22
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Gets all the options in the select list
|
27
|
+
#
|
28
|
+
# @return [Watir::OptionCollection]
|
29
|
+
#
|
30
|
+
|
31
|
+
def options
|
32
|
+
assert_exists
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Returns true if the select list has one or more options where text or label matches the given value.
|
38
|
+
#
|
39
|
+
# @param [String, Regexp] str_or_rx
|
40
|
+
# @return [Boolean]
|
41
|
+
#
|
42
|
+
|
43
|
+
def include?(str_or_rx)
|
44
|
+
assert_exists
|
45
|
+
# TODO: optimize similar to selected?
|
46
|
+
options.any? { |e| str_or_rx === e.text }
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Select the option(s) whose text or label matches the given string.
|
51
|
+
# If this is a multi-select and several options match the value given, all will be selected.
|
52
|
+
#
|
53
|
+
# @param [String, Regexp] str_or_rx
|
54
|
+
# @raise [Watir::Exception::NoValueFoundException] if the value does not exist.
|
55
|
+
# @return [String] The text of the option selected. If multiple options match, returns the first match.
|
56
|
+
#
|
57
|
+
|
58
|
+
def select(str_or_rx)
|
59
|
+
assert_exists
|
60
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Selects the option(s) whose value attribute matches the given string.
|
65
|
+
#
|
66
|
+
# @see +select+
|
67
|
+
#
|
68
|
+
# @param [String, Regexp] str_or_rx
|
69
|
+
# @raise [Watir::Exception::NoValueFoundException] if the value does not exist.
|
70
|
+
# @return [String] The option selected. If multiple options match, returns the first match
|
71
|
+
#
|
72
|
+
|
73
|
+
def select_value(str_or_rx)
|
74
|
+
assert_exists
|
75
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Returns true if any of the selected options' text or label matches the given value.
|
80
|
+
#
|
81
|
+
# @param [String, Regexp] str_or_rx
|
82
|
+
# @raise [Watir::Exception::UnknownObjectException] if the options do not exist
|
83
|
+
# @return [Boolean]
|
84
|
+
#
|
85
|
+
|
86
|
+
def selected?(str_or_rx)
|
87
|
+
assert_exists
|
88
|
+
matches = options.select { |e| str_or_rx === e.text || str_or_rx === e.attribute_value(:label) }
|
89
|
+
|
90
|
+
if matches.empty?
|
91
|
+
raise UnknownObjectException, "Unable to locate option matching #{str_or_rx.inspect}"
|
92
|
+
end
|
93
|
+
|
94
|
+
matches.any? { |e| e.selected? }
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Returns the value of the first selected option in the select list.
|
99
|
+
# Returns nil if no option is selected.
|
100
|
+
#
|
101
|
+
# @return [String, nil]
|
102
|
+
#
|
103
|
+
|
104
|
+
def value
|
105
|
+
o = options.find { |e| e.selected? } || return
|
106
|
+
o.value
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# Returns an array of currently selected options.
|
111
|
+
#
|
112
|
+
# @return [Array<Watir::Option>]
|
113
|
+
#
|
114
|
+
|
115
|
+
def selected_options
|
116
|
+
assert_exists
|
117
|
+
options.select { |e| e.selected? }
|
118
|
+
end
|
119
|
+
|
120
|
+
end # Select
|
121
|
+
|
122
|
+
module Container
|
123
|
+
alias_method :select_list, :select
|
124
|
+
alias_method :select_lists, :selects
|
125
|
+
end # Container
|
126
|
+
end # Watir
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module WatirNokogiri
|
4
|
+
class Table < HTMLElement
|
5
|
+
include RowContainer
|
6
|
+
|
7
|
+
#
|
8
|
+
# Represents table rows as hashes
|
9
|
+
#
|
10
|
+
# @return [Array<Hash>]
|
11
|
+
#
|
12
|
+
|
13
|
+
def hashes
|
14
|
+
all_rows = rows.to_a
|
15
|
+
header_row = all_rows.shift or raise Exception::Error, "no rows in table"
|
16
|
+
|
17
|
+
headers = header_row.ths.map { |header_cell| header_cell.text }
|
18
|
+
result = []
|
19
|
+
|
20
|
+
all_rows.each_with_index do |row, idx|
|
21
|
+
cells = row.cells.to_a
|
22
|
+
if cells.length != headers.length
|
23
|
+
raise Exception::Error, "row at index #{idx} has #{cells.length} cells, expected #{headers.length}"
|
24
|
+
end
|
25
|
+
|
26
|
+
result << headers.inject({}) { |res, header| res.merge(header => cells.shift.text) }
|
27
|
+
end
|
28
|
+
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Returns row of this table with given index.
|
34
|
+
#
|
35
|
+
# @param [Fixnum] idx
|
36
|
+
# @return WatirNokogiri::TableRow
|
37
|
+
#
|
38
|
+
|
39
|
+
def [](idx)
|
40
|
+
row(:index, idx)
|
41
|
+
end
|
42
|
+
|
43
|
+
end # Table
|
44
|
+
end # WatirNokogiri
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module WatirNokogiri
|
2
|
+
class TableCell < HTMLElement
|
3
|
+
# @private
|
4
|
+
attr_writer :locator_class
|
5
|
+
|
6
|
+
def locator_class
|
7
|
+
@locator_class || super
|
8
|
+
end
|
9
|
+
|
10
|
+
def colspan
|
11
|
+
value = attribute_value :colspan
|
12
|
+
value != '' ? Integer(value) : 1
|
13
|
+
end
|
14
|
+
end # TableCell
|
15
|
+
|
16
|
+
class TableCellCollection < ElementCollection
|
17
|
+
attr_writer :locator_class
|
18
|
+
|
19
|
+
def locator_class
|
20
|
+
@locator_class || super
|
21
|
+
end
|
22
|
+
|
23
|
+
def elements
|
24
|
+
# we do this craziness since the xpath used will find direct child rows
|
25
|
+
# before any rows inside thead/tbody/tfoot...
|
26
|
+
elements = super
|
27
|
+
|
28
|
+
if locator_class == ChildCellLocator
|
29
|
+
elements = elements.sort_by { |row| row.get_attribute(:cellIndex).to_i }
|
30
|
+
end
|
31
|
+
|
32
|
+
elements
|
33
|
+
end
|
34
|
+
|
35
|
+
end # TableCellCollection
|
36
|
+
end # WatirNokogiri
|