watir-webdriver 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Rakefile +0 -7
- data/lib/watir-webdriver.rb +0 -1
- data/lib/watir-webdriver/browser.rb +22 -5
- data/lib/watir-webdriver/elements/button.rb +0 -9
- data/lib/watir-webdriver/elements/checkbox.rb +0 -8
- data/lib/watir-webdriver/elements/file_field.rb +0 -8
- data/lib/watir-webdriver/elements/frame.rb +55 -63
- data/lib/watir-webdriver/elements/generated.rb +2 -1
- data/lib/watir-webdriver/elements/input.rb +0 -14
- data/lib/watir-webdriver/elements/radio.rb +0 -7
- data/lib/watir-webdriver/elements/text_field.rb +0 -10
- data/lib/watir-webdriver/version.rb +1 -1
- data/spec/browser_spec.rb +23 -4
- data/spec/html/wait.html +1 -1
- data/spec/spec_helper.rb +7 -0
- data/spec/wait_spec.rb +35 -21
- data/support/html5.html +1430 -835
- data/watir-webdriver.gemspec +3 -3
- metadata +5 -16
- data/lib/watir-webdriver/core_ext/string.rb +0 -22
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -8,13 +8,6 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
8
8
|
end
|
9
9
|
|
10
10
|
namespace :spec do
|
11
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
12
|
-
spec.ruby_opts = "-I lib:spec"
|
13
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
14
|
-
spec.rcov = true
|
15
|
-
spec.rcov_opts = %w[--exclude spec,ruby-debug,/Library/Ruby,.gem --include lib/watir-webdriver]
|
16
|
-
end
|
17
|
-
|
18
11
|
RSpec::Core::RakeTask.new(:html) do |spec|
|
19
12
|
spec.ruby_opts = "-I lib:spec"
|
20
13
|
spec.pattern = 'spec/**/*_spec.rb'
|
data/lib/watir-webdriver.rb
CHANGED
@@ -112,11 +112,7 @@ module Watir
|
|
112
112
|
args.map! { |e| e.kind_of?(Watir::Element) ? e.element : e }
|
113
113
|
returned = @driver.execute_script(script, *args)
|
114
114
|
|
115
|
-
|
116
|
-
Watir.element_class_for(returned.tag_name).new(self, :element => returned)
|
117
|
-
else
|
118
|
-
returned
|
119
|
-
end
|
115
|
+
wrap_elements_in(returned)
|
120
116
|
end
|
121
117
|
|
122
118
|
def add_checker(checker = nil, &block)
|
@@ -160,5 +156,26 @@ module Watir
|
|
160
156
|
self
|
161
157
|
end
|
162
158
|
|
159
|
+
private
|
160
|
+
|
161
|
+
def wrap_elements_in(obj)
|
162
|
+
case obj
|
163
|
+
when WebDriver::Element
|
164
|
+
wrap_element(obj)
|
165
|
+
when Array
|
166
|
+
obj.map { |e| wrap_elements_in(e) }
|
167
|
+
when Hash
|
168
|
+
obj.each { |k,v| obj[k] = wrap_elements_in(v) }
|
169
|
+
|
170
|
+
obj
|
171
|
+
else
|
172
|
+
obj
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def wrap_element(element)
|
177
|
+
Watir.element_class_for(element.tag_name).new(self, :element => element)
|
178
|
+
end
|
179
|
+
|
163
180
|
end # Browser
|
164
181
|
end # Watir
|
@@ -14,15 +14,6 @@ module Watir
|
|
14
14
|
|
15
15
|
VALID_TYPES = %w[button reset submit image]
|
16
16
|
|
17
|
-
def self.from(parent, element)
|
18
|
-
if element.tag_name == "button" ||
|
19
|
-
element.tag_name == "input" && VALID_TYPES.include?(element.attribute(:type))
|
20
|
-
Button.new(parent, :element => element)
|
21
|
-
else
|
22
|
-
raise TypeError, "expected button or input[@type=#{VALID_TYPES.join("|")}] for #{element.inspect}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
17
|
#
|
27
18
|
# Returns the text of the button.
|
28
19
|
#
|
@@ -3,14 +3,6 @@
|
|
3
3
|
module Watir
|
4
4
|
class CheckBox < Input
|
5
5
|
|
6
|
-
def self.from(parent, element)
|
7
|
-
if element.attribute(:type) != "checkbox"
|
8
|
-
raise TypeError, "expected type=checkbox for #{element.inspect}"
|
9
|
-
end
|
10
|
-
|
11
|
-
super
|
12
|
-
end
|
13
|
-
|
14
6
|
#
|
15
7
|
# Set this checkbox to the given value
|
16
8
|
#
|
@@ -1,14 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Watir
|
3
3
|
class FileField < Input
|
4
|
-
def self.from(parent, element)
|
5
|
-
if element.attribute(:type) != "file"
|
6
|
-
raise TypeError, "expected type=file for #{element.inspect}"
|
7
|
-
end
|
8
|
-
|
9
|
-
super
|
10
|
-
end
|
11
|
-
|
12
4
|
#
|
13
5
|
# Set the file field to the given path
|
14
6
|
#
|
@@ -2,30 +2,24 @@
|
|
2
2
|
module Watir
|
3
3
|
class Frame < HTMLElement
|
4
4
|
|
5
|
-
VALID_LOCATORS = [:id, :name, :index]
|
6
|
-
|
7
|
-
def initialize(*args)
|
8
|
-
super
|
9
|
-
@frame_id = nil
|
10
|
-
end
|
11
|
-
|
12
5
|
def locate
|
13
6
|
@parent.assert_exists
|
14
7
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
locate_iframe || locate_frame
|
20
|
-
else
|
21
|
-
switch!
|
22
|
-
driver
|
23
|
-
end
|
8
|
+
element = locate_iframe || locate_frame
|
9
|
+
element or raise UnknownFrameException, "unable to locate frame/iframe using #{selector_string}"
|
10
|
+
|
11
|
+
FramedDriver.new(element, driver)
|
24
12
|
end
|
25
13
|
|
26
14
|
def assert_exists
|
27
|
-
|
28
|
-
|
15
|
+
if element = @selector[:element]
|
16
|
+
@parent.assert_exists
|
17
|
+
@element = FramedDriver.new(element, driver)
|
18
|
+
else
|
19
|
+
@element = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
super
|
29
23
|
end
|
30
24
|
|
31
25
|
def execute_script(*args)
|
@@ -46,65 +40,63 @@ module Watir
|
|
46
40
|
|
47
41
|
def locate_iframe
|
48
42
|
# hack - frame doesn't have IFrame's attributes either
|
49
|
-
|
50
|
-
|
51
|
-
if @iframe
|
52
|
-
switch_to_iframe @iframe
|
53
|
-
driver
|
54
|
-
end
|
43
|
+
IFrame.new(@parent, @selector.merge(:tag_name => "iframe")).locate
|
55
44
|
end
|
56
45
|
|
57
46
|
def locate_frame
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
@frame_id = @selector[loc]
|
65
|
-
|
66
|
-
unless [String, Integer].any? { |e| @frame_id.kind_of?(e) }
|
67
|
-
raise TypeError, "can't locate frame using #{@frame_id.inspect}:#{@frame_id.class}"
|
68
|
-
end
|
69
|
-
|
70
|
-
switch!
|
47
|
+
locator = locator_class.new(@parent.wd, @selector.merge(:tag_name => "frame"), self.class.attribute_list)
|
48
|
+
locator.locate
|
49
|
+
end
|
50
|
+
end # Frame
|
71
51
|
|
72
|
-
|
52
|
+
module Container
|
53
|
+
def frame(*args)
|
54
|
+
Frame.new(self, extract_selector(args))
|
73
55
|
end
|
74
56
|
|
75
|
-
def
|
76
|
-
|
77
|
-
rescue Selenium::WebDriver::Error::NoSuchFrameError => e
|
78
|
-
raise UnknownFrameException, e.message
|
57
|
+
def frames(*args)
|
58
|
+
FrameCollection.new(self, extract_selector(args).merge(:tag_name => /^(iframe|frame)$/)) # hack
|
79
59
|
end
|
60
|
+
end
|
80
61
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
62
|
+
# @api private
|
63
|
+
#
|
64
|
+
# another hack..
|
65
|
+
#
|
86
66
|
|
87
|
-
|
88
|
-
|
67
|
+
class FramedDriver
|
68
|
+
def initialize(element, driver)
|
69
|
+
@element = element
|
70
|
+
@driver = driver
|
71
|
+
end
|
72
|
+
|
73
|
+
def ==(other)
|
74
|
+
@element == other.element
|
75
|
+
end
|
76
|
+
alias_method :eql?, :==
|
77
|
+
|
78
|
+
protected
|
79
|
+
|
80
|
+
def element
|
81
|
+
@element
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
89
85
|
|
90
|
-
|
91
|
-
|
92
|
-
|
86
|
+
def method_missing(meth, *args, &blk)
|
87
|
+
if @driver.respond_to?(meth)
|
88
|
+
switch!
|
89
|
+
@driver.send(meth, *args, &blk)
|
93
90
|
else
|
94
|
-
|
91
|
+
@element.send(meth, *args, &blk)
|
95
92
|
end
|
96
|
-
|
97
|
-
driver.switch_to.frame loc
|
98
93
|
end
|
99
|
-
end # Frame
|
100
94
|
|
101
|
-
|
102
|
-
|
103
|
-
|
95
|
+
def switch!
|
96
|
+
@driver.switch_to.frame @element
|
97
|
+
rescue Selenium::WebDriver::Error::NoSuchFrameError => e
|
98
|
+
raise UnknownFrameException, e.message
|
104
99
|
end
|
105
100
|
|
106
|
-
|
107
|
-
FrameCollection.new(self, extract_selector(args))
|
108
|
-
end
|
109
|
-
end
|
101
|
+
end # FramedDriver
|
110
102
|
end # Watir
|
@@ -412,7 +412,7 @@ module Watir
|
|
412
412
|
end
|
413
413
|
end
|
414
414
|
class Track < HTMLElement
|
415
|
-
attributes(:string => [:kind, :src, :
|
415
|
+
attributes(:string => [:kind, :src, :srclang, :label, :track], :bool => [:default])
|
416
416
|
end
|
417
417
|
class TrackCollection < ElementCollection
|
418
418
|
def element_class
|
@@ -753,6 +753,7 @@ module Watir
|
|
753
753
|
|
754
754
|
|
755
755
|
|
756
|
+
|
756
757
|
module Container
|
757
758
|
#
|
758
759
|
# @return [Anchor]
|
@@ -4,20 +4,6 @@ module Watir
|
|
4
4
|
|
5
5
|
alias_method :readonly?, :read_only?
|
6
6
|
|
7
|
-
#
|
8
|
-
# @private
|
9
|
-
#
|
10
|
-
# subclasses can use this to validate the incoming element
|
11
|
-
#
|
12
|
-
|
13
|
-
def self.from(parent, element)
|
14
|
-
unless element.tag_name == "input"
|
15
|
-
raise TypeError, "can't create #{self} from #{element.inspect}"
|
16
|
-
end
|
17
|
-
|
18
|
-
new(parent, :element => element)
|
19
|
-
end
|
20
|
-
|
21
7
|
def enabled?
|
22
8
|
!disabled?
|
23
9
|
end
|
@@ -1,13 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Watir
|
3
3
|
class Radio < Input
|
4
|
-
def self.from(parent, element)
|
5
|
-
if element.attribute(:type) != "radio"
|
6
|
-
raise TypeError, "expected type=radio for #{element.inspect}"
|
7
|
-
end
|
8
|
-
|
9
|
-
super
|
10
|
-
end
|
11
4
|
#
|
12
5
|
# Select this radio button.
|
13
6
|
#
|
@@ -5,16 +5,6 @@ module Watir
|
|
5
5
|
attributes Watir::TextArea.typed_attributes
|
6
6
|
remove_method :type # we want Input#type here, which was overriden by TextArea's attributes
|
7
7
|
|
8
|
-
def self.from(parent, element)
|
9
|
-
type = element.attribute(:type)
|
10
|
-
|
11
|
-
if TextFieldLocator::NON_TEXT_TYPES.include?(type)
|
12
|
-
raise TypeError, "expected type != #{type} for #{element.inspect}"
|
13
|
-
end
|
14
|
-
|
15
|
-
super
|
16
|
-
end
|
17
|
-
|
18
8
|
#
|
19
9
|
# Clear the element, the type in the given value.
|
20
10
|
#
|
data/spec/browser_spec.rb
CHANGED
@@ -21,10 +21,29 @@ describe Watir::Browser do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#execute_script" do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
returned.
|
24
|
+
before { browser.goto(WatirSpec.files + "/definition_lists.html") }
|
25
|
+
|
26
|
+
it "wraps elements as Watir objects" do
|
27
|
+
returned = browser.execute_script("return document.body")
|
28
|
+
returned.should be_kind_of(Watir::Body)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "wraps elements in an array" do
|
32
|
+
list = browser.execute_script("return [document.body];")
|
33
|
+
list.size.should == 1
|
34
|
+
list.first.should be_kind_of(Watir::Body)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "wraps elements in a Hash" do
|
38
|
+
hash = browser.execute_script("return {element: document.body};")
|
39
|
+
hash['element'].should be_kind_of(Watir::Body)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "wraps elements in a deep object" do
|
43
|
+
hash = browser.execute_script("return {elements: [document.body], body: {element: document.body }}")
|
44
|
+
|
45
|
+
hash['elements'].first.should be_kind_of(Watir::Body)
|
46
|
+
hash['body']['element'].should be_kind_of(Watir::Body)
|
28
47
|
end
|
29
48
|
end
|
30
49
|
|
data/spec/html/wait.html
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
<body>
|
22
22
|
<div id="foo" style="display:block;">foo</div>
|
23
|
-
<div id="bar" style="display:none;">bar</div>
|
23
|
+
<div id="bar" style="display:none;" onclick='this.innerHTML = "changed"'>bar</div>
|
24
24
|
<a id="show_bar" href="#" onclick="setTimeoutDisplay('bar', 'block', 500);">show bar</a>
|
25
25
|
<a id="hide_foo" href="#" onclick="setTimeoutDisplay('foo', 'none', 500);">hide foo</a>
|
26
26
|
<a id="remove_foo" href="#" onclick="setTimeoutRemove('foo', 500);">remove foo</a>
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
4
|
|
5
|
+
if ENV['coverage']
|
6
|
+
raise "simplecov only works on Ruby 1.9" unless RUBY_VERSION =~ /^1\.9/
|
7
|
+
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start { add_filter "spec/" }
|
10
|
+
end
|
11
|
+
|
5
12
|
require 'watir-webdriver'
|
6
13
|
require 'locator_spec_helper'
|
7
14
|
require 'rubygems'
|
data/spec/wait_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Watir::Wait do
|
|
6
6
|
it "waits until the block returns true" do
|
7
7
|
Wait::until(1) { true }.should be_true
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "times out" do
|
11
11
|
lambda do
|
12
12
|
Wait::until(1) { false }
|
@@ -18,7 +18,7 @@ describe Watir::Wait do
|
|
18
18
|
it "waits while the block returns true" do
|
19
19
|
Wait::while(1) { false }.should == nil
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "times out" do
|
23
23
|
lambda do
|
24
24
|
Wait::while(1) { true }
|
@@ -37,40 +37,54 @@ describe Watir::Element do
|
|
37
37
|
it "returns true if the element exists and is visible" do
|
38
38
|
browser.div(:id, 'foo').should be_present
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "returns false if the element exists but is not visible" do
|
42
42
|
browser.div(:id, 'bar').should_not be_present
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "returns false if the element does not exist" do
|
46
46
|
browser.div(:id, 'should-not-exist').should_not be_present
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
describe "#when_present" do
|
51
|
-
it "
|
52
|
-
browser.a(:id, 'show_bar').click
|
51
|
+
it "yields when the element becomes present" do
|
53
52
|
called = false
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
|
54
|
+
browser.a(:id, 'show_bar').click
|
55
|
+
browser.div(:id, 'bar').when_present(1) { called = true }
|
56
|
+
|
57
|
+
called.should be_true
|
58
58
|
end
|
59
|
-
|
60
|
-
it "
|
61
|
-
|
59
|
+
|
60
|
+
it "invokes subsequent method calls when the element becomes present" do
|
61
|
+
browser.a(:id, 'show_bar').click
|
62
|
+
|
63
|
+
bar = browser.div(:id, 'bar')
|
64
|
+
bar.when_present(1).click
|
65
|
+
bar.text.should == "changed"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "times out when given a block" do
|
69
|
+
lambda {
|
62
70
|
browser.div(:id, 'bar').when_present(1) {}
|
63
|
-
|
71
|
+
}.should raise_error(Watir::Wait::TimeoutError)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "times out when not given a block" do
|
75
|
+
lambda {
|
76
|
+
browser.div(:id, 'bar').when_present(1).click
|
77
|
+
}.should raise_error(Watir::Wait::TimeoutError)
|
64
78
|
end
|
65
79
|
end
|
66
80
|
|
67
81
|
describe "#wait_until_present" do
|
68
|
-
it "
|
82
|
+
it "it waits until the element appears" do
|
69
83
|
browser.a(:id, 'show_bar').click
|
70
84
|
browser.div(:id, 'bar').wait_until_present(1)
|
71
85
|
end
|
72
|
-
|
73
|
-
it "times out" do
|
86
|
+
|
87
|
+
it "times out if the element doesn't appear" do
|
74
88
|
lambda do
|
75
89
|
browser.div(:id, 'bar').wait_until_present(1)
|
76
90
|
end.should raise_error(Watir::Wait::TimeoutError)
|
@@ -87,12 +101,12 @@ describe Watir::Element do
|
|
87
101
|
browser.a(:id, 'remove_foo').click
|
88
102
|
browser.div(:id, 'foo').wait_while_present(1)
|
89
103
|
end
|
90
|
-
|
91
|
-
it "times out" do
|
104
|
+
|
105
|
+
it "times out" do
|
92
106
|
lambda do
|
93
107
|
browser.div(:id, 'foo').wait_while_present(1)
|
94
108
|
end.should raise_error(Watir::Wait::TimeoutError)
|
95
109
|
end
|
96
110
|
end
|
97
|
-
|
111
|
+
|
98
112
|
end
|