watir-webdriver 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +1 -0
  3. data/CHANGES.md +1693 -0
  4. data/Gemfile +0 -1
  5. data/Rakefile +22 -0
  6. data/lib/watir-webdriver/alert.rb +46 -0
  7. data/lib/watir-webdriver/aliases.rb +2 -2
  8. data/lib/watir-webdriver/atoms.rb +2 -2
  9. data/lib/watir-webdriver/atoms/README +0 -1
  10. data/lib/watir-webdriver/browser.rb +195 -14
  11. data/lib/watir-webdriver/cell_container.rb +14 -2
  12. data/lib/watir-webdriver/container.rb +22 -0
  13. data/lib/watir-webdriver/cookies.rb +41 -0
  14. data/lib/watir-webdriver/element_collection.rb +13 -3
  15. data/lib/watir-webdriver/elements/button.rb +3 -1
  16. data/lib/watir-webdriver/elements/checkbox.rb +8 -6
  17. data/lib/watir-webdriver/elements/dlist.rb +4 -4
  18. data/lib/watir-webdriver/elements/element.rb +153 -28
  19. data/lib/watir-webdriver/elements/file_field.rb +6 -4
  20. data/lib/watir-webdriver/elements/generated.rb +12 -8
  21. data/lib/watir-webdriver/elements/image.rb +10 -5
  22. data/lib/watir-webdriver/elements/input.rb +6 -0
  23. data/lib/watir-webdriver/elements/option.rb +28 -2
  24. data/lib/watir-webdriver/elements/radio.rb +5 -1
  25. data/lib/watir-webdriver/elements/select.rb +11 -9
  26. data/lib/watir-webdriver/elements/table.rb +8 -1
  27. data/lib/watir-webdriver/elements/table_cell.rb +3 -3
  28. data/lib/watir-webdriver/elements/table_row.rb +0 -1
  29. data/lib/watir-webdriver/elements/table_section.rb +8 -2
  30. data/lib/watir-webdriver/elements/text_area.rb +2 -2
  31. data/lib/watir-webdriver/elements/text_field.rb +2 -2
  32. data/lib/watir-webdriver/extensions/alerts.rb +3 -3
  33. data/lib/watir-webdriver/extensions/nokogiri.rb +2 -2
  34. data/lib/watir-webdriver/extensions/select_text.rb +2 -2
  35. data/lib/watir-webdriver/has_window.rb +23 -1
  36. data/lib/watir-webdriver/html.rb +2 -0
  37. data/lib/watir-webdriver/html/visitor.rb +2 -2
  38. data/lib/watir-webdriver/locators/element_locator.rb +8 -0
  39. data/lib/watir-webdriver/locators/text_field_locator.rb +1 -1
  40. data/lib/watir-webdriver/row_container.rb +11 -3
  41. data/lib/watir-webdriver/screenshot.rb +11 -0
  42. data/lib/watir-webdriver/user_editable.rb +10 -4
  43. data/lib/watir-webdriver/version.rb +2 -2
  44. data/lib/watir-webdriver/wait.rb +32 -11
  45. data/lib/watir-webdriver/window.rb +104 -1
  46. data/lib/watir-webdriver/xpath_support.rb +4 -0
  47. data/lib/yard/handlers/watir.rb +1 -1
  48. data/spec/element_locator_spec.rb +14 -1
  49. data/spec/html/clicks.html +1 -1
  50. data/spec/implementation.rb +29 -6
  51. data/spec/wait_spec.rb +2 -2
  52. data/support/travis.sh +5 -3
  53. data/support/version_differ.rb +59 -0
  54. data/watir-webdriver.gemspec +4 -3
  55. metadata +146 -149
  56. data/spec/alert_spec.rb +0 -91
  57. data/spec/html/alerts.html +0 -12
  58. data/spec/screenshot_spec.rb +0 -25
  59. data/support/html5.html +0 -102577
@@ -6,5 +6,5 @@ module Watir
6
6
  assert_exists
7
7
  execute_atom :selectText, @element, str
8
8
  end
9
- end
10
- end
9
+ end # Element
10
+ end # Watir
@@ -1,5 +1,16 @@
1
1
  module Watir
2
2
  module HasWindow
3
+
4
+ #
5
+ # Returns browser windows array.
6
+ #
7
+ # @example
8
+ # browser.a(:id => "open_new_window").click
9
+ # browser.windows(:title => "new")
10
+ #
11
+ # @return [Array<Window>]
12
+ #
13
+
3
14
  def windows(*args)
4
15
  all = @driver.window_handles.map { |handle| Window.new(@driver, :handle => handle) }
5
16
 
@@ -10,6 +21,16 @@ module Watir
10
21
  end
11
22
  end
12
23
 
24
+ #
25
+ # Returns browser window.
26
+ #
27
+ # @example
28
+ # browser.a(:id => "open_new_window").click
29
+ # browser.window(:title => "new")
30
+ #
31
+ # @return [Window]
32
+ #
33
+
13
34
  def window(*args, &blk)
14
35
  win = Window.new @driver, extract_selector(args)
15
36
 
@@ -29,5 +50,6 @@ module Watir
29
50
  selector.all? { |key, value| value === win.send(key) }
30
51
  end
31
52
  end
32
- end # WindowSwitching
53
+
54
+ end # HasWindow
33
55
  end # Watir
@@ -12,6 +12,8 @@ ActiveSupport::Inflector.inflections do |inflect|
12
12
  inflect.plural /^s$/, 'ss'
13
13
  inflect.plural 'meta', 'metas'
14
14
  inflect.plural 'details', 'detailses'
15
+ inflect.plural 'data', 'datas'
16
+ inflect.plural 'datalist', 'datalists'
15
17
  end
16
18
 
17
19
  require "watir-webdriver/html/util"
@@ -146,9 +146,9 @@ module Watir
146
146
  :string
147
147
  when 'UnsignedLong', 'Long', 'Integer', 'Short', 'UnsignedShort'
148
148
  :int
149
- when 'Float', 'Double'
149
+ when 'Float', /.*Double$/
150
150
  :float
151
- when 'Function'
151
+ when 'Function', /.*EventHandler$/
152
152
  :function
153
153
  when 'Boolean'
154
154
  :bool
@@ -329,6 +329,10 @@ module Watir
329
329
  return false
330
330
  end
331
331
 
332
+ if selectors[:tag_name] == 'input' && selectors.has_key?(:type)
333
+ return false
334
+ end
335
+
332
336
  if selectors.has_key?(:class) && selectors[:class] !~ /^[\w-]+$/ui
333
337
  return false
334
338
  end
@@ -369,6 +373,10 @@ module Watir
369
373
  when :href
370
374
  # TODO: change this behaviour?
371
375
  'normalize-space(@href)'
376
+ when :type
377
+ # type attributes can be upper case - downcase them
378
+ # https://github.com/watir/watir-webdriver/issues/72
379
+ XpathSupport.downcase('@type')
372
380
  else
373
381
  "@#{key.to_s.gsub("_", "-")}"
374
382
  end
@@ -3,7 +3,7 @@ module Watir
3
3
 
4
4
  NON_TEXT_TYPES = %w[file radio checkbox submit reset image button hidden datetime date month week time datetime-local range color]
5
5
  # TODO: better way of finding input text fields?
6
- NEGATIVE_TYPE_EXPR = NON_TEXT_TYPES.map { |t| "@type!=#{t.inspect}" }.join(" and ")
6
+ NEGATIVE_TYPE_EXPR = NON_TEXT_TYPES.map { |type| "%s!=%s" % [XpathSupport.downcase('@type'), type.inspect] }.join(' and ')
7
7
 
8
8
  def locate_all
9
9
  find_all_by_multiple
@@ -1,6 +1,10 @@
1
1
  module Watir
