watir-webdriver 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/watir-webdriver.rb +38 -44
- data/lib/watir-webdriver/browser.rb +4 -0
- data/lib/watir-webdriver/elements/element.rb +17 -1
- data/lib/watir-webdriver/elements/frame.rb +9 -4
- data/lib/watir-webdriver/extensions/wait.rb +1 -141
- data/lib/watir-webdriver/version.rb +1 -1
- data/lib/watir-webdriver/wait.rb +137 -0
- data/lib/watir-webdriver/window_switching.rb +57 -19
- data/spec/browser_spec.rb +19 -0
- data/spec/element_spec.rb +18 -0
- data/spec/wait_spec.rb +19 -22
- data/watir-webdriver.gemspec +1 -1
- metadata +6 -5
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
data/lib/watir-webdriver.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'selenium-webdriver'
|
3
|
+
require 'json'
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
5
|
+
require 'watir-webdriver/version'
|
6
|
+
require 'watir-webdriver/wait'
|
7
|
+
require 'watir-webdriver/exception'
|
8
|
+
require 'watir-webdriver/xpath_support'
|
9
|
+
require 'watir-webdriver/window_switching'
|
10
|
+
require 'watir-webdriver/container'
|
11
|
+
require 'watir-webdriver/locators/element_locator'
|
12
|
+
require 'watir-webdriver/locators/button_locator'
|
13
|
+
require 'watir-webdriver/locators/text_field_locator'
|
14
|
+
require 'watir-webdriver/locators/child_row_locator'
|
15
|
+
require 'watir-webdriver/locators/child_cell_locator'
|
16
|
+
require 'watir-webdriver/browser'
|
16
17
|
|
17
18
|
module Watir
|
18
19
|
include Selenium
|
@@ -29,40 +30,33 @@ module Watir
|
|
29
30
|
|
30
31
|
end
|
31
32
|
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
require
|
43
|
-
require
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
48
|
-
require
|
49
|
-
require
|
50
|
-
require
|
51
|
-
require
|
52
|
-
require
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
33
|
+
require 'watir-webdriver/attribute_helper'
|
34
|
+
require 'watir-webdriver/row_container'
|
35
|
+
require 'watir-webdriver/cell_container'
|
36
|
+
require 'watir-webdriver/element_collection'
|
37
|
+
require 'watir-webdriver/elements/element'
|
38
|
+
require 'watir-webdriver/elements/generated'
|
39
|
+
require 'watir-webdriver/elements/frame'
|
40
|
+
require 'watir-webdriver/elements/input'
|
41
|
+
require 'watir-webdriver/elements/button'
|
42
|
+
require 'watir-webdriver/elements/checkbox'
|
43
|
+
require 'watir-webdriver/elements/file_field'
|
44
|
+
require 'watir-webdriver/elements/image'
|
45
|
+
require 'watir-webdriver/elements/link'
|
46
|
+
require 'watir-webdriver/elements/font'
|
47
|
+
require 'watir-webdriver/elements/radio'
|
48
|
+
require 'watir-webdriver/elements/text_field'
|
49
|
+
require 'watir-webdriver/elements/hidden'
|
50
|
+
require 'watir-webdriver/elements/select'
|
51
|
+
require 'watir-webdriver/elements/form'
|
52
|
+
require 'watir-webdriver/elements/option'
|
53
|
+
require 'watir-webdriver/elements/table'
|
54
|
+
require 'watir-webdriver/elements/table_row'
|
55
|
+
require 'watir-webdriver/elements/table_cell'
|
56
|
+
require 'watir-webdriver/elements/table_section'
|
56
57
|
|
57
58
|
Watir.tag_to_class.freeze
|
58
59
|
|
59
|
-
module Watir
|
60
|
-
module Container
|
61
|
-
|
62
|
-
end # Container
|
63
|
-
end # Watir
|
64
|
-
|
65
|
-
|
66
60
|
# undefine deprecated methods to use them for Element attributes
|
67
61
|
class Object
|
68
62
|
undef_method :id if method_defined? "id"
|
@@ -7,10 +7,12 @@ module Watir
|
|
7
7
|
#
|
8
8
|
|
9
9
|
class Element
|
10
|
+
extend AttributeHelper
|
11
|
+
|
10
12
|
include Exception
|
11
13
|
include Container
|
12
14
|
include Selenium
|
13
|
-
|
15
|
+
include EventuallyPresent
|
14
16
|
|
15
17
|
def initialize(parent, selector)
|
16
18
|
@parent = parent
|
@@ -157,11 +159,25 @@ module Watir
|
|
157
159
|
end
|
158
160
|
alias_method :wd, :element # ensures duck typing with Browser
|
159
161
|
|
162
|
+
#
|
163
|
+
# Returns true if this element is visible on the page
|
164
|
+
#
|
165
|
+
|
160
166
|
def visible?
|
161
167
|
assert_exists
|
162
168
|
@element.displayed?
|
163
169
|
end
|
164
170
|
|
171
|
+
#
|
172
|
+
# Returns true if the element exists and is visible on the page
|
173
|
+
#
|
174
|
+
# @see Watir::Wait
|
175
|
+
#
|
176
|
+
|
177
|
+
def present?
|
178
|
+
exists? && visible?
|
179
|
+
end
|
180
|
+
|
165
181
|
def style(property = nil)
|
166
182
|
if property
|
167
183
|
assert_exists
|
@@ -69,18 +69,23 @@ module Watir
|
|
69
69
|
@element = element
|
70
70
|
@driver = driver
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def ==(other)
|
74
74
|
@element == other.element
|
75
75
|
end
|
76
76
|
alias_method :eql?, :==
|
77
|
-
|
77
|
+
|
78
|
+
def send_keys(*args)
|
79
|
+
switch!
|
80
|
+
@driver.switch_to.active_element.send_keys(*args)
|
81
|
+
end
|
82
|
+
|
78
83
|
protected
|
79
|
-
|
84
|
+
|
80
85
|
def element
|
81
86
|
@element
|
82
87
|
end
|
83
|
-
|
88
|
+
|
84
89
|
private
|
85
90
|
|
86
91
|
def method_missing(meth, *args, &blk)
|
@@ -1,141 +1 @@
|
|
1
|
-
|
2
|
-
module Watir
|
3
|
-
|
4
|
-
#
|
5
|
-
# Module provided by optional require:
|
6
|
-
#
|
7
|
-
# require "watir-webdriver/extensions/wait"
|
8
|
-
#
|
9
|
-
|
10
|
-
module Wait
|
11
|
-
module_function
|
12
|
-
|
13
|
-
class TimeoutError < StandardError
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# Wait until the block evaluates to true or times out.
|
18
|
-
#
|
19
|
-
|
20
|
-
def until(timeout = 30, &block)
|
21
|
-
end_time = ::Time.now + timeout
|
22
|
-
|
23
|
-
until ::Time.now > end_time
|
24
|
-
result = yield(self)
|
25
|
-
return result if result
|
26
|
-
sleep 0.5
|
27
|
-
end
|
28
|
-
|
29
|
-
raise TimeoutError, "timed out after #{timeout} seconds"
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# Wait while the block evaluates to true or times out.
|
34
|
-
#
|
35
|
-
|
36
|
-
def while(timeout = 30, &block)
|
37
|
-
end_time = ::Time.now + timeout
|
38
|
-
|
39
|
-
until ::Time.now > end_time
|
40
|
-
return unless yield(self)
|
41
|
-
sleep 0.5
|
42
|
-
end
|
43
|
-
|
44
|
-
raise TimeoutError, "timed out after #{timeout} seconds"
|
45
|
-
end
|
46
|
-
|
47
|
-
end # Wait
|
48
|
-
|
49
|
-
#
|
50
|
-
# Wraps an Element so that any subsequent method calls are
|
51
|
-
# put on hold until the element is present (exists and is visible) on the page.
|
52
|
-
#
|
53
|
-
|
54
|
-
class WhenPresentDecorator
|
55
|
-
def initialize(element, timeout)
|
56
|
-
@element = element
|
57
|
-
@timeout = timeout
|
58
|
-
end
|
59
|
-
|
60
|
-
def method_missing(m, *args, &block)
|
61
|
-
unless @element.respond_to?(m)
|
62
|
-
raise NoMethodError, "undefined method `#{m}' for #{@element.inspect}:#{@element.class}"
|
63
|
-
end
|
64
|
-
|
65
|
-
Watir::Wait.until(@timeout) { @element.present? }
|
66
|
-
|
67
|
-
@element.__send__(m, *args, &block)
|
68
|
-
end
|
69
|
-
end # WhenPresentDecorator
|
70
|
-
|
71
|
-
class Element
|
72
|
-
|
73
|
-
#
|
74
|
-
# Returns true if the element exists and is visible on the page
|
75
|
-
#
|
76
|
-
# This method is provided by an optional require.
|
77
|
-
# @see Watir::Wait
|
78
|
-
#
|
79
|
-
|
80
|
-
def present?
|
81
|
-
exists? && visible?
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# Waits until the element is present.
|
86
|
-
#
|
87
|
-
# This method is provided by an optional require.
|
88
|
-
# @see Watir::Wait
|
89
|
-
#
|
90
|
-
# Example:
|
91
|
-
# browser.button(:id, 'foo').when_present.click
|
92
|
-
# browser.div(:id, 'bar').when_present { |div| ... }
|
93
|
-
# browser.p(:id, 'baz').when_present(60).text
|
94
|
-
#
|
95
|
-
# @param [Integer] timeout seconds to wait before timing out
|
96
|
-
#
|
97
|
-
|
98
|
-
def when_present(timeout = 30)
|
99
|
-
if block_given?
|
100
|
-
Watir::Wait.until(timeout) { self.present? }
|
101
|
-
yield self
|
102
|
-
else
|
103
|
-
WhenPresentDecorator.new(self, timeout)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
#
|
108
|
-
# Waits until the element is present.
|
109
|
-
#
|
110
|
-
# This method is provided by an optional require.
|
111
|
-
#
|
112
|
-
# @param [Integer] timeout seconds to wait before timing out
|
113
|
-
#
|
114
|
-
# @see Watir::Wait
|
115
|
-
# @see Watir::Element#present?
|
116
|
-
#
|
117
|
-
|
118
|
-
def wait_until_present(timeout = 30)
|
119
|
-
Watir::Wait.until(timeout) { self.present? }
|
120
|
-
end
|
121
|
-
|
122
|
-
#
|
123
|
-
# Waits while the element is present.
|
124
|
-
#
|
125
|
-
# This method is provided by an optional require.
|
126
|
-
#
|
127
|
-
# @param [Integer] timeout seconds to wait before timing out
|
128
|
-
#
|
129
|
-
# @see Watir::Wait
|
130
|
-
# @see Watir::Element#present?
|
131
|
-
#
|
132
|
-
|
133
|
-
def wait_while_present(timeout = 30)
|
134
|
-
Watir::Wait.while(timeout) { self.present? }
|
135
|
-
rescue Selenium::WebDriver::Error::ObsoleteElementError
|
136
|
-
# it's not present
|
137
|
-
end
|
138
|
-
end # Element
|
139
|
-
|
140
|
-
|
141
|
-
end # Watir
|
1
|
+
warn "wait helpers are now loaded by default, please remove require of 'watir-webdriver/extensions/wait'"
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
|
4
|
+
module Wait
|
5
|
+
|
6
|
+
class TimeoutError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
#
|
11
|
+
# Wait until the block evaluates to true or times out.
|
12
|
+
#
|
13
|
+
|
14
|
+
def until(timeout = 30, message = nil, &block)
|
15
|
+
end_time = ::Time.now + timeout
|
16
|
+
|
17
|
+
until ::Time.now > end_time
|
18
|
+
result = yield(self)
|
19
|
+
return result if result
|
20
|
+
sleep 0.5
|
21
|
+
end
|
22
|
+
|
23
|
+
raise TimeoutError, message_for(timeout, message)
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Wait while the block evaluates to true or times out.
|
28
|
+
#
|
29
|
+
|
30
|
+
def while(timeout = 30, message = nil, &block)
|
31
|
+
end_time = ::Time.now + timeout
|
32
|
+
|
33
|
+
until ::Time.now > end_time
|
34
|
+
return unless yield(self)
|
35
|
+
sleep 0.5
|
36
|
+
end
|
37
|
+
|
38
|
+
raise TimeoutError, message_for(timeout, message)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def message_for(timeout, message)
|
44
|
+
err = "timed out after #{timeout} seconds"
|
45
|
+
err << ", #{message}" if message
|
46
|
+
|
47
|
+
err
|
48
|
+
end
|
49
|
+
end # class << self
|
50
|
+
end # Wait
|
51
|
+
|
52
|
+
#
|
53
|
+
# Wraps an Element so that any subsequent method calls are
|
54
|
+
# put on hold until the element is present (exists and is visible) on the page.
|
55
|
+
#
|
56
|
+
|
57
|
+
class WhenPresentDecorator
|
58
|
+
def initialize(element, timeout, message = nil)
|
59
|
+
@element = element
|
60
|
+
@timeout = timeout
|
61
|
+
@message = message
|
62
|
+
end
|
63
|
+
|
64
|
+
def method_missing(m, *args, &block)
|
65
|
+
unless @element.respond_to?(m)
|
66
|
+
raise NoMethodError, "undefined method `#{m}' for #{@element.inspect}:#{@element.class}"
|
67
|
+
end
|
68
|
+
|
69
|
+
Watir::Wait.until(@timeout, @message) { @element.present? }
|
70
|
+
|
71
|
+
@element.__send__(m, *args, &block)
|
72
|
+
end
|
73
|
+
end # WhenPresentDecorator
|
74
|
+
|
75
|
+
#
|
76
|
+
# Convenience methods for things that eventually become present.
|
77
|
+
#
|
78
|
+
# Includers should implement a public #present? and a (possibly private) #selector_string method.
|
79
|
+
#
|
80
|
+
|
81
|
+
module EventuallyPresent
|
82
|
+
#
|
83
|
+
# Waits until the element is present.
|
84
|
+
#
|
85
|
+
# @see Watir::Wait
|
86
|
+
#
|
87
|
+
# Example:
|
88
|
+
# browser.button(:id, 'foo').when_present.click
|
89
|
+
# browser.div(:id, 'bar').when_present { |div| ... }
|
90
|
+
# browser.p(:id, 'baz').when_present(60).text
|
91
|
+
#
|
92
|
+
# @param [Integer] timeout seconds to wait before timing out
|
93
|
+
#
|
94
|
+
|
95
|
+
def when_present(timeout = 30)
|
96
|
+
message = "waiting for #{selector_string} to become present"
|
97
|
+
|
98
|
+
if block_given?
|
99
|
+
Watir::Wait.until(timeout, message) { present? }
|
100
|
+
yield self
|
101
|
+
else
|
102
|
+
WhenPresentDecorator.new(self, timeout, message)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# Waits until the element is present.
|
108
|
+
#
|
109
|
+
# @param [Integer] timeout seconds to wait before timing out
|
110
|
+
#
|
111
|
+
# @see Watir::Wait
|
112
|
+
# @see Watir::Element#present?
|
113
|
+
#
|
114
|
+
|
115
|
+
def wait_until_present(timeout = 30)
|
116
|
+
message = "waiting for #{selector_string} to become present"
|
117
|
+
Watir::Wait.until(timeout, message) { present? }
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# Waits while the element is present.
|
122
|
+
#
|
123
|
+
# @param [Integer] timeout seconds to wait before timing out
|
124
|
+
#
|
125
|
+
# @see Watir::Wait
|
126
|
+
# @see Watir::Element#present?
|
127
|
+
#
|
128
|
+
|
129
|
+
def wait_while_present(timeout = 30)
|
130
|
+
message = "waiting for #{selector_string} to disappear"
|
131
|
+
Watir::Wait.while(timeout, message) { present? }
|
132
|
+
rescue Selenium::WebDriver::Error::ObsoleteElementError
|
133
|
+
# it's not present
|
134
|
+
end
|
135
|
+
|
136
|
+
end # EventuallyPresent
|
137
|
+
end # Watir
|
@@ -5,7 +5,7 @@ module Watir
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def windows(*args)
|
8
|
-
all = @driver.window_handles.map { |
|
8
|
+
all = @driver.window_handles.map { |handle| Window.new(@driver, :handle => handle) }
|
9
9
|
|
10
10
|
if args.empty?
|
11
11
|
all
|
@@ -15,13 +15,11 @@ module Watir
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def window(*args, &blk)
|
18
|
-
win =
|
18
|
+
win = Window.new @driver, extract_selector(args)
|
19
19
|
|
20
|
-
|
21
|
-
win.use(&blk)
|
22
|
-
end
|
20
|
+
win.use(&blk) if block_given?
|
23
21
|
|
24
|
-
win
|
22
|
+
win
|
25
23
|
end
|
26
24
|
|
27
25
|
private
|
@@ -29,10 +27,6 @@ module Watir
|
|
29
27
|
def filter_windows(args, all, method)
|
30
28
|
sel = extract_selector(args)
|
31
29
|
|
32
|
-
if sel.empty?
|
33
|
-
all.find { |w| w.current? }
|
34
|
-
end
|
35
|
-
|
36
30
|
unless sel.keys.all? { |k| [:title, :url].include? k }
|
37
31
|
raise ArgumentError, "invalid window selector: #{sel.inspect}"
|
38
32
|
end
|
@@ -44,27 +38,48 @@ module Watir
|
|
44
38
|
end # WindowSwitching
|
45
39
|
|
46
40
|
class Window
|
47
|
-
|
48
|
-
|
41
|
+
include EventuallyPresent
|
42
|
+
|
43
|
+
def initialize(driver, selector)
|
44
|
+
@driver = driver
|
45
|
+
@selector = selector
|
46
|
+
|
47
|
+
if selector.empty?
|
48
|
+
@handle = driver.window_handle
|
49
|
+
elsif selector.has_key? :handle
|
50
|
+
@handle = selector.delete :handle
|
51
|
+
else
|
52
|
+
unless selector.keys.all? { |k| [:title, :url].include? k }
|
53
|
+
raise ArgumentError, "invalid window selector: #{selector.inspect}"
|
54
|
+
end
|
55
|
+
end
|
49
56
|
end
|
50
57
|
|
51
58
|
def inspect
|
52
|
-
'#<%s:0x%x
|
59
|
+
'#<%s:0x%x located=%s>' % [self.class, hash*2, !!@handle]
|
53
60
|
end
|
54
61
|
|
62
|
+
def exists?
|
63
|
+
handle
|
64
|
+
true
|
65
|
+
rescue NoMatchingWindowFoundException
|
66
|
+
false
|
67
|
+
end
|
68
|
+
alias_method :present?, :exists? # for Wait::EventuallyPresent
|
69
|
+
|
55
70
|
def ==(other)
|
56
71
|
return false unless other.kind_of?(self.class)
|
57
72
|
|
58
|
-
|
73
|
+
handle == other.handle
|
59
74
|
end
|
60
75
|
alias_method :eql?, :==
|
61
76
|
|
62
77
|
def hash
|
63
|
-
|
78
|
+
handle.hash ^ self.class.hash
|
64
79
|
end
|
65
80
|
|
66
81
|
def current?
|
67
|
-
@driver.window_handle ==
|
82
|
+
@driver.window_handle == handle
|
68
83
|
end
|
69
84
|
|
70
85
|
def close
|
@@ -91,14 +106,37 @@ module Watir
|
|
91
106
|
return self
|
92
107
|
end
|
93
108
|
|
94
|
-
@driver.switch_to.window(
|
109
|
+
@driver.switch_to.window(handle, &blk)
|
95
110
|
self
|
96
111
|
end
|
97
112
|
|
98
113
|
protected
|
99
114
|
|
100
|
-
def
|
101
|
-
@
|
115
|
+
def handle
|
116
|
+
@handle ||= locate
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def selector_string
|
122
|
+
@selector.inspect
|
123
|
+
end
|
124
|
+
|
125
|
+
def locate
|
126
|
+
handle = @driver.window_handles.find { |handle|
|
127
|
+
matches?(handle)
|
128
|
+
}
|
129
|
+
|
130
|
+
handle or raise NoMatchingWindowFoundException, @selector.inspect
|
131
|
+
end
|
132
|
+
|
133
|
+
def matches?(handle)
|
134
|
+
@driver.switch_to.window(handle) {
|
135
|
+
matches_title = @selector[:title].nil? || @selector[:title] === @driver.title
|
136
|
+
matches_url = @selector[:url].nil? || @selector[:url] === @driver.current_url
|
137
|
+
|
138
|
+
matches_title && matches_url
|
139
|
+
}
|
102
140
|
end
|
103
141
|
|
104
142
|
end # Window
|
data/spec/browser_spec.rb
CHANGED
@@ -47,6 +47,25 @@ describe Watir::Browser do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
describe "#send_key{,s}" do
|
51
|
+
it "sends keystrokes to the active element" do
|
52
|
+
browser.goto WatirSpec.files + "/forms_with_input_elements.html"
|
53
|
+
|
54
|
+
browser.send_keys "hello"
|
55
|
+
browser.text_field(:id => "new_user_first_name").value.should == "hello"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "sends keys to a frame" do
|
59
|
+
browser.goto WatirSpec.files + "/frames.html"
|
60
|
+
tf = browser.frame.text_field(:id => "senderElement")
|
61
|
+
tf.clear
|
62
|
+
|
63
|
+
browser.frame.send_keys "hello"
|
64
|
+
|
65
|
+
tf.value.should == "hello"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
50
69
|
bug "http://github.com/jarib/watirspec/issues/issue/8", [:webdriver, :ie], [:webdriver, :chrome] do
|
51
70
|
it "raises an error when trying to interact with a closed browser" do
|
52
71
|
b = WatirSpec.new_browser
|
data/spec/element_spec.rb
CHANGED
@@ -10,4 +10,22 @@ describe Watir::Element do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
describe "#present?" do
|
14
|
+
before do
|
15
|
+
browser.goto("file://" + File.expand_path("html/wait.html", File.dirname(__FILE__)))
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns true if the element exists and is visible" do
|
19
|
+
browser.div(:id, 'foo').should be_present
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false if the element exists but is not visible" do
|
23
|
+
browser.div(:id, 'bar').should_not be_present
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns false if the element does not exist" do
|
27
|
+
browser.div(:id, 'should-not-exist').should_not be_present
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
13
31
|
end
|
data/spec/wait_spec.rb
CHANGED
@@ -1,29 +1,40 @@
|
|
1
1
|
require File.expand_path("watirspec/spec_helper", File.dirname(__FILE__))
|
2
|
-
require "watir-webdriver/extensions/wait"
|
3
2
|
|
4
3
|
describe Watir::Wait do
|
5
4
|
describe "#until" do
|
6
5
|
it "waits until the block returns true" do
|
7
|
-
Wait
|
6
|
+
Wait.until(0.5) { true }.should be_true
|
8
7
|
end
|
9
8
|
|
10
9
|
it "times out" do
|
11
10
|
lambda do
|
12
|
-
Wait
|
11
|
+
Wait.until(0.5) { false }
|
13
12
|
end.should raise_error(Watir::Wait::TimeoutError)
|
14
13
|
end
|
14
|
+
|
15
|
+
it "times out with a custom message" do
|
16
|
+
lambda do
|
17
|
+
Wait.until(0.5, "oops") { false }
|
18
|
+
end.should raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
describe "#while" do
|
18
23
|
it "waits while the block returns true" do
|
19
|
-
Wait
|
24
|
+
Wait.while(0.5) { false }.should == nil
|
20
25
|
end
|
21
26
|
|
22
27
|
it "times out" do
|
23
28
|
lambda do
|
24
|
-
Wait
|
29
|
+
Wait.while(0.5) { true }
|
25
30
|
end.should raise_error(Watir::Wait::TimeoutError)
|
26
31
|
end
|
32
|
+
|
33
|
+
it "times out with a custom message" do
|
34
|
+
lambda do
|
35
|
+
Wait.while(0.5, "oops") { true }
|
36
|
+
end.should raise_error(Watir::Wait::TimeoutError, "timed out after 0.5 seconds, oops")
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
29
40
|
|
@@ -33,20 +44,6 @@ describe Watir::Element do
|
|
33
44
|
browser.goto("file://" + File.expand_path("html/wait.html", File.dirname(__FILE__)))
|
34
45
|
end
|
35
46
|
|
36
|
-
describe "#present?" do
|
37
|
-
it "returns true if the element exists and is visible" do
|
38
|
-
browser.div(:id, 'foo').should be_present
|
39
|
-
end
|
40
|
-
|
41
|
-
it "returns false if the element exists but is not visible" do
|
42
|
-
browser.div(:id, 'bar').should_not be_present
|
43
|
-
end
|
44
|
-
|
45
|
-
it "returns false if the element does not exist" do
|
46
|
-
browser.div(:id, 'should-not-exist').should_not be_present
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
47
|
describe "#when_present" do
|
51
48
|
it "yields when the element becomes present" do
|
52
49
|
called = false
|
@@ -74,7 +71,7 @@ describe Watir::Element do
|
|
74
71
|
it "times out when not given a block" do
|
75
72
|
lambda {
|
76
73
|
browser.div(:id, 'bar').when_present(1).click
|
77
|
-
}.should raise_error(Watir::Wait::TimeoutError)
|
74
|
+
}.should raise_error(Watir::Wait::TimeoutError, 'timed out after 1 seconds, waiting for {:id=>"bar", :tag_name=>"div"} to become present')
|
78
75
|
end
|
79
76
|
end
|
80
77
|
|
@@ -87,7 +84,7 @@ describe Watir::Element do
|
|
87
84
|
it "times out if the element doesn't appear" do
|
88
85
|
lambda do
|
89
86
|
browser.div(:id, 'bar').wait_until_present(1)
|
90
|
-
end.should raise_error(Watir::Wait::TimeoutError)
|
87
|
+
end.should raise_error(Watir::Wait::TimeoutError, 'timed out after 1 seconds, waiting for {:id=>"bar", :tag_name=>"div"} to become present')
|
91
88
|
end
|
92
89
|
end
|
93
90
|
|
@@ -105,7 +102,7 @@ describe Watir::Element do
|
|
105
102
|
it "times out" do
|
106
103
|
lambda do
|
107
104
|
browser.div(:id, 'foo').wait_while_present(1)
|
108
|
-
end.should raise_error(Watir::Wait::TimeoutError)
|
105
|
+
end.should raise_error(Watir::Wait::TimeoutError, 'timed out after 1 seconds, waiting for {:id=>"foo", :tag_name=>"div"} to disappear')
|
109
106
|
end
|
110
107
|
end
|
111
108
|
|
data/watir-webdriver.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_dependency "selenium-webdriver", '>= 0.1.2'
|
23
23
|
|
24
|
-
s.add_development_dependency "rspec", "~> 2.
|
24
|
+
s.add_development_dependency "rspec", "~> 2.3.0"
|
25
25
|
s.add_development_dependency "yard", "~> 0.6"
|
26
26
|
s.add_development_dependency "webidl", ">= 0.0.6"
|
27
27
|
s.add_development_dependency "sinatra", "~> 1.0"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 9
|
9
|
+
version: 0.1.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jari Bakken
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-28 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -42,9 +42,9 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
segments:
|
44
44
|
- 2
|
45
|
-
-
|
45
|
+
- 3
|
46
46
|
- 0
|
47
|
-
version: 2.
|
47
|
+
version: 2.3.0
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- lib/watir-webdriver/locators/text_field_locator.rb
|
181
181
|
- lib/watir-webdriver/row_container.rb
|
182
182
|
- lib/watir-webdriver/version.rb
|
183
|
+
- lib/watir-webdriver/wait.rb
|
183
184
|
- lib/watir-webdriver/window_switching.rb
|
184
185
|
- lib/watir-webdriver/xpath_support.rb
|
185
186
|
- lib/yard/handlers/watir.rb
|