watir-webdriver 0.2.0.dev → 0.2.0.dev2

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/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'bundler'
2
3
  Bundler::GemHelper.install_tasks
3
4
 
@@ -8,6 +8,7 @@ module Watir
8
8
  class Browser
9
9
  include Container
10
10
  include WindowSwitching
11
+ include Waitable
11
12
 
12
13
  attr_reader :driver
13
14
  alias_method :wd, :driver # ensures duck typing with Watir::Element
@@ -122,10 +123,10 @@ module Watir
122
123
  def add_checker(checker = nil, &block)
123
124
  if block_given?
124
125
  @error_checkers << block
125
- elsif Proc === checker
126
+ elsif checker.respond_to? :call
126
127
  @error_checkers << checker
127
128
  else
128
- raise ArgumentError, "argument must be a Proc or block"
129
+ raise ArgumentError, "expected block or object responding to #call"
129
130
  end
130
131
  end
131
132
 
@@ -134,7 +135,7 @@ module Watir
134
135
  end
135
136
 
136
137
  def run_checkers
137
- @error_checkers.each { |e| e[self] }
138
+ @error_checkers.each { |e| e.call(self) }
138
139
  end
139
140
 
140
141
  #
@@ -155,6 +156,7 @@ module Watir
155
156
  def exist?
156
157
  not @closed
157
158
  end
159
+ alias_method :exists?, :exist?
158
160
 
159
161
  def browser
160
162
  self
@@ -1,3 +1,3 @@
1
1
  module Watir
2
- VERSION = "0.2.0.dev"
2
+ VERSION = "0.2.0.dev2"
3
3
  end
@@ -1,11 +1,12 @@
1
1
  # encoding: utf-8
2
2
  module Watir
3
-
4
3
  module Wait
5
4
 
6
5
  class TimeoutError < StandardError
7
6
  end
8
7
 
8
+ INTERVAL = 0.1
9
+
9
10
  class << self
10
11
  #
11
12
  # Wait until the block evaluates to true or times out.
@@ -17,7 +18,7 @@ module Watir
17
18
  until ::Time.now > end_time
18
19
  result = yield(self)
19
20
  return result if result
20
- sleep 0.5
21
+ sleep INTERVAL
21
22
  end
22
23
 
23
24
  raise TimeoutError, message_for(timeout, message)
@@ -32,7 +33,7 @@ module Watir
32
33
 
33
34
  until ::Time.now > end_time
34
35
  return unless yield(self)
35
- sleep 0.5
36
+ sleep INTERVAL
36
37
  end
37
38
 
38
39
  raise TimeoutError, message_for(timeout, message)
@@ -49,6 +50,16 @@ module Watir
49
50
  end # class << self
50
51
  end # Wait
51
52
 
53
+ module Waitable
54
+ def wait_until(*args, &blk)
55
+ Wait.until(*args, &blk)
56
+ end
57
+
58
+ def wait_while(*args, &blk)
59
+ Wait.while(*args, &blk)
60
+ end
61
+ end
62
+
52
63
  #
53
64
  # Wraps an Element so that any subsequent method calls are
54
65
  # put on hold until the element is present (exists and is visible) on the page.
@@ -1,9 +1,6 @@
1
1
  module Watir
2
2
  module WindowSwitching
3
3
 
4
- class NoMatchingWindowFoundException < StandardError
5
- end
6
-
7
4
  def windows(*args)
8
5
  all = @driver.window_handles.map { |handle| Window.new(@driver, :handle => handle) }
9
6
 
@@ -62,7 +59,7 @@ module Watir
62
59
  def exists?
63
60
  handle
64
61
  true
65
- rescue NoMatchingWindowFoundException
62
+ rescue Exception::NoMatchingWindowFoundException
66
63
  false
67
64
  end
68
65
  alias_method :present?, :exists? # for Wait::EventuallyPresent
@@ -122,7 +119,7 @@ module Watir
122
119
  matches?(handle)
123
120
  }
124
121
 
125
- handle or raise NoMatchingWindowFoundException, @selector.inspect
122
+ handle or raise Exception::NoMatchingWindowFoundException, @selector.inspect
126
123
  end
127
124
 
128
125
  def matches?(handle)
data/spec/browser_spec.rb CHANGED
@@ -76,4 +76,26 @@ describe Watir::Browser do
76
76
  end
77
77
  end
78
78
 
79
+ describe "#wait_while" do
80
+ it "delegates to the Wait module" do
81
+ Wait.should_receive(:while).with(3, "foo").and_yield
82
+
83
+ called = false
84
+ browser.wait_while(3, "foo") { called = true }
85
+
86
+ called.should be_true
87
+ end
88
+ end
89
+
90
+ describe "#wait_until" do
91
+ it "delegates to the Wait module" do
92
+ Wait.should_receive(:until).with(3, "foo").and_yield
93
+
94
+ called = false
95
+ browser.wait_until(3, "foo") { called = true }
96
+
97
+ called.should be_true
98
+ end
99
+ end
100
+
79
101
  end
data/spec/wait_spec.rb CHANGED
@@ -71,7 +71,9 @@ describe Watir::Element do
71
71
  it "times out when not given a block" do
72
72
  lambda {
73
73
  browser.div(:id, 'bar').when_present(1).click
74
- }.should raise_error(Watir::Wait::TimeoutError, 'timed out after 1 seconds, waiting for {:id=>"bar", :tag_name=>"div"} to become present')
74
+ }.should raise_error(Watir::Wait::TimeoutError,
75
+ /^timed out after 1 seconds, waiting for (\{:id=>"bar", :tag_name=>"div"\}|\{:tag_name=>"div", :id=>"bar"\}) to become present$/
76
+ )
75
77
  end
76
78
  end
77
79
 
@@ -84,7 +86,9 @@ describe Watir::Element do
84
86
  it "times out if the element doesn't appear" do
85
87
  lambda do
86
88
  browser.div(:id, 'bar').wait_until_present(1)
87
- end.should raise_error(Watir::Wait::TimeoutError, 'timed out after 1 seconds, waiting for {:id=>"bar", :tag_name=>"div"} to become present')
89
+ end.should raise_error(Watir::Wait::TimeoutError,
90
+ /^timed out after 1 seconds, waiting for (\{:id=>"bar", :tag_name=>"div"\}|\{:tag_name=>"div", :id=>"bar"\}) to become present$/
91
+ )
88
92
  end
89
93
  end
90
94
 
@@ -102,7 +106,9 @@ describe Watir::Element do
102
106
  it "times out" do
103
107
  lambda do
104
108
  browser.div(:id, 'foo').wait_while_present(1)
105
- end.should raise_error(Watir::Wait::TimeoutError, 'timed out after 1 seconds, waiting for {:id=>"foo", :tag_name=>"div"} to disappear')
109
+ end.should raise_error(Watir::Wait::TimeoutError,
110
+ /^timed out after 1 seconds, waiting for (\{:id=>"foo", :tag_name=>"div"\}|\{:tag_name=>"div", :id=>"foo"\}) to disappear$/
111
+ )
106
112
  end
107
113
  end
108
114
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: watir-webdriver
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.2.0.dev
5
+ version: 0.2.0.dev2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jari Bakken
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-04 00:00:00 +01:00
13
+ date: 2011-02-07 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency