watir 6.0.3 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,8 +58,8 @@ module Watir
58
58
  # @example
59
59
  # browser.window.resize_to 1600, 1200
60
60
  #
61
- # @param [Fixnum] width
62
- # @param [Fixnum] height
61
+ # @param [Integer] width
62
+ # @param [Integer] height
63
63
  #
64
64
 
65
65
  def resize_to(width, height)
@@ -75,8 +75,8 @@ module Watir
75
75
  # @example
76
76
  # browser.window.move_to 300, 200
77
77
  #
78
- # @param [Fixnum] x
79
- # @param [Fixnum] y
78
+ # @param [Integer] x
79
+ # @param [Integer] y
80
80
  #
81
81
 
82
82
  def move_to(x, y)
@@ -72,15 +72,12 @@ module WatirSpec
72
72
  info = []
73
73
  info << instance.class.name
74
74
 
75
- if instance.respond_to?(:driver) && instance.driver.class.name == "Selenium::WebDriver::Driver"
76
- info << "(webdriver)"
77
- caps = instance.driver.capabilities
75
+ caps = instance.driver.capabilities
78
76
 
79
- info << "#{caps.browser_name}"
80
- info << "#{caps.version}"
81
- end
77
+ info << "#{caps.browser_name}"
78
+ info << "#{caps.version}"
82
79
 
83
- $stderr.puts "running watirspec against #{info.join ' '} using args #{WatirSpec.implementation.browser_args.inspect}"
80
+ $stderr.puts "running watirspec against #{info.join ' '} using:\n#{WatirSpec.implementation.inspect_args}"
84
81
  rescue
85
82
  # ignored
86
83
  end
@@ -19,7 +19,9 @@ module WatirSpec
19
19
  else
20
20
  puts
21
21
  gs.each do |guard|
22
- puts "\t#{guard[:name].to_s.ljust(20)}: #{guard[:data].inspect}"
22
+ guard[:data][:file] = guard[:data][:file][/\/spec\/(.*):/, 1]
23
+ guard_name = "#{guard[:name]}:".ljust(15)
24
+ puts " #{guard_name} #{guard[:data].inspect}"
23
25
  end
24
26
  end
25
27
  end
@@ -29,5 +29,13 @@ module WatirSpec
29
29
  result
30
30
  end
31
31
 
32
+ def inspect_args
33
+ caps = browser_args.last.delete(:desired_capabilities).send(:capabilities)
34
+ string = "driver: #{browser_args.first}\n"
35
+ browser_args.last.each { |arg| string << "#{arg.inspect}\n" }
36
+ string << "capabilities:\n"
37
+ caps.each { |k, v| string << "\t#{k}: #{v}\n"}
38
+ string
39
+ end
32
40
  end # Implementation
33
41
  end # WatirSpec
@@ -77,10 +77,10 @@ describe Watir::Browser do
77
77
 
78
78
  describe "#wait_while" do
79
79
  it "delegates to the Wait module" do
80
- expect(Watir::Wait).to receive(:while).with(timeout: 3, message: "foo", object: browser).and_yield
80
+ expect(Watir::Wait).to receive(:while).with(timeout: 3, message: "foo", interval: 0.2, object: browser).and_yield
81
81
 
82
82
  called = false
83
- browser.wait_while(timeout: 3, message: "foo") { called = true }
83
+ browser.wait_while(timeout: 3, message: "foo", interval: 0.2) { called = true }
84
84
 
85
85
  expect(called).to be true
86
86
  end
@@ -88,10 +88,10 @@ describe Watir::Browser do
88
88
 
89
89
  describe "#wait_until" do
90
90
  it "delegates to the Wait module" do
91
- expect(Watir::Wait).to receive(:until).with(timeout: 3, message: "foo", object: browser).and_yield
91
+ expect(Watir::Wait).to receive(:until).with(timeout: 3, message: "foo", interval: 0.2, object: browser).and_yield
92
92
 
93
93
  called = false
94
- browser.wait_until(timeout: 3, message: "foo") { called = true }
94
+ browser.wait_until(timeout: 3, message: "foo", interval: 0.2) { called = true }
95
95
 
96
96
  expect(called).to be true
97
97
  end
@@ -283,14 +283,15 @@ describe Watir::Locators::Element::Locator do
283
283
  end
284
284
 
285
285
  describe "errors" do
286
- it "raises a TypeError if :index is not a Fixnum" do
286
+ it "raises a TypeError if :index is not a Integer" do
287
287
  expect { locate_one(tag_name: "div", index: "bar") }.to \
288
- raise_error(TypeError, %[expected Fixnum, got "bar":String])
288
+ raise_error(TypeError, %[expected Integer, got "bar":String])
289
289
  end
290
290
 
291
291
  it "raises a TypeError if selector value is not a String or Regexp" do