2
2
  module RowContainer
3
3
 
4
+ #
5
+ # Returns table row.
6
+ #
7
+
4
8
  def row(*args)
5
9
  row = tr(*args)
6
10
  row.locator_class = ChildRowLocator
@@ -8,13 +12,17 @@ module Watir
8
12
  row
9
13
  end
10
14
 
15
+ #
16
+ # Returns table rows collection.
17
+ #
18
+
11
19
  def rows(*args)
12
20
  rows = trs(*args)
13
21
  rows.locator_class = ChildRowLocator
14
22
 
15
23
  rows
16
24
  end
17
-
25
+
18
26
  #
19
27
  # The table as a 2D Array of strings with the text of each cell.
20
28
  #
@@ -30,5 +38,5 @@ module Watir
30
38
  end
31
39
  alias_method :to_a, :strings
32
40
 
33
- end
34
- end
41
+ end # RowContainer
42
+ end # Watir
@@ -9,6 +9,9 @@ module Watir
9
9
  #
10
10
  # Saves screenshot to given path.
11
11
  #
12
+ # @example
13
+ # browser.screenshot.save "screenshot.png"
14
+ #
12
15
  # @param [String] path
13
16
  #
14
17
 
@@ -19,6 +22,10 @@ module Watir
19
22
  #
20
23
  # Represents screenshot as PNG image string.
21
24
  #
25
+ # @example
26
+ # browser.screenshot.png
27
+ # #=> '\x95\xC7\x8C@1\xC07\x1C(Edb\x15\xB2\vL'
28
+ #
22
29
  # @return [String]
23
30
  #
24
31
 
@@ -29,6 +36,10 @@ module Watir
29
36
  #
30
37
  # Represents screenshot as Base64 encoded string.
31
38
  #
39
+ # @example
40
+ # browser.screenshot.base64
41
+ # #=> '7HWJ43tZDscPleeUuPW6HhN3x+z7vU/lufmH0qNTtTum94IBWMT46evImci1vnFGT'
42
+ #
32
43
  # @return [String]
33
44
  #
34
45
 
@@ -1,8 +1,11 @@
1
1
  module Watir
2
2
  module UserEditable
3
+
3
4
  #
4
5
  # Clear the element, the type in the given value.
5
6
  #
7
+ # @param [String, Symbol] *args
8
+ #
6
9
 
7
10
  def set(*args)
8
11
  assert_exists
@@ -14,7 +17,9 @@ module Watir
14
17
  alias_method :value=, :set
15
18
 
16
19
  #
17
- # Append the given value to the text in the text field.
20
+ # Appends the given value to the text in the text field.
21
+ #
22
+ # @param [String, Symbol] *args
18
23
  #
19
24
 
20
25
  def append(*args)
@@ -26,12 +31,13 @@ module Watir
26
31
  alias_method :<<, :append
27
32
 
28
33
  #
29
- # Clear the text field.
34
+ # Clears the text field.
30
35
  #
31
36
 
32
37
  def clear
33
38
  assert_exists
34
39
  @element.clear
35
40
  end
36
- end
37
- end
41
+
42
+ end # UserEditable
43
+ end # Watir
@@ -1,3 +1,3 @@
1
1
  module Watir
2
- VERSION = "0.6.1"
3
- end
2
+ VERSION = "0.6.2"
3
+ end # Watir
@@ -2,14 +2,20 @@
2
2
  module Watir
3
3
  module Wait
4
4
 
5
- class TimeoutError < StandardError
6
- end
5
+ class TimeoutError < StandardError ; end
7
6
 
8
7
  INTERVAL = 0.1
9
8
 
10
9
  class << self
11
10
  #
12
- # Wait until the block evaluates to true or times out.
11
+ # Waits until the block evaluates to true or times out.
12
+ #
13
+ # @example
14
+ # Watir::Wait.until { browser.a(:id => "ajaxed").visible? }
15
+ #
16
+ # @param [Fixnum] timeout How long to wait in seconds
17
+ # @param [String] message Message to raise if timeout is exceeded
18
+ # @raise [TimeoutError] if timeout is exceeded
13
19
  #
