watir-webdriver 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -1
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/watir-webdriver.rb +6 -7
- data/lib/watir-webdriver/attribute_helper.rb +17 -10
- data/lib/watir-webdriver/browser.rb +1 -1
- data/lib/watir-webdriver/cell_container.rb +19 -0
- data/lib/watir-webdriver/container.rb +8 -0
- data/lib/watir-webdriver/element_collection.rb +2 -2
- data/lib/watir-webdriver/elements/button.rb +3 -2
- data/lib/watir-webdriver/elements/element.rb +41 -1
- data/lib/watir-webdriver/elements/generated.rb +3 -3
- data/lib/watir-webdriver/elements/input.rb +0 -52
- data/lib/watir-webdriver/elements/select.rb +0 -1
- data/lib/watir-webdriver/elements/table.rb +26 -4
- data/lib/watir-webdriver/elements/table_cell.rb +36 -0
- data/lib/watir-webdriver/elements/table_row.rb +23 -14
- data/lib/watir-webdriver/elements/table_section.rb +9 -0
- data/lib/watir-webdriver/extensions/alerts.rb +69 -0
- data/lib/watir-webdriver/extensions/performance.rb +54 -0
- data/lib/watir-webdriver/locators/button_locator.rb +3 -5
- data/lib/watir-webdriver/locators/{table_row_locator.rb → child_cell_locator.rb} +11 -6
- data/lib/watir-webdriver/locators/child_row_locator.rb +37 -0
- data/lib/watir-webdriver/locators/element_locator.rb +24 -14
- data/lib/watir-webdriver/row_container.rb +19 -0
- data/lib/watir-webdriver/window_switching.rb +37 -10
- data/spec/alert_spec.rb +49 -0
- data/spec/element_locator_spec.rb +15 -16
- data/spec/element_spec.rb +0 -32
- data/spec/html/alerts.html +11 -0
- data/spec/input_spec.rb +8 -46
- data/spec/locator_spec_helper.rb +19 -5
- data/spec/spec_helper.rb +3 -0
- data/spec/watirspec/areas_spec.rb +8 -0
- data/spec/watirspec/browser_spec.rb +4 -4
- data/spec/watirspec/button_spec.rb +3 -4
- data/spec/watirspec/buttons_spec.rb +8 -0
- data/spec/watirspec/checkboxes_spec.rb +8 -0
- data/spec/watirspec/dds_spec.rb +8 -0
- data/spec/watirspec/dels_spec.rb +8 -0
- data/spec/watirspec/divs_spec.rb +8 -0
- data/spec/watirspec/dls_spec.rb +8 -0
- data/spec/watirspec/dts_spec.rb +8 -0
- data/spec/watirspec/element_spec.rb +71 -2
- data/spec/watirspec/ems_spec.rb +8 -0
- data/spec/watirspec/filefield_spec.rb +16 -11
- data/spec/watirspec/filefields_spec.rb +8 -0
- data/spec/watirspec/font_spec.rb +21 -19
- data/spec/watirspec/form_spec.rb +5 -3
- data/spec/watirspec/forms_spec.rb +11 -5
- data/spec/watirspec/frames_spec.rb +8 -0
- data/spec/watirspec/hiddens_spec.rb +8 -0
- data/spec/watirspec/hns_spec.rb +8 -0
- data/spec/watirspec/images_spec.rb +8 -0
- data/spec/watirspec/inses_spec.rb +8 -0
- data/spec/watirspec/label_spec.rb +2 -0
- data/spec/watirspec/labels_spec.rb +8 -0
- data/spec/watirspec/lib/server.rb +19 -1
- data/spec/watirspec/lib/spec_helper.rb +1 -1
- data/spec/watirspec/links_spec.rb +8 -0
- data/spec/watirspec/lis_spec.rb +8 -0
- data/spec/watirspec/maps_spec.rb +8 -0
- data/spec/watirspec/metas_spec.rb +8 -0
- data/spec/watirspec/ols_spec.rb +8 -0
- data/spec/watirspec/pres_spec.rb +8 -0
- data/spec/watirspec/ps_spec.rb +8 -0
- data/spec/watirspec/radios_spec.rb +8 -0
- data/spec/watirspec/select_list_spec.rb +6 -6
- data/spec/watirspec/select_lists_spec.rb +8 -0
- data/spec/watirspec/spans_spec.rb +8 -0
- data/spec/watirspec/strongs_spec.rb +8 -0
- data/spec/watirspec/table_nesting_spec.rb +50 -0
- data/spec/watirspec/table_spec.rb +62 -102
- data/spec/watirspec/tables_spec.rb +8 -0
- data/spec/watirspec/{table_body_spec.rb → tbody_spec.rb} +21 -31
- data/spec/watirspec/{table_bodies_spec.rb → tbodys_spec.rb} +8 -0
- data/spec/watirspec/td_spec.rb +72 -0
- data/spec/watirspec/{table_cells_spec.rb → tds_spec.rb} +18 -25
- data/spec/watirspec/text_fields_spec.rb +8 -0
- data/spec/watirspec/{table_footer_spec.rb → tfoot_spec.rb} +21 -28
- data/spec/watirspec/{table_footers_spec.rb → tfoots_spec.rb} +8 -0
- data/spec/watirspec/{table_header_spec.rb → thead_spec.rb} +21 -29
- data/spec/watirspec/{table_headers_spec.rb → theads_spec.rb} +8 -0
- data/spec/watirspec/tr_spec.rb +88 -0
- data/spec/watirspec/trs_spec.rb +68 -0
- data/spec/watirspec/uls_spec.rb +8 -0
- data/spec/watirspec/window_switching_spec.rb +165 -0
- data/support/html5.html +884 -422
- data/watir-webdriver.gemspec +91 -85
- metadata +159 -161
- data/Gemfile.lock +0 -48
- data/spec/html/closeable.html +0 -13
- data/spec/html/data_attributes.html +0 -9
- data/spec/html/window_switching.html +0 -12
- data/spec/watirspec/table_cell_spec.rb +0 -74
- data/spec/watirspec/table_row_spec.rb +0 -99
- data/spec/watirspec/table_rows_spec.rb +0 -60
- data/spec/window_switching_spec.rb +0 -116
data/README.rdoc
CHANGED
@@ -22,10 +22,18 @@ http://jarib.github.com/watir-webdriver/doc/
|
|
22
22
|
|
23
23
|
The file in lib/watir/elements/generated.rb is autogenerated from the HTML5 spec. This is done by extracting the IDL parts from the spec and processing them with the WebIDL gem (link below).
|
24
24
|
|
25
|
+
= Specs
|
26
|
+
|
27
|
+
watir-webdriver uses the watir2 branch of watirspec for testing. After cloning, you should fetch the submodule:
|
28
|
+
|
29
|
+
git submodule init && git submodule update
|
30
|
+
|
31
|
+
Specs specific to watir-webdriver are found in spec/*_spec.rb, with watirspec in spec/watirspec.
|
32
|
+
|
25
33
|
= See also
|
26
34
|
|
27
35
|
* http://github.com/jarib/webidl
|
28
|
-
* http://
|
36
|
+
* http://github.com/jarib/watirspec/tree/watir2
|
29
37
|
* http://selenium.googlecode.com
|
30
38
|
|
31
39
|
= Dependencies
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/jarib/watir-webdriver"
|
12
12
|
gem.authors = ["Jari Bakken"]
|
13
13
|
|
14
|
-
gem.add_dependency "selenium-webdriver", '
|
14
|
+
gem.add_dependency "selenium-webdriver", '0.0.28'
|
15
15
|
|
16
16
|
gem.add_development_dependency "rspec"
|
17
17
|
gem.add_development_dependency "yard", "~> 0.6"
|
@@ -118,6 +118,7 @@ namespace :html5 do
|
|
118
118
|
mv "#{file}.new", file
|
119
119
|
end
|
120
120
|
|
121
|
+
task :update => [:download, :generate, :overwrite]
|
121
122
|
end # html5
|
122
123
|
|
123
124
|
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/watir-webdriver.rb
CHANGED
@@ -10,7 +10,8 @@ require "watir-webdriver/container"
|
|
10
10
|
require "watir-webdriver/locators/element_locator"
|
11
11
|
require "watir-webdriver/locators/button_locator"
|
12
12
|
require "watir-webdriver/locators/text_field_locator"
|
13
|
-
require "watir-webdriver/locators/
|
13
|
+
require "watir-webdriver/locators/child_row_locator"
|
14
|
+
require "watir-webdriver/locators/child_cell_locator"
|
14
15
|
require "watir-webdriver/browser"
|
15
16
|
|
16
17
|
module Watir
|
@@ -29,6 +30,8 @@ module Watir
|
|
29
30
|
end
|
30
31
|
|
31
32
|
require "watir-webdriver/attribute_helper"
|
33
|
+
require "watir-webdriver/row_container"
|
34
|
+
require "watir-webdriver/cell_container"
|
32
35
|
require "watir-webdriver/element_collection"
|
33
36
|
require "watir-webdriver/elements/element"
|
34
37
|
require "watir-webdriver/elements/generated"
|
@@ -48,18 +51,14 @@ require "watir-webdriver/elements/form"
|
|
48
51
|
require "watir-webdriver/elements/option"
|
49
52
|
require "watir-webdriver/elements/table"
|
50
53
|
require "watir-webdriver/elements/table_row"
|
54
|
+
require "watir-webdriver/elements/table_cell"
|
55
|
+
require "watir-webdriver/elements/table_section"
|
51
56
|
|
52
57
|
Watir.tag_to_class.freeze
|
53
58
|
|
54
59
|
module Watir
|
55
60
|
module Container
|
56
61
|
|
57
|
-
# TODO: deprecate cell/row in favor of td/tr?
|
58
|
-
alias_method :cell, :td
|
59
|
-
alias_method :cells, :tds
|
60
|
-
alias_method :row, :tr
|
61
|
-
alias_method :rows, :trs
|
62
|
-
|
63
62
|
end # Container
|
64
63
|
end # Watir
|
65
64
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Watir
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
# @private
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# Extended by Element, provides methods for defining attributes on the element classes.
|
7
|
-
#
|
8
|
-
|
7
|
+
#
|
8
|
+
|
9
9
|
module AttributeHelper
|
10
|
-
|
10
|
+
|
11
11
|
IGNORED_ATTRIBUTES = [:text, :hash]
|
12
|
-
|
12
|
+
|
13
13
|
def typed_attributes
|
14
14
|
@typed_attributes ||= Hash.new { |hash, type| hash[type] = [] }
|
15
15
|
end
|
@@ -74,7 +74,8 @@ module Watir
|
|
74
74
|
def define_int_attribute(mname, aname)
|
75
75
|
define_method mname do
|
76
76
|
assert_exists
|
77
|
-
@element.attribute(aname)
|
77
|
+
value = @element.attribute(aname)
|
78
|
+
value && Integer(value)
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
@@ -85,7 +86,7 @@ module Watir
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def method_name_for(type, attribute)
|
88
|
-
#
|
89
|
+
# http://github.com/jarib/watir-webdriver/issues/issue/26
|
89
90
|
name = case attribute
|
90
91
|
when :html_for
|
91
92
|
'for'
|
@@ -103,6 +104,8 @@ module Watir
|
|
103
104
|
end
|
104
105
|
|
105
106
|
def attribute_for_method(method)
|
107
|
+
# http://github.com/jarib/watir-webdriver/issues/issue/26
|
108
|
+
|
106
109
|
case method.to_sym
|
107
110
|
when :class_name
|
108
111
|
'class'
|
@@ -112,10 +115,14 @@ module Watir
|
|
112
115
|
'readonly'
|
113
116
|
when :http_equiv
|
114
117
|
'http-equiv'
|
118
|
+
when :col_span
|
119
|
+
'colspan'
|
120
|
+
when :row_span
|
121
|
+
'rowspan'
|
115
122
|
else
|
116
123
|
method.to_s
|
117
124
|
end
|
118
125
|
end
|
119
|
-
|
126
|
+
|
120
127
|
end # AttributeHelper
|
121
|
-
end # Watir
|
128
|
+
end # Watir
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Watir
|
2
|
+
module CellContainer
|
3
|
+
|
4
|
+
def cell(*args)
|
5
|
+
cell = TableCell.new(self, extract_selector(args).merge(:tag_name => /^(th|td)$/))
|
6
|
+
cell.locator_class = ChildCellLocator
|
7
|
+
|
8
|
+
cell
|
9
|
+
end
|
10
|
+
|
11
|
+
def cells(*args)
|
12
|
+
cells = TableCellCollection.new(self, extract_selector(args).merge(:tag_name => /^(th|td)$/))
|
13
|
+
cells.locator_class = ChildCellLocator
|
14
|
+
|
15
|
+
cells
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -3,6 +3,14 @@ module Watir
|
|
3
3
|
module Container
|
4
4
|
include XpathSupport
|
5
5
|
|
6
|
+
def element(*args)
|
7
|
+
HTMLElement.new(self, extract_selector(args))
|
8
|
+
end
|
9
|
+
|
10
|
+
def elements(*args)
|
11
|
+
HTMLElementCollection.new(self, extract_selector(args))
|
12
|
+
end
|
13
|
+
|
6
14
|
private
|
7
15
|
|
8
16
|
def browserbot(function_name, *arguments)
|
@@ -53,7 +53,7 @@ module Watir
|
|
53
53
|
#
|
54
54
|
|
55
55
|
def first
|
56
|
-
|
56
|
+
self[0]
|
57
57
|
end
|
58
58
|
|
59
59
|
#
|
@@ -63,7 +63,7 @@ module Watir
|
|
63
63
|
#
|
64
64
|
|
65
65
|
def last
|
66
|
-
|
66
|
+
self[-1]
|
67
67
|
end
|
68
68
|
|
69
69
|
#
|
@@ -12,13 +12,14 @@ module Watir
|
|
12
12
|
# add the attributes from <input>
|
13
13
|
attributes Watir::Input.typed_attributes
|
14
14
|
|
15
|
+
VALID_TYPES = %w[button reset submit image]
|
15
16
|
|
16
17
|
def self.from(parent, element)
|
17
18
|
if element.tag_name == "button" ||
|
18
|
-
element.tag_name == "input" &&
|
19
|
+
element.tag_name == "input" && VALID_TYPES.include?(element.attribute(:type))
|
19
20
|
Button.new(parent, :element => element)
|
20
21
|
else
|
21
|
-
raise TypeError, "expected button or input[@type=#{
|
22
|
+
raise TypeError, "expected button or input[@type=#{VALID_TYPES.join("|")}] for #{element.inspect}"
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
@@ -42,6 +42,8 @@ module Watir
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def ==(other)
|
45
|
+
return false unless other.kind_of? self.class
|
46
|
+
|
45
47
|
assert_exists
|
46
48
|
@element == other.element
|
47
49
|
end
|
@@ -173,6 +175,40 @@ module Watir
|
|
173
175
|
@parent.run_checkers
|
174
176
|
end
|
175
177
|
|
178
|
+
#
|
179
|
+
# Cast this Element instance to a more specific subtype.
|
180
|
+
#
|
181
|
+
# Example:
|
182
|
+
#
|
183
|
+
# browser.element(:xpath => "//input[@type='submit']").to_subtype #=> #<Watir::Button>
|
184
|
+
#
|
185
|
+
|
186
|
+
def to_subtype
|
187
|
+
elem = element()
|
188
|
+
tag_name = elem.tag_name
|
189
|
+
|
190
|
+
klass = nil
|
191
|
+
|
192
|
+
if tag_name == "input"
|
193
|
+
klass = case elem.attribute(:type)
|
194
|
+
when *Button::VALID_TYPES
|
195
|
+
Button
|
196
|
+
when 'checkbox'
|
197
|
+
CheckBox
|
198
|
+
when 'radio'
|
199
|
+
Radio
|
200
|
+
when 'file'
|
201
|
+
FileField
|
202
|
+
else
|
203
|
+
TextField
|
204
|
+
end
|
205
|
+
else
|
206
|
+
klass = Watir.element_class_for(tag_name)
|
207
|
+
end
|
208
|
+
|
209
|
+
klass.new(@parent, :element => elem)
|
210
|
+
end
|
211
|
+
|
176
212
|
protected
|
177
213
|
|
178
214
|
def assert_exists
|
@@ -189,11 +225,15 @@ module Watir
|
|
189
225
|
|
190
226
|
def locate
|
191
227
|
@parent.assert_exists
|
192
|
-
|
228
|
+
locator_class.new(@parent.wd, @selector, self.class.attribute_list).locate
|
193
229
|
end
|
194
230
|
|
195
231
|
private
|
196
232
|
|
233
|
+
def locator_class
|
234
|
+
ElementLocator
|
235
|
+
end
|
236
|
+
|
197
237
|
def selector_string
|
198
238
|
@selector.inspect
|
199
239
|
end
|
@@ -74,7 +74,7 @@ module Watir
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
class Frame < HTMLElement
|
77
|
-
attributes(:string => [:frame_border, :long_desc, :margin_height, :margin_width, :name, :scrolling, :src], :bool => [:no_resize], :document => [:content_document])
|
77
|
+
attributes(:string => [:frame_border, :long_desc, :margin_height, :margin_width, :name, :scrolling, :src, :content_window], :bool => [:no_resize], :document => [:content_document])
|
78
78
|
end
|
79
79
|
class FrameCollection < ElementCollection
|
80
80
|
def element_class
|
@@ -90,7 +90,7 @@ module Watir
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
class Marquee < HTMLElement
|
93
|
-
attributes(:string => [:behavior, :bg_color, :direction, :height, :
|
93
|
+
attributes(:string => [:behavior, :bg_color, :direction, :height, :width], :int => [:hspace, :loop, :scroll_amount, :scroll_delay, :vspace], :bool => [:true_speed], :function => [:onbounce, :onfinish, :onstart])
|
94
94
|
end
|
95
95
|
class MarqueeCollection < ElementCollection
|
96
96
|
def element_class
|
@@ -410,7 +410,7 @@ module Watir
|
|
410
410
|
end
|
411
411
|
end
|
412
412
|
class Track < HTMLElement
|
413
|
-
attributes(:string => [:kind, :
|
413
|
+
attributes(:string => [:kind, :src, :charset, :srclang, :label, :track])
|
414
414
|
end
|
415
415
|
class TrackCollection < ElementCollection
|
416
416
|
def element_class
|
@@ -38,57 +38,5 @@ module Watir
|
|
38
38
|
TextFieldLocator::NON_TEXT_TYPES.include?(value) ? value : 'text'
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
42
|
-
# not sure about this
|
43
|
-
#
|
44
|
-
# this is mostly useful if you're using Browser#element_by_xpath, and want to
|
45
|
-
# 'cast' the returned Input instance to one of the subclasses
|
46
|
-
#
|
47
|
-
|
48
|
-
#
|
49
|
-
# @return [Watir::CheckBox]
|
50
|
-
#
|
51
|
-
|
52
|
-
def to_checkbox
|
53
|
-
assert_exists
|
54
|
-
CheckBox.from(@parent, @element)
|
55
|
-
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# @return [Watir::Radio]
|
59
|
-
#
|
60
|
-
|
61
|
-
def to_radio
|
62
|
-
assert_exists
|
63
|
-
Radio.from(@parent, @element)
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# @return [Watir::Button]
|
68
|
-
#
|
69
|
-
|
70
|
-
def to_button
|
71
|
-
assert_exists
|
72
|
-
Button.from(@parent, @element)
|
73
|
-
end
|
74
|
-
|
75
|
-
#
|
76
|
-
# @return [Watir::TextField]
|
77
|
-
#
|
78
|
-
|
79
|
-
def to_text_field
|
80
|
-
assert_exists
|
81
|
-
TextField.from(@parent, @element)
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# @return [Watir::FileField]
|
86
|
-
#
|
87
|
-
|
88
|
-
def to_file_field
|
89
|
-
assert_exists
|
90
|
-
FileField.from(@parent, @element)
|
91
|
-
end
|
92
|
-
|
93
41
|
end # Input
|
94
42
|
end # Watir
|
@@ -1,19 +1,41 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
module Watir
|
3
4
|
class Table < HTMLElement
|
5
|
+
include RowContainer
|
4
6
|
|
5
7
|
#
|
6
|
-
# The table as
|
8
|
+
# The table as a 2D Array of strings with the text of each cell.
|
7
9
|
#
|
8
10
|
# @return [Array<Array<String>>]
|
9
11
|
#
|
10
12
|
|
11
|
-
def
|
13
|
+
def strings
|
12
14
|
assert_exists
|
13
15
|
|
14
|
-
|
15
|
-
res << row.
|
16
|
+
rows.inject [] do |res, row|
|
17
|
+
res << row.cells.map { |cell| cell.text }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias_method :to_a, :strings
|
21
|
+
|
22
|
+
def hashes
|
23
|
+
all_rows = rows.to_a
|
24
|
+
header_row = all_rows.shift or raise Exception::Error, "no rows in table"
|
25
|
+
|
26
|
+
headers = header_row.ths.map { |header_cell| header_cell.text }
|
27
|
+
result = []
|
28
|
+
|
29
|
+
all_rows.each_with_index do |row, idx|
|
30
|
+
cells = row.cells.to_a
|
31
|
+
if cells.length != headers.length
|
32
|
+
raise Exception::Error, "row at index #{idx} has #{cells.length} cells, expected #{headers.length}"
|
33
|
+
end
|
34
|
+
|
35
|
+
result << headers.inject({}) { |res, header| res.merge(header => cells.shift.text) }
|
16
36
|
end
|
37
|
+
|
38
|
+
result
|
17
39
|
end
|
18
40
|
|
19
41
|
#
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Watir
|
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
|
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.attribute(:cellIndex).to_i }
|
30
|
+
end
|
31
|
+
|
32
|
+
elements
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|