292
+ num_type = RUBY_VERSION[/^\d+\.(\d+)/, 1].to_i >= 4 ? 'Integer' : 'Fixnum'
292
293
  expect { locate_one(tag_name: 123) }.to \
293
- raise_error(TypeError, %[expected one of [String, Regexp], got 123:Fixnum])
294
+ raise_error(TypeError, %[expected one of [String, Regexp], got 123:#{num_type}])
294
295
  end
295
296
 
296
297
  it "raises a MissingWayOfFindingObjectException if the attribute is not valid" do
@@ -117,7 +117,7 @@ describe Watir::Element do
117
117
  it "displays selector string for element from colection" do
118
118
  browser.goto(WatirSpec.url_for("wait.html"))
119
119
  element = browser.divs.last
120
- error = 'timed out after 0 seconds, waiting for true condition on {:tag_name=>"div", :index=>4}'
120
+ error = 'timed out after 0 seconds, waiting for true condition on {:tag_name=>"div", :index=>5}'
121
121
  expect { element.wait_until_present(timeout: 0) }.to raise_exception(Watir::Wait::TimeoutError, error)
122
122
  end
123
123
 
@@ -14,7 +14,7 @@ describe Watir::Locators::Element::Locator do
14
14
  end
15
15
 
16
16
  it "handles tag_name and index" do
17
- element = browser.div(visible: true, index: 1)
17
+ element = browser.div(visible: true, index: 1)
18
18
  expect(element.id).to eq 'buttons'
19
19
  end
20
20
 
@@ -32,6 +32,11 @@ describe Watir::Locators::Element::Locator do
32
32
  element = browser.element(visible: true, css: 'div#foo')
33
33
  expect(element.id).to eq 'foo'
34
34
  end
35
+
36
+ it "handles in collections" do
37
+ elements = browser.divs(visible: true)
38
+ expect(elements.size).to eq 3
39
+ end
35
40
  end
36
41
 
37
42
  context "when false" do
@@ -59,6 +64,11 @@ describe Watir::Locators::Element::Locator do
59
64
  element = browser.element(visible: false, css: 'div#bar')
60
65
  expect(element.id).to eq 'bar'
61
66
  end
67
+
68
+ it "handles in collections" do
69
+ elements = browser.divs(visible: false)
70
+ expect(elements.size).to eq 3
71
+ end
62
72
  end
63
73
  end
64
74
  end
@@ -341,8 +341,8 @@ describe "SelectList" do
341
341
  end
342
342
 
343
343
  it "raises NoValueFoundException if the option doesn't exist" do
344
- expect { browser.select_list(name: "new_user_country").select("missing_option") }.to raise_error(Watir::Exception::NoValueFoundException)
345
- expect { browser.select_list(name: "new_user_country").select(/missing_option/) }.to raise_error(Watir::Exception::NoValueFoundException)
344
+ expect { browser.select_list(name: "new_user_country").select("missing_option") }.to raise_no_value_found_exception
345
+ expect { browser.select_list(name: "new_user_country").select(/missing_option/) }.to raise_no_value_found_exception
346
346
  end
347
347
 
348
348
  it "raises ObjectDisabledException if the option is disabled" do
@@ -371,8 +371,8 @@ describe "SelectList" do
371
371
  end
372
372
 
373
373
  it "raises NoValueFoundException if the option doesn't exist" do
374
- expect { browser.select_list(name: "new_user_languages").select_value("no_such_option") }.to raise_error(Watir::Exception::NoValueFoundException)
375
- expect { browser.select_list(name: "new_user_languages").select_value(/no_such_option/) }.to raise_error(Watir::Exception::NoValueFoundException)
374
+ expect { browser.select_list(name: "new_user_languages").select_value("no_such_option") }.to raise_no_value_found_exception
375
+ expect { browser.select_list(name: "new_user_languages").select_value(/no_such_option/) }.to raise_no_value_found_exception
376
376
  end
377
377
  end
378
378
 
@@ -58,6 +58,20 @@
58
58
  show and enable btn
59
59
  </a>
60
60
  </div>
61
+ <div>
62
+ <a id="add_select" href="#" onclick="setTimeoutDisplay('languages', 'block', 500);">show select list</a>
63
+ </div>
64
+ <form>
65
+ <fieldset>
66
+ <select name="languages" id="languages", style="display: none">
67
+ <option id="danish" value="1">Danish</option>
68
+ <option selected="selected" value="2">English</option>
69
+ <option selected="selected" value="3">Norwegian</option>
70
+ <option value="4" disabled>Russian</option>
71
+ <option>Swedish</option>
72
+ </select> <br />
73
+ </fieldset>
74
+ </form>
61
75
  <div id="also_hidden" style="display:none;">
62
76
  <div id="hidden_child">Nothing to see here</div>
63
77
  </div>
@@ -14,6 +14,7 @@ describe 'Watir#relaxed_locate?' do
14
14
  Watir.default_timeout = time_out
15
15
  element = browser.link(id: 'not_there')
16
16
  start_time = ::Time.now
17
+ allow($stderr).to receive(:write).twice
17
18
  expect { element.click }.to raise_exception(Watir::Exception::UnknownObjectException)
18
19
  expect(::Time.now - start_time).to be > time_out
19
20
  ensure
@@ -83,6 +84,7 @@ describe 'Watir#relaxed_locate?' do
83
84
  element = browser.div(id: 'also_hidden').div(id: 'hidden_child')
84
85
  error = Watir::Exception::UnknownObjectException
85
86
  message = "element located, but timed out after #{Watir.default_timeout} seconds, waiting for true condition on #{selector}"
87
+ allow($stderr).to receive(:write).twice
86
88
  expect { element.click }.to raise_exception(error, message)
87
89
  ensure
88
90
  Watir.default_timeout = 30
@@ -96,6 +98,7 @@ describe 'Watir#relaxed_locate?' do
96
98
  element = browser.div(id: 'buttons').button(id: 'btn2')
97
99
  error = Watir::Exception::UnknownObjectException
98
100
  message = "element located, but timed out after #{Watir.default_timeout} seconds, waiting for true condition on #{selector}"
101
+ allow($stderr).to receive(:write).twice
99
102
  expect { element.click }.to raise_exception(error, message)
100
103
  ensure
101
104
  Watir.default_timeout = 30
@@ -162,6 +165,7 @@ describe 'Watir#relaxed_locate?' do
162
165
  begin
163
166
  Watir.default_timeout = 1.1
164
167
  browser.a(id: 'add_foobar').click
168
+ allow($stderr).to receive(:write).twice
165
169
  # Element created after 1 second, and displays after 2 seconds
166
170
  # Click will only raise this exception if the timer is not reset between #wait_for_exists and #wait_for_present
167
171
  expect { browser.div(id: 'foobar').click }.to raise_exception Watir::Exception::UnknownObjectException
@@ -4,7 +4,8 @@ if defined?(RSpec)
4
4
  raise_no_matching_window_exception: Watir::Exception::NoMatchingWindowFoundException,
5
5
  raise_unknown_frame_exception: Watir::Exception::UnknownFrameException,
6
6
  raise_object_disabled_exception: Watir::Exception::ObjectDisabledException,
7
- raise_object_read_only_exception: Watir::Exception::ObjectReadOnlyException
7
+ raise_object_read_only_exception: Watir::Exception::ObjectReadOnlyException,
8
+ raise_no_value_found_exception: Watir::Exception::NoValueFoundException
8
9
  }.freeze
9
10
 
10
11
  TIMING_EXCEPTIONS.each do |matcher, exception|
@@ -23,6 +23,17 @@ not_compliant_on :safari do
23
23
  }.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