14
20
 
15
21
  def until(timeout = 30, message = nil, &block)
@@ -27,6 +33,13 @@ module Watir
27
33
  #
28
34
  # Wait while the block evaluates to true or times out.
29
35
  #
36
+ # @example
37
+ # Watir::Wait.while { browser.a(:id => "ajaxed").visible? }
38
+ #
39
+ # @param [Fixnum] timeout How long to wait in seconds
40
+ # @param [String] message Message to raise if timeout is exceeded
41
+ # @raise [TimeoutError] if timeout is exceeded
42
+ #
30
43
 
31
44
  def while(timeout = 30, message = nil, &block)
32
45
  end_time = ::Time.now + timeout
@@ -47,7 +60,8 @@ module Watir
47
60
 
48
61
  err
49
62
  end
50
- end # class << self
63
+
64
+ end # self
51
65
  end # Wait
52
66
 
53
67
  module Waitable
@@ -97,14 +111,15 @@ module Watir
97
111
  #
98
112
  # Waits until the element is present.
99
113
  #
100
- # @see Watir::Wait
114
+ # @example
115
+ # browser.button(:id => 'foo').when_present.click
116
+ # browser.div(:id => 'bar').when_present { |div| ... }
117
+ # browser.p(:id => 'baz').when_present(60).text
101
118
  #
102
- # Example:
103
- # browser.button(:id, 'foo').when_present.click
104
- # browser.div(:id, 'bar').when_present { |div| ... }
105
- # browser.p(:id, 'baz').when_present(60).text
119
+ # @param [Fixnum] timeout seconds to wait before timing out
106
120
  #
107
- # @param [Integer] timeout seconds to wait before timing out
121
+ # @see Watir::Wait
122
+ # @see Watir::Element#present?
108
123
  #
109
124
 
110
125
  def when_present(timeout = 30)
@@ -121,7 +136,10 @@ module Watir
121
136
  #
122
137
  # Waits until the element is present.
123
138
  #
124
- # @param [Integer] timeout seconds to wait before timing out
139
+ # @example
140
+ # browser.button(:id => 'foo').wait_until_present
141
+ #
142
+ # @param [Fixnum] timeout seconds to wait before timing out
125
143
  #
126
144
  # @see Watir::Wait
127
145
  # @see Watir::Element#present?
@@ -135,6 +153,9 @@ module Watir
135
153
  #
136
154
  # Waits while the element is present.
137
155
  #
156
+ # @example
157
+ # browser.button(:id => 'foo').wait_while_present
158
+ #
138
159
  # @param [Integer] timeout seconds to wait before timing out
139
160
  #
140
161
  # @see Watir::Wait
@@ -21,6 +21,15 @@ module Watir
21
21
  '#<%s:0x%x located=%s>' % [self.class, hash*2, !!@handle]
22
22
  end
23
23
 
24
+ #
25
+ # Returns window size.
26
+ #
27
+ # @example
28
+ # size = browser.window.size
29
+ # "%sx%s" % [size.width, size.height]
30
+ # #=> "1600x1200"
31
+ #
32
+
24
33
  def size
25
34
  size = nil
26
35
  use { size = @driver.manage.window.size }
@@ -28,6 +37,15 @@ module Watir
28
37
  size
29
38
  end
30
39
 
40
+ #
41
+ # Returns window position.
42
+ #
43
+ # @example
44
+ # position = browser.window.position
45
+ # "%sx%s" % [position.x, position.y]
46
+ # #=> "92x76"
47
+ #
48
+
31
49
  def position
32
50
  pos = nil
33
51
  use { pos = @driver.manage.window.position }
@@ -35,6 +53,16 @@ module Watir
35
53
  pos
36
54
  end
37
55
 
