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
data/Gemfile CHANGED
@@ -2,7 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  unless ENV['TRAVIS']
4
4
  gem "simplecov", ">= 0.3.5", :platform => :ruby_19
5
- gem "ruby-debug19", :platform => :ruby_19
6
5
  end
7
6
 
8
7
  # Specify your gem's dependencies in watir-webdriver.gemspec
data/Rakefile CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
2
 
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
+ require 'watir-webdriver/version'
5
6
  Bundler::GemHelper.install_tasks
6
7
 
7
8
  require 'rspec/core/rake_task'
@@ -91,4 +92,25 @@ YARD::Rake::YardocTask.new do |task|
91
92
  task.options = %w[--debug] # this is pretty slow, so nice with some output
92
93
  end
93
94
 
95
+ namespace :changes do
96
+ task :differ do
97
+ require './support/version_differ'
98
+ end
99
+
100
+ desc 'Update CHANGES.md'
101
+ task :update => :differ do
102
+ VersionDiffer.new.update('CHANGES.md')
103
+ end
104
+
105
+ desc 'Generate CHANGES.md from scratch'
106
+ task :generate => :differ do
107
+ VersionDiffer.new.generate('CHANGES.md')
108
+ end
109
+
110
+ desc 'Print latest diff'
111
+ task :print => :differ do
112
+ VersionDiffer.new.print_latest(STDOUT)
113
+ end
114
+ end
115
+
94
116
  load "spec/watirspec/watirspec.rake" if File.exist?("spec/watirspec/watirspec.rake")
@@ -9,26 +9,68 @@ module Watir
9
9
  @alert = nil
10
10
  end
11
11
 
12
+ #
13
+ # Returns text of alert.
14
+ #
15
+ # @example
16
+ # browser.alert.text
17
+ # #=> "This is alert text"
18
+ #
19
+ # @return [String]
20
+ #
21
+
12
22
  def text
13
23
  assert_exists
14
24
  @alert.text
15
25
  end
16
26
 
27
+ #
28
+ # Closes alert or accepts prompts/confirms.
29
+ #
30
+ # @example
31
+ # browser.alert.ok
32
+ # browser.alert.exists?
33
+ # #=> false
34
+ #
35
+
17
36
  def ok
18
37
  assert_exists
19
38
  @alert.accept
20
39
  end
21
40
 
41
+ #
42
+ # Closes alert or cancels prompts/confirms.
43
+ #
44
+ # @example
45
+ # browser.alert.close
46
+ # browser.alert.exists?
47
+ # #=> false
48
+ #
49
+
22
50
  def close
23
51
  assert_exists
24
52
  @alert.dismiss
25
53
  end
26
54
 
55
+ #
56
+ # Enters text to prompt.
57
+ #
58
+ # @example
59
+ # browser.alert.set "Text for prompt"
60
+ # browser.alert.ok
61
+ #
62
+ # @param [String] value
63
+ #
64
+
27
65
  def set(value)
28
66
  assert_exists
29
67
  @alert.send_keys(value)
30
68
  end
31
69
 
70
+ #
71
+ # Returns true if alert, confirm or prompt is present and false otherwise.
72
+ #
73
+
32
74
  def exists?
33
75
  assert_exists
34
76
  true
@@ -37,6 +79,10 @@ module Watir
37
79
  end
38
80
  alias_method :present?, :exists?
39
81
 
82
+ #
83
+ # @api private
84
+ #
85
+
40
86
  def selector_string
41
87
  'alert'
42
88
  end
@@ -2,5 +2,5 @@ module Watir
2
2
  module Container
3
3
  alias_method :field_set, :fieldset
4
4
  alias_method :field_sets, :fieldsets
5
- end
6
- end
5
+ end # Container
6
+ end # Watir
@@ -19,5 +19,5 @@ module Watir
19
19
  driver.execute_script(script, *arguments)
20
20
  end
21
21
 
22
- end
23
- end
22
+ end # Atoms
23
+ end # Watir
@@ -1,4 +1,3 @@
1
1
  These compiled JavaScript fragments originate in the Selenium code base, and are under the Apache 2.0 License.
2
2
 
3
3
  See http://selenium.googlecode.com/svn/trunk/javascript/watir-atoms/
4
-
@@ -14,8 +14,19 @@ module Watir
14
14
  alias_method :wd, :driver # ensures duck typing with Watir::Element
15
15
 
16
16
  class << self