24
24
  end
25
25
 
26
+ it "uses provided interval" do
27
+ begin
28
+ Watir::Wait.until(timeout: 0.4, interval: 0.2) do
29
+ @result = @result.nil? ? 1 : @result + 1
30
+ false
31
+ end
32
+ rescue Watir::Wait::TimeoutError
33
+ end
34
+ expect(@result).to eq 2
35
+ end
36
+
26
37
  it "uses timer for waiting" do
27
38
  timer = Watir::Wait.timer
28
39
  expect(timer).to receive(:wait).with(0.5).and_call_original
@@ -54,6 +65,17 @@ not_compliant_on :safari do
54
65
  }.to raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
55
66
  end
56
67
 
68
+ it "uses provided interval" do
69
+ begin
70
+ Watir::Wait.while(timeout: 0.4, interval: 0.2) do
71
+ @result = @result.nil? ? 1 : @result + 1
72
+ true
73
+ end
74
+ rescue Watir::Wait::TimeoutError
75
+ end
76
+ expect(@result).to eq 2
77
+ end
78
+
57
79
  it "uses timer for waiting" do
58
80
  timer = Watir::Wait.timer
59
81
  expect(timer).to receive(:wait).with(0.5).and_call_original
@@ -168,7 +190,7 @@ not_compliant_on :safari do
168
190
  end
169
191
 
170
192
  describe "#wait_until_present" do
171
- it "it waits until the element appears" do
193
+ it "waits until the element appears" do
172
194
  browser.a(id: 'show_bar').click
173
195
  expect { browser.div(id: 'bar').wait_until_present(timeout: 5) }.to_not raise_exception
174
196
  end
@@ -178,11 +200,34 @@ not_compliant_on :safari do
178
200
  expect { browser.div(id: 'bar').wait_until_present(timeout: 1) }.to raise_error(Watir::Wait::TimeoutError, message)
179
201
  end
180
202
 
