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
data/spec/element_spec.rb
CHANGED
@@ -1,17 +1,46 @@
|
|
1
|
-
require File.expand_path
|
1
|
+
require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
|
4
4
|
describe Watir::Element do
|
5
5
|
|
6
|
-
before :each do
|
7
|
-
browser.goto("file://" + File.expand_path("html/keylogger.html", File.dirname(__FILE__)))
|
8
|
-
end
|
9
|
-
|
10
6
|
describe "#send_keys" do
|
11
7
|
it "sends keystrokes to the element" do
|
8
|
+
browser.goto("file://" + File.expand_path("html/keylogger.html", File.dirname(__FILE__)))
|
12
9
|
browser.div(:id, 'receiver').send_keys("hello world")
|
13
10
|
browser.div(:id, 'output').ps.size.should == 11
|
14
11
|
end
|
15
12
|
end
|
16
13
|
|
14
|
+
describe "#== and #eql?" do
|
15
|
+
before { browser.goto(WatirSpec.files + "/definition_lists.html") }
|
16
|
+
|
17
|
+
it "returns true if the two elements point to the same DOM element" do
|
18
|
+
a = browser.dl(:id => "experience-list")
|
19
|
+
b = browser.dl
|
20
|
+
|
21
|
+
a.should == b
|
22
|
+
a.should eql(b)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns false if the two elements are not the same" do
|
26
|
+
a = browser.dls[0]
|
27
|
+
b = browser.dls[1]
|
28
|
+
|
29
|
+
a.should_not == b
|
30
|
+
a.should_not eql(b)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "data-* attributes" do
|
35
|
+
before { browser.goto("file://" + File.expand_path("html/data_attributes.html", File.dirname(__FILE__))) }
|
36
|
+
|
37
|
+
it "finds elements by a data-* attribute" do
|
38
|
+
browser.p(:data_type => "ruby-library").should exist
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the value of a data-* attribute" do
|
42
|
+
browser.p.data_type.should == "ruby-library"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
17
46
|
end
|
data/spec/html/wait.html
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
<!DOCTYPE HTML>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>wait test</title>
|
5
|
+
<script type="text/javascript" charset="utf-8">
|
6
|
+
function setTimeoutDisplay(id, display, timeout) {
|
7
|
+
setTimeout(function() {
|
8
|
+
document.getElementById(id).style.display = display;
|
9
|
+
}, timeout);
|
10
|
+
}
|
11
|
+
function setTimeoutRemove(id, timeout) {
|
12
|
+
setTimeout(function() {
|
13
|
+
var e = document.getElementById(id);
|
14
|
+
e.parentNode.removeChild(e);
|
15
|
+
}, timeout);
|
16
|
+
}
|
17
|
+
</script>
|
18
|
+
</head>
|
19
|
+
|
20
|
+
<body>
|
21
|
+
<div id="foo" style="display:block;">foo</div>
|
22
|
+
<div id="bar" style="display:none;">bar</div>
|
23
|
+
<a id="show_bar" href="#" onclick="setTimeoutDisplay('bar', 'block', 500);">show bar</a>
|
24
|
+
<a id="hide_foo" href="#" onclick="setTimeoutDisplay('foo', 'none', 500);">hide foo</a>
|
25
|
+
<a id="remove_foo" href="#" onclick="setTimeoutRemove('foo', 500);">remove foo</a>
|
26
|
+
</body>
|
27
|
+
</html>
|
data/spec/input_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path
|
1
|
+
require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe Watir::Input do
|
4
4
|
|
@@ -27,7 +27,7 @@ describe Watir::Input do
|
|
27
27
|
|
28
28
|
it "raises an error if the element is not a radio button" do
|
29
29
|
lambda {
|
30
|
-
browser.input(:xpath => "//input[@type='text']").
|
30
|
+
browser.input(:xpath => "//input[@type='text']").to_radio
|
31
31
|
}.should raise_error(TypeError)
|
32
32
|
end
|
33
33
|
end
|
@@ -62,4 +62,16 @@ describe Watir::Input do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
describe "#to_file_field" do
|
66
|
+
it "returns a TextField instance" do
|
67
|
+
e = browser.input(:xpath => "//input[@type='file']").to_file_field
|
68
|
+
e.should be_kind_of(Watir::FileField)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "raises an error if the element is not a text field" do
|
72
|
+
lambda {
|
73
|
+
browser.input(:xpath => "//input[@type='radio']").to_file_field
|
74
|
+
}.should raise_error(TypeError)
|
75
|
+
end
|
76
|
+
end
|
65
77
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module LocatorSpecHelper
|
2
|
+
def driver
|
3
|
+
@driver ||= mock(Selenium::WebDriver::Driver)
|
4
|
+
end
|
5
|
+
|
6
|
+
def locator(selector, attrs = Watir::HTMLElement.attributes)
|
7
|
+
Watir::ElementLocator.new(driver, selector, attrs)
|
8
|
+
end
|
9
|
+
|
10
|
+
def expect_one(*args)
|
11
|
+
driver.should_receive(:find_element).with(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def expect_all(*args)
|
15
|
+
driver.should_receive(:find_elements).with(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def locate_one(*args)
|
19
|
+
locator(*args).locate
|
20
|
+
end
|
21
|
+
|
22
|
+
def locate_all(*args)
|
23
|
+
locator(*args).locate_all
|
24
|
+
end
|
25
|
+
|
26
|
+
def element(opts = {})
|
27
|
+
attrs = opts.delete(:attributes)
|
28
|
+
el = mock(Watir::Element, opts)
|
29
|
+
|
30
|
+
attrs.each do |key, value|
|
31
|
+
el.stub!(:attribute).with(key).and_return(value)
|
32
|
+
end if attrs
|
33
|
+
|
34
|
+
el
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -4,12 +4,14 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
4
|
|
5
5
|
require 'rubygems'
|
6
6
|
require 'watir-webdriver'
|
7
|
+
require 'locator_spec_helper'
|
7
8
|
require 'spec'
|
8
9
|
require 'spec/autorun'
|
9
10
|
|
10
11
|
include Watir
|
11
12
|
include Watir::Exception
|
12
13
|
|
14
|
+
WEBDRIVER_SELECTORS = [:class, :class_name, :css, :id, :name, :tag_name, :xpath]
|
13
15
|
|
14
16
|
if defined?(WatirSpec)
|
15
17
|
browser = (ENV['WATIR_WEBDRIVER_BROWSER'] || :firefox).to_sym
|
@@ -24,3 +26,4 @@ if defined?(WatirSpec)
|
|
24
26
|
}
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
data/spec/wait_spec.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.expand_path("watirspec/spec_helper", File.dirname(__FILE__))
|
2
|
+
require "watir-webdriver/extensions/wait"
|
3
|
+
|
4
|
+
describe Watir::Wait do
|
5
|
+
describe "#until" do
|
6
|
+
it "waits until the block returns true" do
|
7
|
+
Wait::until(1) { true }.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "times out" do
|
11
|
+
lambda do
|
12
|
+
Wait::until(1) { false }
|
13
|
+
end.should raise_error(Watir::Wait::TimeoutError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#while" do
|
18
|
+
it "waits while the block returns true" do
|
19
|
+
Wait::while(1) { false }.should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "times out" do
|
23
|
+
lambda do
|
24
|
+
Wait::while(1) { true }
|
25
|
+
end.should raise_error(Watir::Wait::TimeoutError)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Watir::Element do
|
31
|
+
|
32
|
+
before do
|
33
|
+
browser.goto("file://" + File.expand_path("html/wait.html", File.dirname(__FILE__)))
|
34
|
+
end
|
35
|
+
|
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
|
+
describe "#when_present" do
|
51
|
+
it "invokes subsequent methods after waiting for the element's presence" do
|
52
|
+
browser.a(:id, 'show_bar').click
|
53
|
+
called = false
|
54
|
+
browser.div(:id, 'bar').when_present(1) do
|
55
|
+
called = true
|
56
|
+
end
|
57
|
+
called.should == true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "times out" do
|
61
|
+
lambda do
|
62
|
+
browser.div(:id, 'bar').when_present(1) {}
|
63
|
+
end.should raise_error(Watir::Wait::TimeoutError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#wait_until_present" do
|
68
|
+
it "invokes subsequent methods after waiting until the element's appereance" do
|
69
|
+
browser.a(:id, 'show_bar').click
|
70
|
+
browser.div(:id, 'bar').wait_until_present(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "times out" do
|
74
|
+
lambda do
|
75
|
+
browser.div(:id, 'bar').wait_until_present(1)
|
76
|
+
end.should raise_error(Watir::Wait::TimeoutError)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#wait_while_present" do
|
81
|
+
it "invokes subsequent methods after waiting until the element's disappearance" do
|
82
|
+
browser.a(:id, 'hide_foo').click
|
83
|
+
browser.div(:id, 'foo').wait_while_present(1)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "invokes subsequent methods after waiting until the element's removal" do
|
87
|
+
browser.a(:id, 'remove_foo').click
|
88
|
+
browser.div(:id, 'foo').wait_while_present(1)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "times out" do
|
92
|
+
lambda do
|
93
|
+
browser.div(:id, 'foo').wait_while_present(1)
|
94
|
+
end.should raise_error(Watir::Wait::TimeoutError)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/spec/watirspec/area_spec.rb
CHANGED
@@ -15,8 +15,6 @@ describe "Area" do
|
|
15
15
|
browser.area(:title, "Tables").should exist
|
16
16
|
browser.area(:title, /Tables/).should exist
|
17
17
|
|
18
|
-
browser.area(:url, "tables.html").should exist
|
19
|
-
browser.area(:url, /tables/).should exist
|
20
18
|
browser.area(:href, "tables.html").should exist
|
21
19
|
browser.area(:href, /tables/).should exist
|
22
20
|
|
@@ -24,14 +22,16 @@ describe "Area" do
|
|
24
22
|
browser.area(:xpath, "//area[@id='NCE']").should exist
|
25
23
|
end
|
26
24
|
|
25
|
+
it "returns the first area if given no args" do
|
26
|
+
browser.area.should exist
|
27
|
+
end
|
28
|
+
|
27
29
|
it "returns false if the area doesn't exist" do
|
28
30
|
browser.area(:id, "no_such_id").should_not exist
|
29
31
|
browser.area(:id, /no_such_id/).should_not exist
|
30
32
|
browser.area(:title, "no_such_title").should_not exist
|
31
33
|
browser.area(:title, /no_such_title/).should_not exist
|
32
34
|
|
33
|
-
browser.area(:url, "no_such_href").should_not exist
|
34
|
-
browser.area(:url, /no_such_href/).should_not exist
|
35
35
|
browser.area(:href, "no-tables.html").should_not exist
|
36
36
|
browser.area(:href, /no-tables/).should_not exist
|
37
37
|
|
@@ -9,10 +9,12 @@ describe "Browser" do
|
|
9
9
|
browser.should exist
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
bug "http://github.com/jarib/watir-webdriver/issues/issue/29", [:webdriver, :ie] do
|
13
|
+
it "returns false after Browser#close" do
|
14
|
+
b = WatirSpec.new_browser
|
15
|
+
b.close
|
16
|
+
b.should_not exist
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -79,7 +81,7 @@ describe "Browser" do
|
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
|
-
|
84
|
+
bug "http://github.com/jarib/watirspec/issues/issue/8" [:webdriver, :ie], [:webdriver, :chrome] do
|
83
85
|
describe ".start" do
|
84
86
|
it "goes to the given URL and return an instance of itself" do
|
85
87
|
browser = WatirSpec.implementation.browser_class.start("#{WatirSpec.files}/non_control_elements.html")
|
@@ -158,9 +160,9 @@ describe "Browser" do
|
|
158
160
|
"#{WatirSpec.host}/forms_with_input_elements.html",
|
159
161
|
"#{WatirSpec.host}/definition_lists.html"
|
160
162
|
].map do |page|
|
161
|
-
|
162
|
-
|
163
|
-
|
163
|
+
browser.goto page
|
164
|
+
browser.url
|
165
|
+
end
|
164
166
|
|
165
167
|
3.times { browser.back }
|
166
168
|
browser.url.should == urls.first
|
@@ -170,33 +172,33 @@ describe "Browser" do
|
|
170
172
|
end
|
171
173
|
|
172
174
|
describe "#element_by_xpath" do
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
175
|
+
before :each do
|
176
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
177
|
+
end
|
178
|
+
|
179
|
+
it "finds submit buttons matching the given xpath" do
|
180
|
+
browser.element_by_xpath("//input[@type='submit']").should exist
|
181
|
+
end
|
182
|
+
|
183
|
+
it "finds reset buttons matching the given xpath" do
|
184
|
+
browser.element_by_xpath("//input[@type='reset']").should exist
|
185
|
+
end
|
186
|
+
|
187
|
+
it "finds image buttons matching the given xpath" do
|
188
|
+
browser.element_by_xpath("//input[@type='image']").should exist
|
189
|
+
end
|
190
|
+
|
191
|
+
it "finds the element matching the given xpath" do
|
192
|
+
browser.element_by_xpath("//input[@type='password']").should exist
|
193
|
+
end
|
194
|
+
|
195
|
+
it "will not find elements that doesn't exist" do
|
196
|
+
e = browser.element_by_xpath("//input[@type='foobar']")
|
197
|
+
e.should_not exist
|
198
|
+
lambda { e.text }.should raise_error(UnknownObjectException)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
200
202
|
describe "#elements_by_xpath" do
|
201
203
|
before :each do
|
202
204
|
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
@@ -33,6 +33,11 @@ describe "Button" do
|
|
33
33
|
browser.button(:caption, /Button 2/).should exist
|
34
34
|
end
|
35
35
|
|
36
|
+
|
37
|
+
it "returns the first button if given no args" do
|
38
|
+
browser.button.should exist
|
39
|
+
end
|
40
|
+
|
36
41
|
it "returns false if the button doesn't exist" do
|
37
42
|
browser.button(:id, "no_such_id").should_not exist
|
38
43
|
browser.button(:id, /no_such_id/).should_not exist
|
@@ -50,11 +55,9 @@ describe "Button" do
|
|
50
55
|
browser.button(:xpath, "//input[@id='no_such_id']").should_not exist
|
51
56
|
end
|
52
57
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
browser.button(:xpath, "//input[@type='button']").should exist
|
57
|
-
end
|
58
|
+
it "checks the tag name and type attribute when locating by xpath" do
|
59
|
+
browser.button(:xpath, "//input[@type='text']").should_not exist
|
60
|
+
browser.button(:xpath, "//input[@type='button']").should exist
|
58
61
|
end
|
59
62
|
|
60
63
|
it "raises TypeError when 'what' argument is invalid" do
|
@@ -64,11 +67,6 @@ describe "Button" do
|
|
64
67
|
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
65
68
|
lambda { browser.button(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
66
69
|
end
|
67
|
-
|
68
|
-
# it "locates the correct button when there are duplicate ids and user disambiguates by parent" do
|
69
|
-
# browser.goto(WatirSpec.files + "/buttons_with_duplicate_ids.html")
|
70
|
-
# browser.form(:name, "bar-form").button(:id, 'next').parent.name.should == "bar-form"
|
71
|
-
# end
|
72
70
|
end
|
73
71
|
|
74
72
|
# Attribute methods
|
@@ -107,18 +105,12 @@ describe "Button" do
|
|
107
105
|
end
|
108
106
|
|
109
107
|
describe "#src" do
|
110
|
-
|
108
|
+
bug "http://github.com/jarib/watir-webdriver/issues/issue/27", [:webdriver, :ie], [:webdriver, :firefox] do
|
111
109
|
it "returns the src attribute for the button image" do
|
112
110
|
browser.button(:name, "new_user_image").src.should == "images/button.jpg"
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
116
|
-
deviates_on [:webdriver, :ie], [:webdriver, :firefox] do
|
117
|
-
it "returns the src attribute for the button image" do
|
118
|
-
browser.button(:name, "new_user_image").src.should == "file:///#{File.expand_path(File.dirname(__FILE__))}/html/images/button.jpg"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
114
|
it "raises UnknownObjectException if the button does not exist" do
|
123
115
|
lambda { browser.button(:name, "no_such_name").src }.should raise_error(UnknownObjectException)
|
124
116
|
end
|
@@ -180,6 +172,19 @@ describe "Button" do
|
|
180
172
|
end
|
181
173
|
end
|
182
174
|
|
175
|
+
describe "#text" do
|
176
|
+
it "returns the text of the button" do
|
177
|
+
browser.button(:index, 0).text.should == 'Submit'
|
178
|
+
browser.button(:index, 1).text.should == 'Reset'
|
179
|
+
browser.button(:index, 2).text.should == 'Button'
|
180
|
+
browser.button(:index, 3).text.should == "Button 2"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "raises UnknownObjectException if the element does not exist" do
|
184
|
+
lambda { browser.button(:id, "no_such_id").text }.should raise_error(UnknownObjectException)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
183
188
|
describe "#respond_to?" do
|
184
189
|
it "returns true for all attribute methods" do
|
185
190
|
browser.button(:index, 0).should respond_to(:class_name)
|