watir-webdriver 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +48 -0
- data/Rakefile +23 -8
- data/VERSION +1 -1
- data/lib/watir-webdriver.rb +7 -5
- data/lib/watir-webdriver/browser.rb +9 -2
- data/lib/watir-webdriver/browserbot.js +5 -2
- data/lib/watir-webdriver/container.rb +6 -9
- data/lib/watir-webdriver/{collections/element_collection.rb → element_collection.rb} +5 -0
- data/lib/watir-webdriver/elements/button.rb +5 -4
- data/lib/watir-webdriver/{element.rb → elements/element.rb} +29 -5
- data/lib/watir-webdriver/elements/file_field.rb +21 -4
- data/lib/watir-webdriver/elements/frame.rb +1 -1
- data/lib/watir-webdriver/elements/generated.rb +750 -750
- data/lib/watir-webdriver/elements/image.rb +6 -0
- data/lib/watir-webdriver/elements/link.rb +0 -4
- data/lib/watir-webdriver/elements/select.rb +22 -24
- data/lib/watir-webdriver/elements/table_row.rb +11 -1
- data/lib/watir-webdriver/elements/text_field.rb +5 -15
- data/lib/watir-webdriver/extensions/wait.rb +107 -0
- data/lib/watir-webdriver/html/generator.rb +1 -1
- data/lib/watir-webdriver/html/util.rb +1 -10
- data/lib/watir-webdriver/html/visitor.rb +2 -14
- data/lib/watir-webdriver/locators/button_locator.rb +22 -3
- data/lib/watir-webdriver/locators/element_locator.rb +54 -28
- data/lib/watir-webdriver/locators/table_row_locator.rb +3 -1
- data/lib/watir-webdriver/locators/text_field_locator.rb +7 -3
- data/lib/watir-webdriver/window_switching.rb +78 -0
- data/spec/browser_spec.rb +43 -0
- data/spec/container_spec.rb +43 -0
- data/spec/element_locator_spec.rb +305 -0
- data/spec/element_spec.rb +34 -5
- data/spec/html/closeable.html +13 -0
- data/spec/html/data_attributes.html +9 -0
- data/spec/html/wait.html +27 -0
- data/spec/html/window_switching.html +12 -0
- data/spec/input_spec.rb +14 -2
- data/spec/locator_spec_helper.rb +37 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/wait_spec.rb +98 -0
- data/spec/watirspec/area_spec.rb +4 -4
- data/spec/watirspec/browser_spec.rb +37 -35
- data/spec/watirspec/button_spec.rb +22 -17
- data/spec/watirspec/buttons_spec.rb +1 -1
- data/spec/watirspec/checkbox_spec.rb +4 -0
- data/spec/watirspec/checkboxes_spec.rb +1 -1
- data/spec/watirspec/collections_spec.rb +4 -2
- data/spec/watirspec/dd_spec.rb +4 -0
- data/spec/watirspec/dds_spec.rb +1 -1
- data/spec/watirspec/del_spec.rb +4 -0
- data/spec/watirspec/dels_spec.rb +1 -1
- data/spec/watirspec/div_spec.rb +38 -12
- data/spec/watirspec/divs_spec.rb +1 -1
- data/spec/watirspec/dl_spec.rb +20 -6
- data/spec/watirspec/dls_spec.rb +1 -1
- data/spec/watirspec/dt_spec.rb +4 -0
- data/spec/watirspec/dts_spec.rb +1 -1
- data/spec/watirspec/em_spec.rb +4 -0
- data/spec/watirspec/ems_spec.rb +1 -1
- data/spec/watirspec/filefield_spec.rb +37 -2
- data/spec/watirspec/filefields_spec.rb +1 -1
- data/spec/watirspec/font_spec.rb +4 -0
- data/spec/watirspec/form_spec.rb +4 -0
- data/spec/watirspec/forms_spec.rb +6 -4
- data/spec/watirspec/frame_spec.rb +6 -0
- data/spec/watirspec/hidden_spec.rb +5 -4
- data/spec/watirspec/hiddens_spec.rb +1 -1
- data/spec/watirspec/hn_spec.rb +4 -0
- data/spec/watirspec/image_spec.rb +4 -0
- data/spec/watirspec/images_spec.rb +1 -1
- data/spec/watirspec/ins_spec.rb +4 -0
- data/spec/watirspec/inses_spec.rb +1 -1
- data/spec/watirspec/label_spec.rb +4 -0
- data/spec/watirspec/labels_spec.rb +2 -2
- data/spec/watirspec/li_spec.rb +4 -0
- data/spec/watirspec/link_spec.rb +15 -10
- data/spec/watirspec/links_spec.rb +6 -0
- data/spec/watirspec/lis_spec.rb +1 -1
- data/spec/watirspec/map_spec.rb +4 -0
- data/spec/watirspec/maps_spec.rb +1 -1
- data/spec/watirspec/meta_spec.rb +4 -0
- data/spec/watirspec/metas_spec.rb +1 -1
- data/spec/watirspec/ol_spec.rb +23 -9
- data/spec/watirspec/option_spec.rb +19 -7
- data/spec/watirspec/p_spec.rb +4 -0
- data/spec/watirspec/pre_spec.rb +4 -0
- data/spec/watirspec/pres_spec.rb +1 -1
- data/spec/watirspec/ps_spec.rb +1 -1
- data/spec/watirspec/radio_spec.rb +22 -13
- data/spec/watirspec/radios_spec.rb +6 -0
- data/spec/watirspec/select_list_spec.rb +29 -17
- data/spec/watirspec/select_lists_spec.rb +6 -0
- data/spec/watirspec/span_spec.rb +10 -2
- data/spec/watirspec/spans_spec.rb +1 -1
- data/spec/watirspec/strong_spec.rb +14 -4
- data/spec/watirspec/table_body_spec.rb +4 -0
- data/spec/watirspec/table_cell_spec.rb +9 -3
- data/spec/watirspec/table_cells_spec.rb +0 -1
- data/spec/watirspec/table_footer_spec.rb +4 -0
- data/spec/watirspec/table_header_spec.rb +4 -0
- data/spec/watirspec/table_row_spec.rb +15 -7
- data/spec/watirspec/table_rows_spec.rb +2 -2
- data/spec/watirspec/table_spec.rb +13 -7
- data/spec/watirspec/tables_spec.rb +1 -1
- data/spec/watirspec/text_field_spec.rb +21 -12
- data/spec/watirspec/text_fields_spec.rb +6 -0
- data/spec/watirspec/ul_spec.rb +4 -0
- data/spec/window_switching_spec.rb +116 -0
- data/watir-webdriver.gemspec +38 -16
- metadata +51 -27
- data/lib/watir-webdriver/collections/table_row_collection.rb +0 -11
@@ -9,6 +9,8 @@ module Watir
|
|
9
9
|
find_all_by_multiple
|
10
10
|
end
|
11
11
|
|
12
|
+
private
|
13
|
+
|
12
14
|
def build_xpath(selectors)
|
13
15
|
return if selectors.values.any? { |e| e.kind_of? Regexp }
|
14
16
|
|
@@ -34,14 +36,14 @@ module Watir
|
|
34
36
|
def lhs_for(key)
|
35
37
|
if @building == :input && key == :text
|
36
38
|
"@value"
|
37
|
-
elsif @building == :textarea &&
|
39
|
+
elsif @building == :textarea && key == :value
|
38
40
|
"text()"
|
39
41
|
else
|
40
42
|
super
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
|
-
def matches_selector?(
|
46
|
+
def matches_selector?(element, rx_selector)
|
45
47
|
rx_selector = rx_selector.dup
|
46
48
|
|
47
49
|
[:text, :value, :label].each do |key|
|
@@ -54,8 +56,10 @@ module Watir
|
|
54
56
|
super
|
55
57
|
end
|
56
58
|
|
59
|
+
VALID_TEXT_FIELD_TAGS = %w[input textarea]
|
60
|
+
|
57
61
|
def tag_name_matches?(element, _)
|
58
|
-
|
62
|
+
VALID_TEXT_FIELD_TAGS.include?(element.tag_name)
|
59
63
|
end
|
60
64
|
end # TextFieldLocator
|
61
65
|
end # Watir
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Watir
|
2
|
+
module WindowSwitching
|
3
|
+
|
4
|
+
def windows(*args)
|
5
|
+
wins = @driver.window_handles.map do |id|
|
6
|
+
Window.new(@driver, id)
|
7
|
+
end
|
8
|
+
|
9
|
+
if args.empty?
|
10
|
+
wins
|
11
|
+
else
|
12
|
+
filter_windows(args, wins, :select)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def window(*args, &blk)
|
17
|
+
win = filter_windows(args, windows, :find)
|
18
|
+
|
19
|
+
if win && block_given?
|
20
|
+
win.use(&blk)
|
21
|
+
end
|
22
|
+
|
23
|
+
win
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def filter_windows(args, wins, method)
|
29
|
+
sel = extract_selector(args)
|
30
|
+
|
31
|
+
unless sel.keys.all? { |k| [:title, :url].include? k }
|
32
|
+
raise ArgumentError, "invalid window selector: #{sel}"
|
33
|
+
end
|
34
|
+
|
35
|
+
wins.send(method) do |win|
|
36
|
+
sel.all? { |key, value| value === win.send(key) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end # WindowSwitching
|
40
|
+
|
41
|
+
class Window
|
42
|
+
def initialize(driver, id)
|
43
|
+
@driver, @id = driver, id
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def inspect
|
48
|
+
'#<%s:0x%x id=%s>' % [self.class, hash*2, @id.to_s]
|
49
|
+
end
|
50
|
+
|
51
|
+
def current?
|
52
|
+
@driver.window_handle == @id
|
53
|
+
end
|
54
|
+
|
55
|
+
def close
|
56
|
+
use { @driver.close }
|
57
|
+
end
|
58
|
+
|
59
|
+
def title
|
60
|
+
title = nil
|
61
|
+
use { title = @driver.title }
|
62
|
+
|
63
|
+
title
|
64
|
+
end
|
65
|
+
|
66
|
+
def url
|
67
|
+
url = nil
|
68
|
+
use { url = @driver.current_url }
|
69
|
+
|
70
|
+
url
|
71
|
+
end
|
72
|
+
|
73
|
+
def use(&blk)
|
74
|
+
@driver.switch_to.window(@id, &blk)
|
75
|
+
self
|
76
|
+
end
|
77
|
+
end # Window
|
78
|
+
end # Watir
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
|
4
|
+
describe Watir::Browser do
|
5
|
+
|
6
|
+
describe ".new" do
|
7
|
+
it "passes the args to webdriver" do
|
8
|
+
Selenium::WebDriver.should_receive(:for).with(:firefox, :foo).and_return(nil)
|
9
|
+
Watir::Browser.new(:firefox, :foo)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "takes a Driver instance as argument" do
|
13
|
+
mock_driver = mock(Selenium::WebDriver::Driver)
|
14
|
+
Selenium::WebDriver::Driver.should_receive(:===).with(mock_driver).and_return(true)
|
15
|
+
|
16
|
+
lambda { Watir::Browser.new(mock_driver) }.should_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it "raises ArgumentError for invalid args" do
|
20
|
+
lambda { Watir::Browser.new(Object.new) }.should raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#execute_script" do
|
25
|
+
it "returns DOM elements as Watir objects" do
|
26
|
+
browser.goto(WatirSpec.files + "/definition_lists.html")
|
27
|
+
returned = browser.execute_script("return document.getElementById('experience-list')")
|
28
|
+
returned.should be_kind_of(Watir::DList)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
bug "http://github.com/jarib/watirspec/issues/issue/8", [:webdriver, :ie], [:webdriver, :chrome] do
|
33
|
+
it "raises an error when trying to interact with a closed browser" do
|
34
|
+
b = WatirSpec.new_browser
|
35
|
+
b.goto(WatirSpec.files + "/definition_lists.html")
|
36
|
+
b.close
|
37
|
+
|
38
|
+
lambda { b.dl(:id => "experience-list").id }.should raise_error(Error, "browser was closed")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
|
4
|
+
describe Watir::Container do
|
5
|
+
before { @container = Object.new.extend(Watir::Container) }
|
6
|
+
|
7
|
+
describe "#extract_selector" do
|
8
|
+
before do
|
9
|
+
def @container.public_extract_selector(*args)
|
10
|
+
extract_selector(*args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "converts 2-arg selector into a hash" do
|
15
|
+
@container.public_extract_selector([:how, 'what']).
|
16
|
+
should == { :how => 'what' }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the hash given" do
|
20
|
+
@container.public_extract_selector([:how => "what"]).
|
21
|
+
should == { :how => "what" }
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns an empty hash if given no args" do
|
25
|
+
@container.public_extract_selector([]).should == {}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raises ArgumentError if given 1 arg which is not a Hash" do
|
29
|
+
lambda {
|
30
|
+
@container.public_extract_selector([:how])
|
31
|
+
}.should raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises ArgumentError if given > 2 args" do
|
35
|
+
lambda {
|
36
|
+
@container.public_extract_selector([:how, 'what', 'value'])
|
37
|
+
}.should raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,305 @@
|
|
1
|
+
require File.expand_path("spec_helper", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Watir::ElementLocator do
|
4
|
+
include LocatorSpecHelper
|
5
|
+
|
6
|
+
describe "finds a single element" do
|
7
|
+
describe "by delegating to webdriver" do
|
8
|
+
WEBDRIVER_SELECTORS.each do |loc|
|
9
|
+
it "delegates to webdriver's #{loc} locator" do
|
10
|
+
expect_one(loc, "bar").and_return(element(:tag_name => "div"))
|
11
|
+
locate_one loc => "bar"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "with selectors not supported by webdriver" do
|
17
|
+
it "handles selector with tag name and a single attribute" do
|
18
|
+
expect_one :xpath, ".//div[@class='foo']"
|
19
|
+
|
20
|
+
locate_one :tag_name => "div",
|
21
|
+
:class => "foo"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "handles selector with no tag name and and a single attribute" do
|
25
|
+
expect_one :xpath, ".//*[@title='foo']"
|
26
|
+
locate_one :title => "foo"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "handles selector with tag name and multiple attributes" do
|
30
|
+
expect_one :xpath, %r".//div\[(@class='foo' and @title='bar'|@title='bar' and @class='foo')\]"
|
31
|
+
|
32
|
+
locate_one :tag_name => "div",
|
33
|
+
:class => "foo",
|
34
|
+
:title => 'bar'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "handles selector with no tag name and multiple attributes" do
|
38
|
+
expect_one :xpath, %r".//\*\[(@class='foo' and @title='bar'|@title='bar' and @class='foo')\]"
|
39
|
+
|
40
|
+
locate_one :class => "foo",
|
41
|
+
:title => "bar"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
describe "with special cased selectors" do
|
47
|
+
it "normalizes space for :text" do
|
48
|
+
expect_one :xpath, ".//div[normalize-space()='foo']"
|
49
|
+
locate_one :tag_name => "div",
|
50
|
+
:text => "foo"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "translates :caption to :text" do
|
54
|
+
expect_one :xpath, ".//div[normalize-space()='foo']"
|
55
|
+
|
56
|
+
locate_one :tag_name => "div",
|
57
|
+
:caption => "foo"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "translates :class_name to :class" do
|
61
|
+
expect_one :xpath, ".//div[@class='foo']"
|
62
|
+
|
63
|
+
locate_one :tag_name => "div",
|
64
|
+
:class_name => "foo"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "handles data-* attributes" do
|
68
|
+
expect_one :xpath, ".//div[@data-name='foo']"
|
69
|
+
|
70
|
+
locate_one :tag_name => "div",
|
71
|
+
:data_name => "foo"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "normalizes space for the :href attribute" do
|
75
|
+
expect_one :xpath, ".//a[normalize-space(@href)='foo']"
|
76
|
+
|
77
|
+
selector = {
|
78
|
+
:tag_name => "a",
|
79
|
+
:href => "foo"
|
80
|
+
}
|
81
|
+
|
82
|
+
locate_one selector, Watir::Anchor.attributes
|
83
|
+
end
|
84
|
+
|
85
|
+
it "uses the corresponding <label>'s @for attribute when locating by label" do
|
86
|
+
expect_one :xpath, ".//input[@type='text' and @id=//label[normalize-space()='foo']/@for]"
|
87
|
+
|
88
|
+
selector = {
|
89
|
+
:tag_name => "input",
|
90
|
+
:type => "text",
|
91
|
+
:label => "foo"
|
92
|
+
}
|
93
|
+
|
94
|
+
locate_one selector, Watir::Input.attributes
|
95
|
+
end
|
96
|
+
|
97
|
+
it "does not use the label element for <option> elements" do
|
98
|
+
expect_one :xpath, ".//option[@label='foo']"
|
99
|
+
|
100
|
+
locate_one :tag_name => "option",
|
101
|
+
:label => "foo"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "translates ruby attribute names to content attribute names" do
|
105
|
+
expect_one :xpath, ".//meta[@http-equiv='foo']"
|
106
|
+
|
107
|
+
selector = {
|
108
|
+
:tag_name => "meta",
|
109
|
+
:http_equiv => "foo"
|
110
|
+
}
|
111
|
+
|
112
|
+
locate_one selector, Watir::Meta.attributes
|
113
|
+
|
114
|
+
# TODO: check edge cases
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "with regexp selectors" do
|
119
|
+
it "handles selector with tag name and a single regexp attribute" do
|
120
|
+
elements = [
|
121
|
+
element(:tag_name => "div", :attributes => { :class => "foo" }),
|
122
|
+
element(:tag_name => "div", :attributes => { :class => "foob"})
|
123
|
+
]
|
124
|
+
|
125
|
+
expect_all(:xpath, ".//div").and_return(elements)
|
126
|
+
locate_one(:tag_name => "div", :class => /oob/).should == elements[1]
|
127
|
+
end
|
128
|
+
|
129
|
+
it "handles :tag_name, :index and a single regexp attribute" do
|
130
|
+
elements = [
|
131
|
+
element(:tag_name => "div", :attributes => { :class => "foo" }),
|
132
|
+
element(:tag_name => "div", :attributes => { :class => "foo" })
|
133
|
+
]
|
134
|
+
|
135
|
+
expect_all(:xpath, ".//div").and_return(elements)
|
136
|
+
|
137
|
+
selector = {
|
138
|
+
:tag_name => "div",
|
139
|
+
:class => /foo/,
|
140
|
+
:index => 1
|
141
|
+
}
|
142
|
+
|
143
|
+
locate_one(selector).should == elements[1]
|
144
|
+
end
|
145
|
+
|
146
|
+
it "handles mix of string and regexp attributes" do
|
147
|
+
elements = [
|
148
|
+
element(:tag_name => "div", :attributes => { :class => "foo", :title => "bar" }),
|
149
|
+
element(:tag_name => "div", :attributes => { :class => "foo", :title => "baz" })
|
150
|
+
]
|
151
|
+
|
152
|
+
expect_all(:xpath, ".//div[@class='foo']").and_return(elements)
|
153
|
+
|
154
|
+
selector = {
|
155
|
+
:tag_name => "div",
|
156
|
+
:class => "foo",
|
157
|
+
:title => /baz/
|
158
|
+
}
|
159
|
+
|
160
|
+
locate_one(selector).should == elements[1]
|
161
|
+
end
|
162
|
+
|
163
|
+
it "handles :label => /regexp/ selector" do
|
164
|
+
label_elements = [
|
165
|
+
element(:tag_name => "label", :text => "foo", :attributes => { :for => "bar"}),
|
166
|
+
element(:tag_name => "label", :text => "foob", :attributes => { :for => "baz"})
|
167
|
+
]
|
168
|
+
div_elements = [element(:tag_name => "div")]
|
169
|
+
|
170
|
+
expect_all(:tag_name, "label").ordered.and_return(label_elements)
|
171
|
+
expect_all(:xpath, ".//div[@id='baz']").ordered.and_return(div_elements)
|
172
|
+
|
173
|
+
locate_one(:tag_name => "div", :label => /oob/).should == div_elements.first
|
174
|
+
end
|
175
|
+
|
176
|
+
it "returns nil when no label matching the regexp is found" do
|
177
|
+
expect_all(:tag_name, "label").and_return([])
|
178
|
+
locate_one(:tag_name => "div", :label => /foo/).should be_nil
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
it "finds all if :index is given" do
|
184
|
+
# or could we use XPath indeces reliably instead?
|
185
|
+
elements = [
|
186
|
+
element(:tag_name => "div"),
|
187
|
+
element(:tag_name => "div")
|
188
|
+
]
|
189
|
+
|
190
|
+
expect_all(:xpath, ".//div[@class='foo']").and_return(elements)
|
191
|
+
|
192
|
+
selector = {
|
193
|
+
:tag_name => "div",
|
194
|
+
:class => "foo",
|
195
|
+
:index => 1
|
196
|
+
}
|
197
|
+
|
198
|
+
locate_one(selector).should == elements[1]
|
199
|
+
end
|
200
|
+
|
201
|
+
it "returns nil if found element didn't match the selector tag_name" do
|
202
|
+
expect_one(:xpath, "//div").and_return(element(:tag_name => "div"))
|
203
|
+
|
204
|
+
selector = {
|
205
|
+
:tag_name => "input",
|
206
|
+
:type => "radio",
|
207
|
+
:xpath => "//div"
|
208
|
+
}
|
209
|
+
|
210
|
+
locate_one(selector, Watir::Input.attributes).should be_nil
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "errors" do
|
214
|
+
it "raises a TypeError if :index is not a Fixnum" do
|
215
|
+
lambda {
|
216
|
+
locate_one(:tag_name => "div", :index => "bar")
|
217
|
+
}.should raise_error(TypeError, %[expected Fixnum, got "bar":String])
|
218
|
+
end
|
219
|
+
|
220
|
+
it "raises a TypeError if selector value is not a String or Regexp" do
|
221
|
+
lambda {
|
222
|
+
locate_one(:tag_name => 123)
|
223
|
+
}.should raise_error(TypeError, %[expected one of [String, Regexp], got 123:Fixnum])
|
224
|
+
end
|
225
|
+
|
226
|
+
it "raises a MissingWayOfFindingObjectException if the attribute is not valid" do
|
227
|
+
bad_selector = {:tag_name => "input", :href => "foo"}
|
228
|
+
valid_attributes = Watir::Input.attributes
|
229
|
+
|
230
|
+
lambda {
|
231
|
+
locate_one(bad_selector, valid_attributes)
|
232
|
+
}.should raise_error(MissingWayOfFindingObjectException, "invalid attribute: :href")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe "finds several elements" do
|
238
|
+
describe "by delegating to webdriver" do
|
239
|
+
WEBDRIVER_SELECTORS.each do |loc|
|
240
|
+
it "delegates to webdriver's #{loc} locator" do
|
241
|
+
expect_all(loc, "bar").and_return([element(:tag_name => "div")])
|
242
|
+
locate_all(loc => "bar")
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe "with selectors not supported by webdriver" do
|
248
|
+
it "handles selector with tag name and a single attribute" do
|
249
|
+
expect_all :xpath, ".//div[@class='foo']"
|
250
|
+
|
251
|
+
locate_all :tag_name => "div",
|
252
|
+
:class => "foo"
|
253
|
+
end
|
254
|
+
|
255
|
+
it "handles selector with tag name and multiple attributes" do
|
256
|
+
expect_all :xpath, ".//div[@class='foo' and @title='bar']"
|
257
|
+
|
258
|
+
locate_all :tag_name => "div",
|
259
|
+
:class => "foo",
|
260
|
+
:title => 'bar'
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "with regexp selectors" do
|
265
|
+
it "handles selector with tag name and a single regexp attribute" do
|
266
|
+
elements = [
|
267
|
+
element(:tag_name => "div", :attributes => { :class => "foo" }),
|
268
|
+
element(:tag_name => "div", :attributes => { :class => "foob"}),
|
269
|
+
element(:tag_name => "div", :attributes => { :class => "doob"}),
|
270
|
+
element(:tag_name => "div", :attributes => { :class => "noob"})
|
271
|
+
]
|
272
|
+
|
273
|
+
expect_all(:xpath, ".//div").and_return(elements)
|
274
|
+
locate_all(:tag_name => "div", :class => /oob/).should == elements.last(3)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "handles mix of string and regexp attributes" do
|
278
|
+
elements = [
|
279
|
+
element(:tag_name => "div", :attributes => { :class => "foo", :title => "bar" }),
|
280
|
+
element(:tag_name => "div", :attributes => { :class => "foo", :title => "baz" }),
|
281
|
+
element(:tag_name => "div", :attributes => { :class => "foo", :title => "bazt"})
|
282
|
+
]
|
283
|
+
|
284
|
+
expect_all(:xpath, ".//div[@class='foo']").and_return(elements)
|
285
|
+
|
286
|
+
selector = {
|
287
|
+
:tag_name => "div",
|
288
|
+
:class => "foo",
|
289
|
+
:title => /baz/
|
290
|
+
}
|
291
|
+
|
292
|
+
locate_all(selector).should == elements.last(2)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
describe "errors" do
|
297
|
+
it "raises ArgumentError if :index is given" do
|
298
|
+
lambda {
|
299
|
+
locate_all(:tag_name => "div", :index => 1)
|
300
|
+
}.should raise_error(ArgumentError, "can't locate all elements by :index")
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|