203
+ it "uses provided interval" do
204
+ element = browser.div(id: 'bar')
205
+ expect(element).to receive(:present?).twice
206
+
207
+ begin
208
+ element.wait_until_present(timeout: 0.4, interval: 0.2)
209
+ rescue Watir::Wait::TimeoutError
210
+ end
211
+ end
212
+
181
213
  it "ordered pairs are deprecated" do
182
214
  browser.a(id: 'show_bar').click
183
215
  message = /Instead of passing arguments into #wait_until_present method, use keywords/
184
216
  expect { browser.div(id: 'bar').wait_until_present(5) }.to output(message).to_stderr
185
217
  end
218
+
219
+ it 'waits to select an option' do
220
+ browser.a(id: 'add_select').click
221
+ select_list = browser.select_list(id: 'languages')
222
+ Watir.default_timeout = 1
223
+ begin
224
+ start_time = ::Time.now
225
+ expect { select_list.select('No') }.to raise_error Watir::Exception::NoValueFoundException
226
+ expect(::Time.now - start_time).to be > 1
227
+ ensure
228
+ Watir.default_timeout = 1
229
+ end
230
+ end
186
231
  end
187
232
 
188
233
  describe "#wait_while_present" do
@@ -196,11 +241,32 @@ not_compliant_on :safari do
196
241
  expect { browser.div(id: 'foo').wait_while_present(timeout: 1) }.to raise_error(Watir::Wait::TimeoutError, message)
197
242
  end
198
243
 
244
+ it "uses provided interval" do
245
+ element = browser.div(id: 'foo')
246
+ expect(element).to receive(:present?).twice
247
+
248
+ begin
249
+ element.wait_until_present(timeout: 0.4, interval: 0.2)
250
+ rescue Watir::Wait::TimeoutError
251
+ end
252
+ end
253
+
199
254
  it "ordered pairs are deprecated" do
200
255
  browser.a(id: 'hide_foo').click
201
256
  message = /Instead of passing arguments into #wait_while_present method, use keywords/
202
257
  expect { browser.div(id: 'foo').wait_while_present(5) }.to output(message).to_stderr
203
258
  end
259
+
260
+ it "does not error when element goes stale" do
261
+ element = browser.div(id: 'foo')
262
+
263
+ allow(element).to receive(:stale?).and_return(false, true)
264
+ allow(element.wd).to receive(:displayed?).and_raise(Selenium::WebDriver::Error::StaleElementReferenceError)
265
+
266
+ browser.a(id: 'hide_foo').click
267
+ expect { element.wait_while_present(timeout: 1) }.to_not raise_exception
268
+ end
269
+
204
270
  end
205
271
 
206
272
  describe "#wait_until" do
@@ -229,6 +295,11 @@ not_compliant_on :safari do
229
295
  element = browser.div(id: 'bar')
230
296
  expect { element.wait_until(message: 'no') { true } }.to_not raise_exception
231
297
  end
298
+
299
+ it "accepts just an interval parameter" do
300
+ element = browser.div(id: 'bar')
301
+ expect { element.wait_until(interval: 0.1) { true } }.to_not raise_exception
302
+ end
232
303
  end
233
304
 
234
305
  describe "#wait_while" do
@@ -258,6 +329,11 @@ not_compliant_on :safari do
258
329
  element = browser.div(id: 'foo')
259
330
  expect { element.wait_while(message: 'no') { false } }.to_not raise_exception
260
331
  end
332
+
333
+ it "accepts just an interval parameter" do
334
+ element = browser.div(id: 'foo')
335
+ expect { element.wait_while(interval: 0.1) { false } }.to_not raise_exception
336
+ end
261
337
  end
262
338
  end
263
339
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'watir'
5
- s.version = '6.0.3'
5
+ s.version = '6.1.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Alex Rodionov', 'Titus Fortner']
8
8
  s.email = ['p0deje@gmail.com', 'titusfortner@gmail.com']
@@ -21,7 +21,7 @@ It facilitates the writing of automated tests by mimicing the behavior of a user
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  s.require_paths = ['lib']
23
23
 
24
- s.add_dependency "selenium-webdriver", "~> 3.0"
24
+ s.add_dependency 'selenium-webdriver', '~> 3.0'
25
25
 
26
26
  s.add_development_dependency 'rspec', '~> 3.0'
27
27
  s.add_development_dependency 'yard', '> 0.8.2.1'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.3
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rodionov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-22 00:00:00.000000000 Z
12
+ date: 2017-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
@@ -465,7 +465,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
465
465
  version: '0'
466
466
  requirements: []
467
467
  rubyforge_project: watir
468
- rubygems_version: 2.5.2
468
+ rubygems_version: 2.6.8
469
469
  signing_key:
470
470
  specification_version: 4
471
471
  summary: Watir powered by Selenium