watir-webdriver 0.0.1.dev
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/.document +5 -0
- data/.gitignore +5 -0
- data/.gitmodules +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +32 -0
- data/Rakefile +107 -0
- data/TODO +15 -0
- data/VERSION +1 -0
- data/lib/watir-webdriver.rb +74 -0
- data/lib/watir-webdriver/base_element.rb +347 -0
- data/lib/watir-webdriver/browser.rb +130 -0
- data/lib/watir-webdriver/browserbot.js +34 -0
- data/lib/watir-webdriver/collections/buttons_collection.rb +13 -0
- data/lib/watir-webdriver/collections/element_collection.rb +45 -0
- data/lib/watir-webdriver/collections/table_rows_collection.rb +14 -0
- data/lib/watir-webdriver/collections/text_fields_collection.rb +13 -0
- data/lib/watir-webdriver/container.rb +24 -0
- data/lib/watir-webdriver/core_ext/string.rb +22 -0
- data/lib/watir-webdriver/elements/button.rb +27 -0
- data/lib/watir-webdriver/elements/checkbox.rb +23 -0
- data/lib/watir-webdriver/elements/file_field.rb +20 -0
- data/lib/watir-webdriver/elements/form.rb +11 -0
- data/lib/watir-webdriver/elements/generated.rb +941 -0
- data/lib/watir-webdriver/elements/headings.rb +48 -0
- data/lib/watir-webdriver/elements/hidden.rb +18 -0
- data/lib/watir-webdriver/elements/image.rb +33 -0
- data/lib/watir-webdriver/elements/input.rb +39 -0
- data/lib/watir-webdriver/elements/link.rb +13 -0
- data/lib/watir-webdriver/elements/option.rb +36 -0
- data/lib/watir-webdriver/elements/radio.rb +23 -0
- data/lib/watir-webdriver/elements/select_list.rb +73 -0
- data/lib/watir-webdriver/elements/shared_radio_checkbox.rb +13 -0
- data/lib/watir-webdriver/elements/table.rb +18 -0
- data/lib/watir-webdriver/elements/table_row.rb +17 -0
- data/lib/watir-webdriver/elements/text_field.rb +60 -0
- data/lib/watir-webdriver/exception.rb +20 -0
- data/lib/watir-webdriver/locators/button_locator.rb +57 -0
- data/lib/watir-webdriver/locators/element_locator.rb +269 -0
- data/lib/watir-webdriver/locators/table_row_locator.rb +25 -0
- data/lib/watir-webdriver/locators/text_field_locator.rb +61 -0
- data/lib/watir-webdriver/xpath_support.rb +23 -0
- data/spec/element_locator_spec.rb +11 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/watirspec/area_spec.rb +78 -0
- data/spec/watirspec/areas_spec.rb +31 -0
- data/spec/watirspec/browser_spec.rb +262 -0
- data/spec/watirspec/button_spec.rb +242 -0
- data/spec/watirspec/buttons_spec.rb +48 -0
- data/spec/watirspec/checkbox_spec.rb +272 -0
- data/spec/watirspec/checkboxes_spec.rb +32 -0
- data/spec/watirspec/dd_spec.rb +136 -0
- data/spec/watirspec/dds_spec.rb +31 -0
- data/spec/watirspec/div_spec.rb +222 -0
- data/spec/watirspec/divs_spec.rb +31 -0
- data/spec/watirspec/dl_spec.rb +136 -0
- data/spec/watirspec/dls_spec.rb +32 -0
- data/spec/watirspec/dt_spec.rb +136 -0
- data/spec/watirspec/dts_spec.rb +31 -0
- data/spec/watirspec/element_spec.rb +87 -0
- data/spec/watirspec/em_spec.rb +110 -0
- data/spec/watirspec/ems_spec.rb +32 -0
- data/spec/watirspec/filefield_spec.rb +119 -0
- data/spec/watirspec/filefields_spec.rb +32 -0
- data/spec/watirspec/form_spec.rb +63 -0
- data/spec/watirspec/forms_spec.rb +33 -0
- data/spec/watirspec/frame_spec.rb +140 -0
- data/spec/watirspec/frames_spec.rb +62 -0
- data/spec/watirspec/hidden_spec.rb +102 -0
- data/spec/watirspec/hiddens_spec.rb +32 -0
- data/spec/watirspec/hn_spec.rb +93 -0
- data/spec/watirspec/hns_spec.rb +38 -0
- data/spec/watirspec/image_spec.rb +207 -0
- data/spec/watirspec/images_spec.rb +31 -0
- data/spec/watirspec/label_spec.rb +75 -0
- data/spec/watirspec/labels_spec.rb +31 -0
- data/spec/watirspec/li_spec.rb +127 -0
- data/spec/watirspec/lib/guards.rb +59 -0
- data/spec/watirspec/lib/server.rb +127 -0
- data/spec/watirspec/lib/spec_helper.rb +79 -0
- data/spec/watirspec/lib/watirspec.rb +72 -0
- data/spec/watirspec/link_spec.rb +165 -0
- data/spec/watirspec/links_spec.rb +35 -0
- data/spec/watirspec/lis_spec.rb +31 -0
- data/spec/watirspec/map_spec.rb +92 -0
- data/spec/watirspec/maps_spec.rb +32 -0
- data/spec/watirspec/meta_spec.rb +22 -0
- data/spec/watirspec/metas_spec.rb +30 -0
- data/spec/watirspec/ol_spec.rb +78 -0
- data/spec/watirspec/ols_spec.rb +31 -0
- data/spec/watirspec/option_spec.rb +173 -0
- data/spec/watirspec/p_spec.rb +143 -0
- data/spec/watirspec/pre_spec.rb +125 -0
- data/spec/watirspec/pres_spec.rb +31 -0
- data/spec/watirspec/ps_spec.rb +31 -0
- data/spec/watirspec/radio_spec.rb +278 -0
- data/spec/watirspec/radios_spec.rb +32 -0
- data/spec/watirspec/select_list_spec.rb +318 -0
- data/spec/watirspec/select_lists_spec.rb +35 -0
- data/spec/watirspec/span_spec.rb +157 -0
- data/spec/watirspec/spans_spec.rb +57 -0
- data/spec/watirspec/spec_helper.rb +17 -0
- data/spec/watirspec/strong_spec.rb +89 -0
- data/spec/watirspec/strongs_spec.rb +32 -0
- data/spec/watirspec/table_bodies_spec.rb +45 -0
- data/spec/watirspec/table_body_spec.rb +98 -0
- data/spec/watirspec/table_cell_spec.rb +68 -0
- data/spec/watirspec/table_cells_spec.rb +47 -0
- data/spec/watirspec/table_footer_spec.rb +85 -0
- data/spec/watirspec/table_footers_spec.rb +47 -0
- data/spec/watirspec/table_header_spec.rb +85 -0
- data/spec/watirspec/table_headers_spec.rb +45 -0
- data/spec/watirspec/table_row_spec.rb +87 -0
- data/spec/watirspec/table_rows_spec.rb +50 -0
- data/spec/watirspec/table_spec.rb +166 -0
- data/spec/watirspec/tables_spec.rb +33 -0
- data/spec/watirspec/text_field_spec.rb +276 -0
- data/spec/watirspec/text_fields_spec.rb +35 -0
- data/spec/watirspec/ul_spec.rb +76 -0
- data/spec/watirspec/uls_spec.rb +33 -0
- data/spec/xpath_builder_spec.rb +49 -0
- data/support/html5/html5.idl +815 -0
- data/support/html5/html5_extras.idl +147 -0
- data/support/html5/idl_extractor.rb +73 -0
- data/support/html5/watir_visitor.rb +169 -0
- metadata +220 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
|
4
|
+
#
|
5
|
+
# H1 is handled by the generated code
|
6
|
+
#
|
7
|
+
|
8
|
+
|
9
|
+
class H2 < Heading
|
10
|
+
default_selector.clear
|
11
|
+
|
12
|
+
identifier :tag_name => 'h2'
|
13
|
+
container_method :h2
|
14
|
+
collection_method :h2s
|
15
|
+
end
|
16
|
+
|
17
|
+
class H3 < Heading
|
18
|
+
default_selector.clear
|
19
|
+
|
20
|
+
identifier :tag_name => 'h3'
|
21
|
+
container_method :h3
|
22
|
+
collection_method :h3s
|
23
|
+
end
|
24
|
+
|
25
|
+
class H4 < Heading
|
26
|
+
default_selector.clear
|
27
|
+
|
28
|
+
identifier :tag_name => 'h4'
|
29
|
+
container_method :h4
|
30
|
+
collection_method :h4s
|
31
|
+
end
|
32
|
+
|
33
|
+
class H5 < Heading
|
34
|
+
default_selector.clear
|
35
|
+
|
36
|
+
identifier :tag_name => 'h5'
|
37
|
+
container_method :h5
|
38
|
+
collection_method :h5s
|
39
|
+
end
|
40
|
+
|
41
|
+
class H6 < Heading
|
42
|
+
default_selector.clear
|
43
|
+
|
44
|
+
identifier :tag_name => 'h6'
|
45
|
+
container_method :h6
|
46
|
+
collection_method :h6s
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class Hidden < Input
|
4
|
+
identifier :type => 'hidden'
|
5
|
+
|
6
|
+
container_method :hidden
|
7
|
+
collection_method :hiddens
|
8
|
+
|
9
|
+
# deprecate?
|
10
|
+
def value=(val)
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
def visible?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class Image < HTMLElement
|
4
|
+
|
5
|
+
alias_method :loaded?, :complete?
|
6
|
+
|
7
|
+
def width
|
8
|
+
assert_exists
|
9
|
+
driver.execute_script "return arguments[0].width", @element
|
10
|
+
end
|
11
|
+
|
12
|
+
def height
|
13
|
+
assert_exists
|
14
|
+
driver.execute_script "return arguments[0].height", @element
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_created_date
|
18
|
+
assert_exists
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
def file_size
|
23
|
+
assert_exists
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def save(path)
|
28
|
+
assert_exists
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
|
32
|
+
end # Image
|
33
|
+
end # Watir
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class Input
|
4
|
+
|
5
|
+
alias_method :readonly?, :read_only?
|
6
|
+
|
7
|
+
def enabled?
|
8
|
+
!disabled?
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# not sure about this
|
13
|
+
#
|
14
|
+
# this is mostly useful if you're using Browser#element_by_xpath, and want to
|
15
|
+
# 'cast' the returned Input instance to one of the subclasses
|
16
|
+
#
|
17
|
+
|
18
|
+
def to_checkbox
|
19
|
+
assert_exists
|
20
|
+
Watir::CheckBox.new(@parent, :element, @element)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_radio
|
24
|
+
assert_exists
|
25
|
+
Watir::Radio.new(@parent, :element, @element)
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_button
|
29
|
+
assert_exists
|
30
|
+
Watir::Button.new(@parent, :element, @element)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_select_list
|
34
|
+
assert_exists
|
35
|
+
Watir::SelectList.new(@parent, :element, @element)
|
36
|
+
end
|
37
|
+
|
38
|
+
end # Input
|
39
|
+
end # Watir
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class Option < HTMLElement
|
4
|
+
|
5
|
+
def select
|
6
|
+
assert_exists
|
7
|
+
@element.select
|
8
|
+
end
|
9
|
+
|
10
|
+
def toggle
|
11
|
+
assert_exists
|
12
|
+
@element.toggle
|
13
|
+
end
|
14
|
+
|
15
|
+
def selected?
|
16
|
+
assert_exists
|
17
|
+
@element.selected?
|
18
|
+
end
|
19
|
+
|
20
|
+
def text
|
21
|
+
assert_exists
|
22
|
+
|
23
|
+
# A little unintuitive - we'll return the 'label' or 'text' attribute if
|
24
|
+
# they exist, otherwise the inner text of the element
|
25
|
+
|
26
|
+
attribute = [:label, :text].find { |a| attribute? a }
|
27
|
+
|
28
|
+
if attribute
|
29
|
+
@element.attribute(attribute)
|
30
|
+
else
|
31
|
+
@element.text
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end # Option
|
36
|
+
end # Watir
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class Radio < Input
|
4
|
+
include SharedRadioCheckbox
|
5
|
+
|
6
|
+
identifier :type => 'radio' # a text field is the default for input elements, so this needs to be changed
|
7
|
+
|
8
|
+
container_method :radio
|
9
|
+
collection_method :radios
|
10
|
+
|
11
|
+
def set(bool = true)
|
12
|
+
assert_exists
|
13
|
+
assert_enabled
|
14
|
+
|
15
|
+
if set?
|
16
|
+
@element.click unless bool
|
17
|
+
else
|
18
|
+
@element.click if bool
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class SelectList < Select
|
4
|
+
include Watir::Exception
|
5
|
+
|
6
|
+
container_method :select_list
|
7
|
+
collection_method :select_lists
|
8
|
+
|
9
|
+
def enabled?
|
10
|
+
!disabled?
|
11
|
+
end
|
12
|
+
|
13
|
+
def clear
|
14
|
+
assert_exists
|
15
|
+
raise "you can only clear multi-selects" unless multiple?
|
16
|
+
options.each do |o|
|
17
|
+
o.toggle if o.selected?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def includes?(str_or_rx)
|
22
|
+
assert_exists
|
23
|
+
options.any? { |e| str_or_rx === e.text }
|
24
|
+
end
|
25
|
+
|
26
|
+
def select(str_or_rx)
|
27
|
+
select_by :text, str_or_rx
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: deprecate?
|
31
|
+
def select_value(str_or_rx)
|
32
|
+
select_by :value, str_or_rx
|
33
|
+
end
|
34
|
+
|
35
|
+
def selected?(str_or_rx)
|
36
|
+
assert_exists
|
37
|
+
matches = options.select { |e| str_or_rx === e.text }
|
38
|
+
|
39
|
+
if matches.empty?
|
40
|
+
raise UnknownObjectException, "Unable to locate option matching #{str_or_rx.inspect}"
|
41
|
+
end
|
42
|
+
|
43
|
+
matches.any? { |e| e.selected? }
|
44
|
+
end
|
45
|
+
|
46
|
+
def value
|
47
|
+
o = options.find { |e| e.selected? }
|
48
|
+
return if o.nil?
|
49
|
+
|
50
|
+
o.value
|
51
|
+
end
|
52
|
+
|
53
|
+
def selected_options
|
54
|
+
assert_exists
|
55
|
+
options.map { |e| e.text if e.selected? }.compact
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def select_by(how, str_or_rx)
|
61
|
+
assert_exists
|
62
|
+
os = options.select { |e| str_or_rx === e.send(how) }
|
63
|
+
|
64
|
+
if os.empty?
|
65
|
+
raise NoValueFoundException, "#{str_or_rx.inspect} not found in select list"
|
66
|
+
end
|
67
|
+
|
68
|
+
os.each { |e| e.select unless e.selected? }
|
69
|
+
os.first.text
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class Table < HTMLElement
|
4
|
+
|
5
|
+
def to_a
|
6
|
+
assert_exists
|
7
|
+
|
8
|
+
trs.inject [] do |res, row|
|
9
|
+
res << row.tds.map { |cell| cell.text }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def [](idx)
|
14
|
+
row(:index, idx)
|
15
|
+
end
|
16
|
+
|
17
|
+
end # Table
|
18
|
+
end # Watir
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Watir
|
2
|
+
class TableRow < HTMLElement
|
3
|
+
|
4
|
+
def [](idx)
|
5
|
+
td(:index, idx)
|
6
|
+
end
|
7
|
+
|
8
|
+
def locate
|
9
|
+
if @parent.kind_of?(Watir::Table)
|
10
|
+
TableRowLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end # TableRow
|
17
|
+
end # Watir
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class TextField < Input
|
4
|
+
|
5
|
+
# perhaps we'll need a custom locate(), since this should also cover textareas
|
6
|
+
attributes Watir::TextArea.typed_attributes
|
7
|
+
|
8
|
+
container_method :text_field
|
9
|
+
collection_method :text_fields
|
10
|
+
|
11
|
+
def locate
|
12
|
+
TextFieldLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
|
13
|
+
end
|
14
|
+
|
15
|
+
def inspect
|
16
|
+
'#<%s:0x%x located=%s selector=%s>' % [self.class, hash*2, !!@element, selector_without_type.inspect]
|
17
|
+
end
|
18
|
+
|
19
|
+
def selector_string
|
20
|
+
selector_without_type.inspect
|
21
|
+
end
|
22
|
+
|
23
|
+
def set(*args)
|
24
|
+
assert_exists
|
25
|
+
assert_writable
|
26
|
+
|
27
|
+
@element.clear
|
28
|
+
|
29
|
+
append(*args)
|
30
|
+
end
|
31
|
+
alias_method :value=, :set
|
32
|
+
|
33
|
+
def append(*args)
|
34
|
+
assert_exists
|
35
|
+
assert_writable
|
36
|
+
|
37
|
+
@element.send_keys(*args)
|
38
|
+
end
|
39
|
+
|
40
|
+
def clear
|
41
|
+
assert_exists
|
42
|
+
@element.clear
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def value
|
47
|
+
# since 'value' is an attribute on input fields, we override this here
|
48
|
+
assert_exists
|
49
|
+
@element.value
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def selector_without_type
|
55
|
+
s = @selector.dup
|
56
|
+
s[:type] = '(any text type)'
|
57
|
+
s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Watir
|
4
|
+
module Exception
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
# TODO: rename Object -> Element?
|
8
|
+
class UnknownObjectException < Error; end
|
9
|
+
class ObjectDisabledException < Error; end
|
10
|
+
class ObjectReadOnlyException < Error; end
|
11
|
+
class NoValueFoundException < Error; end
|
12
|
+
class MissingWayOfFindingObjectException < Error; end
|
13
|
+
class UnknownCellException < Error; end
|
14
|
+
class NoMatchingWindowFoundException < Error; end
|
15
|
+
class NoStatusBarException < Error; end
|
16
|
+
class NavigationException < Error; end
|
17
|
+
class UnknownFrameException < Error; end
|
18
|
+
|
19
|
+
end # Exception
|
20
|
+
end # Watir
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Watir
|
2
|
+
class ButtonLocator < ElementLocator
|
3
|
+
|
4
|
+
def locate_all
|
5
|
+
find_all_by_multiple
|
6
|
+
end
|
7
|
+
|
8
|
+
def build_xpath(selectors)
|
9
|
+
return if selectors.values.any? { |e| e.kind_of? Regexp }
|
10
|
+
|
11
|
+
selectors.delete(:tag_name) || raise("internal error: no tag_name?!")
|
12
|
+
|
13
|
+
@building = :button
|
14
|
+
button_attr_exp = attribute_expression(selectors)
|
15
|
+
|
16
|
+
@building = :input
|
17
|
+
selectors[:type] = %w[button reset submit image]
|
18
|
+
input_attr_exp = attribute_expression(selectors)
|
19
|
+
|
20
|
+
xpath = ".//button"
|
21
|
+
xpath << "[#{button_attr_exp}]" unless button_attr_exp.empty?
|
22
|
+
xpath << " | .//input"
|
23
|
+
xpath << "[#{input_attr_exp}]"
|
24
|
+
|
25
|
+
p :build_xpath => xpath if $DEBUG
|
26
|
+
|
27
|
+
xpath
|
28
|
+
end
|
29
|
+
|
30
|
+
def lhs_for(key)
|
31
|
+
if @building == :input && key == :text
|
32
|
+
"@value"
|
33
|
+
elsif @building == :button && key == :value
|
34
|
+
"text()"
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def matches_selector?(rx_selector, element)
|
41
|
+
rx_selector = rx_selector.dup
|
42
|
+
|
43
|
+
[:value, :caption].each do |key|
|
44
|
+
if rx_selector.has_key?(key)
|
45
|
+
correct_key = element.tag_name == 'button' ? :text : :value
|
46
|
+
rx_selector[correct_key] = rx_selector.delete(key)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
super
|
51
|
+
end
|
52
|
+
|
53
|
+
def tag_name_matches?(element, _)
|
54
|
+
!!(/^(input|button)$/ === element.tag_name)
|
55
|
+
end
|
56
|
+
end # ButtonLocator
|
57
|
+
end # Watir
|