17
- def start(url, browser = :firefox)
18
- b = new(browser)
17
+ #
18
+ # Creates a Watir::Browser instance and goes to URL.
19
+ #
20
+ # @example
21
+ # browser = Watir::Browser.start "www.google.com", :chrome
22
+ # #=> #<Watir::Browser:0x..fa45a499cb41e1752 url="http://www.google.com" title="Google">
23
+ #
24
+ # @param [String] url
25
+ # @param [Symbol, Selenium::WebDriver] browser :firefox, :ie, :chrome, :remote or Selenium::WebDriver instance
26
+ # @return [Watir::Browser]
27
+ #
28
+ def start(url, browser = :firefox, *args)
29
+ b = new(browser, *args)
19
30
  b.goto url
20
31
 
21
32
  b
@@ -23,9 +34,9 @@ module Watir
23
34
  end
24
35
 
25
36
  #
26
- # Create a Watir::Browser instance
37
+ # Creates a Watir::Browser instance.
27
38
  #
28
- # @param [:firefox, :ie, :chrome, :remote, Selenium::WebDriver] browser
39
+ # @param [Symbol, Selenium::WebDriver] browser :firefox, :ie, :chrome, :remote or Selenium::WebDriver instance
29
40
  # @param args Passed to the underlying driver
30
41
  #
31
42
 
@@ -51,7 +62,10 @@ module Watir
51
62
  end
52
63
 
53
64
  #
54
- # Goto the given URL
65
+ # Goes to the given URL.
66
+ #
67
+ # @example
68
+ # browser.goto "www.google.com"
55
69
  #
56
70
  # @param [String] uri The url.
57
71
  # @return [String] The url you end up at.
@@ -66,22 +80,56 @@ module Watir
66
80
  url
67
81
  end
68
82
 
83
+ #
84
+ # Navigates back in history.
85
+ #
86
+
69
87
  def back
70
88
  @driver.navigate.back
71
89
  end
72
90
 
91
+ #
92
+ # Navigates forward in history.
93
+ #
94
+
73
95
  def forward
74
96
  @driver.navigate.forward
75
97
  end
76
98
 
99
+ #
100
+ # Returns URL of current page.
101
+ #
102
+ # @example
103
+ # browser.goto "http://www.google.com"
104
+ # browser.url
105
+ # #=> "http://www.google.com"
106
+ #
107
+ # @return [String]
108
+ #
109
+
77
110
  def url
78
111
  @driver.current_url
79
112
  end
80
113
 
114
+ #
115
+ # Returns title of current page.
116
+ #
117
+ # @example
118
+ # browser.goto "http://www.google.com"
119
+ # browser.title
120
+ # #=> "Google"
121
+ #
122
+ # @return [String]
123
+ #
124
+
81
125
  def title
82
126
  @driver.title
83
127
  end
84
128
 
129
+ #
130
+ # Closes browser.
131
+ #
132
+
85
133
  def close
86
134
  return if @closed
87
135
  @driver.quit
@@ -89,42 +137,123 @@ module Watir
89
137
  end
90
138
  alias_method :quit, :close # TODO: close vs quit
91
139
 
140
+ #
141
+ # Handles cookies.
142
+ #
143
+ # @return [Watir::Cookies]
144
+ #
145
+
92
146
  def cookies
93
147
  @cookies ||= Cookies.new driver.manage
94
148
  end
95
149
 
150
+ #
151
+ # Returns browser name.
152
+ #
153
+ # @example
154
+ # browser = Watir::Browser.new :chrome
155
+ # browser.name
156
+ # #=> :chrome
157
+ #
158
+ # @return [String]
159
+ #
160
+
161
+ def name
162
+ @driver.browser
163
+ end
164
+
165
+ #
166
+ # Returns text of page body.
167
+ #
168
+ # @return [String]
169
+ #
170
+
96
171
  def text
97
172
  @driver.find_element(:tag_name, "body").text
98
173
  end
99
174
 
175
+ #
176
+ # Returns HTML code of current page.
177
+ #
178
+ # @return [String]
179
+ #
180
+
100
181
  def html
101
182
  # use body.html instead?
102
183
  @driver.page_source
103
184
  end
104
185
 
186
+ #
187
+ # Handles JavaScript alerts, confirms and prompts.
188
+ #
189
+ # @return [Watir::Alert]
190
+ #
191
+
105
192
  def alert
106
193
  Alert.new driver.switch_to
107
194
  end
108
195
 
196
+ #
197
+ # Refreshes current page.
198
+ #
199
+
109
200
  def refresh
110
201
  @driver.navigate.refresh
111
202
  run_checkers
112
203
  end
113
204
 
205
+ #
206
+ # Waits until readyState of document is complete.
207
+ #
208
+ # @param [Fixnum] timeout
209
+ # @raise [Watir::Wait::TimeoutError] if timeout is exceeded
210
+ #
211
+
114
212
  def wait(timeout = 5)
115
213
  wait_until(timeout, "waiting for document.readyState == 'complete'") do
116
214
  ready_state == "complete"
117
215
  end
118
216
  end
119
217
 
218
+ #
219
+ # Returns readyState of document.
220
+ #
221
+ # @return [String]
222
+ #
223
+
120
224
  def ready_state
121
225
  execute_script 'return document.readyState'
122
226
  end
123
227
 
228
+ #
229
+ # Returns the text of status bar.
230
+ #
231
+ # @return [String]
232
+ #
233
+
124
234
  def status
125
235
  execute_script "return window.status;"
126
236
  end
127
237
 
238
+ #
239
+ # Executes JavaScript snippet.
240
+ #
241
+ # If you are going to use the value snippet returns, make sure to use
242
+ # `return` explicitly.
243
+ #
244
+ # @example Check that Ajax requests are completed with jQuery
245
+ # browser.execute_script("return jQuery.active") == '0'
246
+ # #=> true
247
+ #
248
+ # @example Get inner HTML of element
249
+ # span = browser.span(class: "someclass")
250
+ # browser.execute_script "return arguments[0].innerHTML", span
251
+ # #=> "Span innerHTML"
252
+ #
253
+ # @param [String] script JavaScript snippet to execute
254
+ # @param *args Arguments will be available in the given script in the 'arguments' pseudo-array
255
+ #
256
+
128
257
  def execute_script(script, *args)
129
258
  args.map! { |e| e.kind_of?(Watir::Element) ? e.wd : e }
130
259
  returned = @driver.execute_script(script, *args)
@@ -132,15 +261,22 @@ module Watir
132
261
  wrap_elements_in(returned)
133
262
  end
134
263
 
264
+ #
265
+ # Sends sequence of keystrokes to currently active element.
266
+ #
267
+ # @example
268
+ # browser.goto "http://www.google.com"
269
+ # browser.send_keys "Watir", :return
270
+ #
271
+ # @param [String, Symbol] *args
272
+ #
273
+
135
274
  def send_keys(*args)
136
275
  @driver.switch_to.active_element.send_keys(*args)
137
276
  end
138
277
 
139
278
  #
140
- # Handles screenshot of current pages.
141
- #
142
- # @example
143
- # browser.screenshot.save("screenshot.png")
279
+ # Handles screenshots of current pages.
144
280
  #
145
281
  # @return [Watir::Screenshot]
146
282
  #
@@ -149,6 +285,27 @@ module Watir
149
285
  Screenshot.new driver
150
286
  end
151
287
 
288
+ #
289
+ # Adds new checker.
290
+ #
291
+ # Checkers are generally used to ensure application under test does not encounter
292
+ # any error. They are automatically executed after following events:
293
+ # 1. Open URL
294
+ # 2. Refresh page
295
+ # 3. Click, double-click or right-click on element
296
+ #
297
+ # @example
298
+ # browser.add_checker do |page|
299
+ # page.text.include?("Server Error") and puts "Application exception or 500 error!"
300
+ # end
301
+ # browser.goto "www.mywebsite.com/page-with-error"
302
+ # "Server error! (RuntimeError)"
303
+ #
304
+ # @param [#call] checker Object responding to call
305
+ # @yield Checker block
306
+ # @yieldparam [Watir::Browser]
307
+ #
308
+
152
309
  def add_checker(checker = nil, &block)
153
310
  if block_given?
154
311
  @error_checkers << block
@@ -159,14 +316,43 @@ module Watir
159
316
  end
160
317
  end
161
318
 
319
+ #
320
+ # Deletes checker.
321
+ #
322
+ # @example
323
+ # checker = lambda do |page|
324
+ # page.text.include?("Server Error") and puts "Application exception or 500 error!"
325
+ # end
326
+ # browser.add_checker checker
327
+ # browser.goto "www.mywebsite.com/page-with-error"
328
+ # "Server error! (RuntimeError)"
329
+ # browser.disable_checker checker
330
+ # browser.refresh
331
+ #
332
+
162
333
  def disable_checker(checker)
163
334
  @error_checkers.delete(checker)
164
335
  end
165
336
 
337
+ #
338
+ # Runs checkers.
339
+ #
340
+
166
341
  def run_checkers
167
342
  @error_checkers.each { |e| e.call(self) }
168
343
  end
169
344
 
345
+ #
346
+ # Returns true if browser is not closed and false otherwise.
347
+ #
348
+ # @return [Boolean]
349
+ #
350
+
351
+ def exist?
352
+ not @closed
353
+ end
354
+ alias_method :exists?, :exist?
355
+
170
356
  #
171
357
  # Protocol shared with Watir::Element
172
358
  #
@@ -182,11 +368,6 @@ module Watir
182
368
  end
183
369
  end
184
370
 
185
- def exist?
186
- not @closed
187
- end
188
- alias_method :exists?, :exist?
189
-
190
371
  def reset!
191
372
  # no-op
192
373
  end