watir-dom-wait 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -80,7 +80,7 @@ Watir::Dom::Wait.interval = 0.15
80
80
 
81
81
  By attaching `DOMSubtreeModified` event to element. It's supported in all major browsers (except Presto-powered Opera).
82
82
 
83
- Note, that it also rescues `Selenium::WebDriver::Error::StaleElementReferenceError` when waits for DOM.
83
+ Note, that it also rescues `Selenium::WebDriver::Error::StaleElementReferenceError` and `Selenium::WebDriver::Error::JavascriptError` when waits for DOM.
84
84
 
85
85
  ## Contributors
86
86
 
@@ -42,8 +42,16 @@ module Watir
42
42
  WhenDOMChangedDecorator.new(self, opts, message)
43
43
  end
44
44
 
45
- rescue Selenium::WebDriver::Error::StaleElementReferenceError
46
- locate
45
+ rescue Selenium::WebDriver::Error::StaleElementReferenceError, Selenium::WebDriver::Error::JavascriptError
46
+ # StaleElementReferenceError
47
+ # element can become stale, so we just retry DOM waiting
48
+ #
49
+ # JavascriptError
50
+ # in rare cases, args passed to execute script are not correct, for example:
51
+ # correct: [#<Watir::Body:0x6bb2ccb9de06cb92 located=false selector={:element=>(webdriver element)}>, 300, 3000] [el, interval, delay]
52
+ # incorrect: [0.3, 3000, nil] [interval, delay, ?]
53
+ # TODO there might be some logic (bug?) in Selenium which does this
54
+ retry
47
55
  end
48
56
 
49
57
  #
@@ -56,19 +56,21 @@ function Watir(options) {
56
56
  this.set(options);
57
57
 
58
58
  this.startedModifying = false;
59
- this.domReady = 1;
59
+ this.domReady = 1;
60
60
 
61
61
  this.bindDOMEvents();
62
62
  this.exitOnTimeout();
63
63
  };
64
64
 
65
65
  Watir.prototype.set = function (options) {
66
- if (options == null) options = {};
66
+ if (options == null) {
67
+ options = {};
68
+ }
67
69
 
68
- this.el = options.el;
69
- this.event = options.event || 'DOMSubtreeModified';
70
+ this.el = options.el;
71
+ this.event = options.event || 'DOMSubtreeModified';
70
72
  this.interval = options.interval;
71
- this.delay = options.delay;
73
+ this.delay = options.delay;
72
74
 
73
75
  this.forceReady = this.wrappedForceReady();
74
76
  this.startModifying = this.wrappedStartModifying();
@@ -120,7 +122,6 @@ Watir.prototype.addEventListener = (function() {
120
122
  return function (fn) {
121
123
  this.el.addEventListener(this.event, fn, false);
122
124
  };
123
-
124
125
  } else {
125
126
  return function (fn) {
126
127
  this.el.attachEvent('on' + this.event, fn)
@@ -133,7 +134,6 @@ Watir.prototype.removeEventListener = (function() {
133
134
  return function (fn) {
134
135
  this.el.removeEventListener(this.event, fn, false);
135
136
  };
136
-
137
137
  } else {
138
138
  return function (fn) {
139
139
  this.el.detachEvent('on' + this.event, fn)
@@ -142,7 +142,8 @@ Watir.prototype.removeEventListener = (function() {
142
142
  })();
143
143
 
144
144
  window.watir = new Watir({
145
- el: arguments[0],
145
+ el: arguments[0],
146
146
  interval: arguments[1] * 1000,
147
- delay: arguments[2] * 1000,
147
+ delay: arguments[2] * 1000,
148
148
  });
149
+
@@ -1,7 +1,7 @@
1
1
  module Watir
2
2
  module Dom
3
3
  module Wait
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end # Wait
6
6
  end # Dom
7
7
  end # Watir
@@ -0,0 +1 @@
1
+ require 'watir/dom/wait'
@@ -6,24 +6,24 @@ describe Watir::Element do
6
6
  context "when block is not given" do
7
7
  it "waits using event handler" do
8
8
  @browser.button(:id => "quick").click
9
- @browser.div.when_dom_changed.should have(20).spans
9
+ expect(@browser.div.when_dom_changed).to have(20).spans
10
10
  end
11
11
 
12
12
  it "may be run more than one time" do
13
13
  3.times do |i|
14
14
  @browser.button(:id => "quick").click
15
- @browser.div.when_dom_changed.should have(20 * (i + 1)).spans
15
+ expect(@browser.div.when_dom_changed).to have(20 * (i + 1)).spans
16
16
  end
17
17
  end
18
18
 
19
19
  it "waits using custom interval" do
20
20
  @browser.button(:id => "long").click
21
- @browser.div.when_dom_changed(:interval => 1.1).should have(5).spans
21
+ expect(@browser.div.when_dom_changed(:interval => 1.1)).to have(5).spans
22
22
  end
23
23
 
24
24
  it "raises timeout error" do
25
25
  @browser.button(:id => "quick").click
26
- lambda { @browser.div.when_dom_changed(:timeout => 2).spans }.should raise_error(Watir::Wait::TimeoutError)
26
+ expect { @browser.div.when_dom_changed(:timeout => 2).spans }.to raise_error(Watir::Wait::TimeoutError)
27
27
  end
28
28
  end
29
29
 
@@ -31,36 +31,37 @@ describe Watir::Element do
31
31
  it "waits using event handler" do
32
32
  @browser.button(:id => "quick").click
33
33
  @browser.div.when_dom_changed do |div|
34
- div.should have(20).spans
34
+ expect(div).to have(20).spans
35
35
  end
36
36
  end
37
37
 
38
38
  it "waits using custom interval" do
39
39
  @browser.button(:id => "long").click
40
40
  @browser.div.when_dom_changed(:interval => 1.1) do |div|
41
- div.should have(5).spans
41
+ expect(div).to have(5).spans
42
42
  end
43
43
  end
44
44
 
45
45
  it "raises timeout error" do
46
46
  @browser.button(:id => "quick").click
47
- lambda do
47
+ expect {
48
48
  @browser.div.when_dom_changed(:timeout => 2) { |div| div.spans }
49
- end.should raise_error(Watir::Wait::TimeoutError)
49
+ }.to raise_error(Watir::Wait::TimeoutError)
50
50
  end
51
51
 
52
52
  it "returns block evaluation" do
53
53
  @browser.button(:id => "quick").click
54
- @browser.div.when_dom_changed do |div|
54
+ size = @browser.div.when_dom_changed do |div|
55
55
  div.spans.size
56
- end.should == 20
56
+ end
57
+ expect(size).to eq(20)
57
58
  end
58
59
  end
59
60
  end
60
61
 
61
62
  context "when DOM is not changed" do
62
63
  it "doesn't raise any exception" do
63
- @browser.div.when_dom_changed.should have(0).spans
64
+ expect(@browser.div.when_dom_changed).to have(0).spans
64
65
  end
65
66
  end
66
67
 
@@ -77,9 +78,9 @@ describe Watir::Element do
77
78
  div = @browser.div(:id => 'container2')
78
79
  div.exists?
79
80
  @browser.refresh
80
- lambda do
81
+ expect {
81
82
  div.when_dom_changed.text
82
- end.should_not raise_error(Selenium::WebDriver::Error::StaleElementReferenceError)
83
+ }.not_to raise_error(Selenium::WebDriver::Error::StaleElementReferenceError)
83
84
  end
84
85
  end
85
86
  end
@@ -88,12 +89,12 @@ describe Watir::Element do
88
89
  it "calls #when_dom_changed" do
89
90
  div = @browser.div
90
91
  opts = { timeout: 1, interval: 2, delay: 3 }
91
- div.should_receive(:when_dom_changed).with(opts)
92
+ expect(div).to receive(:when_dom_changed).with(opts)
92
93
  div.wait_until_dom_changed(opts)
93
94
  end
94
95
 
95
96
  it "returns nil" do
96
- @browser.div.wait_until_dom_changed.should == nil
97
+ expect(@browser.div.wait_until_dom_changed).to eq(nil)
97
98
  end
98
99
  end
99
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-dom-wait
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-12 00:00:00.000000000 Z
12
+ date: 2013-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
@@ -88,6 +88,7 @@ files:
88
88
  - LICENSE.txt
89
89
  - README.md
90
90
  - Rakefile
91
+ - lib/watir-dom-wait.rb
91
92
  - lib/watir/dom/elements/element.rb
92
93
  - lib/watir/dom/extensions/js/waitForDom.js
93
94
  - lib/watir/dom/wait.rb
@@ -111,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  segments:
113
114
  - 0
114
- hash: 3291543436130083017
115
+ hash: -357748089059915628
115
116
  required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  none: false
117
118
  requirements:
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  version: '0'
121
122
  segments:
122
123
  - 0
123
- hash: 3291543436130083017
124
+ hash: -357748089059915628
124
125
  requirements: []
125
126
  rubyforge_project:
126
127
  rubygems_version: 1.8.23