56
+ #
57
+ # Resizes window to given width and height.
58
+ #
59
+ # @example
60
+ # browser.window.resize_to 1600, 1200
61
+ #
62
+ # @param [Fixnum] width
63
+ # @param [Fixnum] height
64
+ #
65
+
38
66
  def resize_to(width, height)
39
67
  dimension = Selenium::WebDriver::Dimension.new(width, height)
40
68
  use { @driver.manage.window.size = dimension }
@@ -42,6 +70,16 @@ module Watir
42
70
  dimension
43
71
  end
44
72
 
73
+ #
74
+ # Moves window to given x and y coordinates.
75
+ #
76
+ # @example
77
+ # browser.window.move_to 300, 200
78
+ #
79
+ # @param [Fixnum] x
80
+ # @param [Fixnum] y
81
+ #
82
+
45
83
  def move_to(x, y)
46
84
  point = Selenium::WebDriver::Point.new(x, y)
47
85
  use { @driver.manage.window.position = point }
@@ -49,6 +87,23 @@ module Watir
49
87
  point
50
88
  end
51
89
 
90
+ #
91
+ # Maximizes window.
92
+ #
93
+ # @example
94
+ # browser.window.maximize
95
+ #
96
+
97
+ def maximize
98
+ use { @driver.manage.window.maximize }
99
+ end
100
+
101
+ #
102
+ # Returns true if window exists.
103
+ #
104
+ # @return [Boolean]
105
+ #
106
+
52
107
  def exists?
53
108
  handle
54
109
  true
@@ -56,12 +111,27 @@ module Watir
56
111
  false
57
112
  end
58
113
 
114
+ #
115
+ # Returns true if window is present.
116
+ #
117
+ # @return [Boolean]
118
+ #
119
+
59
120
  def present?
60
121
  @handle = nil # relocate
61
122
 
62
123
  exists?
63
124
  end
64
125
 
126
+ #
127
+ # Returns true if two windows are equal.
128
+ #
129
+ # @example
130
+ # browser.window(:index => 1) == browser.window(:index => 2)
131
+ #
132
+ # @param [Window] other
133
+ #
134
+
65
135
  def ==(other)
66
136
  return false unless other.kind_of?(self.class)
67
137
 
@@ -73,14 +143,32 @@ module Watir
73
143
  handle.hash ^ self.class.hash
74
144
  end
75
145
 
146
+ #
147
+ # Returns true if window is current.
148
+ #
149
+ # @example
150
+ # browser.window.current?
151
+ # #=> true
152
+ #
153
+
76
154
  def current?
77
155
  @driver.window_handle == handle
78
156
  end
79
157
 
158
+ #
159
+ # CLoses window.
160
+ #
161
+
80
162
  def close
81
163
  use { @driver.close }
82
164
  end
83
165
 
166
+ #
167
+ # Returns window title.
168
+ #
169
+ # @return [String]
170
+ #
171
+
84
172
  def title
85
173
  title = nil
86
174
  use { title = @driver.title }
@@ -88,6 +176,12 @@ module Watir
88
176
  title
89
177
  end
90
178
 
179
+ #
180
+ # Returns window URL.
181
+ #
182
+ # @return [String]
183
+ #
184
+
91
185
  def url
92
186
  url = nil
93
187
  use { url = @driver.current_url }
@@ -95,6 +189,15 @@ module Watir
95
189
  url
96
190
  end
97
191
 
192
+ #
193
+ # Switches to given window and executes block, then switches back.
194
+ #
195
+ # @example
196
+ # browser.window(:title => "2nd window").use do
197
+ # browser.button(:id => "close").click
198
+ # end
199
+ #
200
+
98
201
  def use(&blk)
99
202
  @driver.switch_to.window(handle, &blk)
100
203
  self
@@ -135,4 +238,4 @@ module Watir
135
238
  end
136
239
 
137
240
  end # Window
138
- end # Watir
241
+ end # Watir