watir-webdriver 0.0.1.dev
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/.document +5 -0
- data/.gitignore +5 -0
- data/.gitmodules +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +32 -0
- data/Rakefile +107 -0
- data/TODO +15 -0
- data/VERSION +1 -0
- data/lib/watir-webdriver.rb +74 -0
- data/lib/watir-webdriver/base_element.rb +347 -0
- data/lib/watir-webdriver/browser.rb +130 -0
- data/lib/watir-webdriver/browserbot.js +34 -0
- data/lib/watir-webdriver/collections/buttons_collection.rb +13 -0
- data/lib/watir-webdriver/collections/element_collection.rb +45 -0
- data/lib/watir-webdriver/collections/table_rows_collection.rb +14 -0
- data/lib/watir-webdriver/collections/text_fields_collection.rb +13 -0
- data/lib/watir-webdriver/container.rb +24 -0
- data/lib/watir-webdriver/core_ext/string.rb +22 -0
- data/lib/watir-webdriver/elements/button.rb +27 -0
- data/lib/watir-webdriver/elements/checkbox.rb +23 -0
- data/lib/watir-webdriver/elements/file_field.rb +20 -0
- data/lib/watir-webdriver/elements/form.rb +11 -0
- data/lib/watir-webdriver/elements/generated.rb +941 -0
- data/lib/watir-webdriver/elements/headings.rb +48 -0
- data/lib/watir-webdriver/elements/hidden.rb +18 -0
- data/lib/watir-webdriver/elements/image.rb +33 -0
- data/lib/watir-webdriver/elements/input.rb +39 -0
- data/lib/watir-webdriver/elements/link.rb +13 -0
- data/lib/watir-webdriver/elements/option.rb +36 -0
- data/lib/watir-webdriver/elements/radio.rb +23 -0
- data/lib/watir-webdriver/elements/select_list.rb +73 -0
- data/lib/watir-webdriver/elements/shared_radio_checkbox.rb +13 -0
- data/lib/watir-webdriver/elements/table.rb +18 -0
- data/lib/watir-webdriver/elements/table_row.rb +17 -0
- data/lib/watir-webdriver/elements/text_field.rb +60 -0
- data/lib/watir-webdriver/exception.rb +20 -0
- data/lib/watir-webdriver/locators/button_locator.rb +57 -0
- data/lib/watir-webdriver/locators/element_locator.rb +269 -0
- data/lib/watir-webdriver/locators/table_row_locator.rb +25 -0
- data/lib/watir-webdriver/locators/text_field_locator.rb +61 -0
- data/lib/watir-webdriver/xpath_support.rb +23 -0
- data/spec/element_locator_spec.rb +11 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/watirspec/area_spec.rb +78 -0
- data/spec/watirspec/areas_spec.rb +31 -0
- data/spec/watirspec/browser_spec.rb +262 -0
- data/spec/watirspec/button_spec.rb +242 -0
- data/spec/watirspec/buttons_spec.rb +48 -0
- data/spec/watirspec/checkbox_spec.rb +272 -0
- data/spec/watirspec/checkboxes_spec.rb +32 -0
- data/spec/watirspec/dd_spec.rb +136 -0
- data/spec/watirspec/dds_spec.rb +31 -0
- data/spec/watirspec/div_spec.rb +222 -0
- data/spec/watirspec/divs_spec.rb +31 -0
- data/spec/watirspec/dl_spec.rb +136 -0
- data/spec/watirspec/dls_spec.rb +32 -0
- data/spec/watirspec/dt_spec.rb +136 -0
- data/spec/watirspec/dts_spec.rb +31 -0
- data/spec/watirspec/element_spec.rb +87 -0
- data/spec/watirspec/em_spec.rb +110 -0
- data/spec/watirspec/ems_spec.rb +32 -0
- data/spec/watirspec/filefield_spec.rb +119 -0
- data/spec/watirspec/filefields_spec.rb +32 -0
- data/spec/watirspec/form_spec.rb +63 -0
- data/spec/watirspec/forms_spec.rb +33 -0
- data/spec/watirspec/frame_spec.rb +140 -0
- data/spec/watirspec/frames_spec.rb +62 -0
- data/spec/watirspec/hidden_spec.rb +102 -0
- data/spec/watirspec/hiddens_spec.rb +32 -0
- data/spec/watirspec/hn_spec.rb +93 -0
- data/spec/watirspec/hns_spec.rb +38 -0
- data/spec/watirspec/image_spec.rb +207 -0
- data/spec/watirspec/images_spec.rb +31 -0
- data/spec/watirspec/label_spec.rb +75 -0
- data/spec/watirspec/labels_spec.rb +31 -0
- data/spec/watirspec/li_spec.rb +127 -0
- data/spec/watirspec/lib/guards.rb +59 -0
- data/spec/watirspec/lib/server.rb +127 -0
- data/spec/watirspec/lib/spec_helper.rb +79 -0
- data/spec/watirspec/lib/watirspec.rb +72 -0
- data/spec/watirspec/link_spec.rb +165 -0
- data/spec/watirspec/links_spec.rb +35 -0
- data/spec/watirspec/lis_spec.rb +31 -0
- data/spec/watirspec/map_spec.rb +92 -0
- data/spec/watirspec/maps_spec.rb +32 -0
- data/spec/watirspec/meta_spec.rb +22 -0
- data/spec/watirspec/metas_spec.rb +30 -0
- data/spec/watirspec/ol_spec.rb +78 -0
- data/spec/watirspec/ols_spec.rb +31 -0
- data/spec/watirspec/option_spec.rb +173 -0
- data/spec/watirspec/p_spec.rb +143 -0
- data/spec/watirspec/pre_spec.rb +125 -0
- data/spec/watirspec/pres_spec.rb +31 -0
- data/spec/watirspec/ps_spec.rb +31 -0
- data/spec/watirspec/radio_spec.rb +278 -0
- data/spec/watirspec/radios_spec.rb +32 -0
- data/spec/watirspec/select_list_spec.rb +318 -0
- data/spec/watirspec/select_lists_spec.rb +35 -0
- data/spec/watirspec/span_spec.rb +157 -0
- data/spec/watirspec/spans_spec.rb +57 -0
- data/spec/watirspec/spec_helper.rb +17 -0
- data/spec/watirspec/strong_spec.rb +89 -0
- data/spec/watirspec/strongs_spec.rb +32 -0
- data/spec/watirspec/table_bodies_spec.rb +45 -0
- data/spec/watirspec/table_body_spec.rb +98 -0
- data/spec/watirspec/table_cell_spec.rb +68 -0
- data/spec/watirspec/table_cells_spec.rb +47 -0
- data/spec/watirspec/table_footer_spec.rb +85 -0
- data/spec/watirspec/table_footers_spec.rb +47 -0
- data/spec/watirspec/table_header_spec.rb +85 -0
- data/spec/watirspec/table_headers_spec.rb +45 -0
- data/spec/watirspec/table_row_spec.rb +87 -0
- data/spec/watirspec/table_rows_spec.rb +50 -0
- data/spec/watirspec/table_spec.rb +166 -0
- data/spec/watirspec/tables_spec.rb +33 -0
- data/spec/watirspec/text_field_spec.rb +276 -0
- data/spec/watirspec/text_fields_spec.rb +35 -0
- data/spec/watirspec/ul_spec.rb +76 -0
- data/spec/watirspec/uls_spec.rb +33 -0
- data/spec/xpath_builder_spec.rb +49 -0
- data/support/html5/html5.idl +815 -0
- data/support/html5/html5_extras.idl +147 -0
- data/support/html5/idl_extractor.rb +73 -0
- data/support/html5/watir_visitor.rb +169 -0
- metadata +220 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
|
4
|
+
describe "Ols" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#length" do
|
11
|
+
it "returns the number of ols" do
|
12
|
+
browser.ols.length.should == 2
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#[]" do
|
17
|
+
it "returns the ol at the given index" do
|
18
|
+
browser.ols[0].id.should == "favorite_compounds"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#each" do
|
23
|
+
it "iterates through ols correctly" do
|
24
|
+
browser.ols.each_with_index do |ol, index|
|
25
|
+
ol.id.should == browser.ol(:index, index).id
|
26
|
+
ol.value.should == browser.ol(:index, index).value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
|
4
|
+
describe "Option" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#exists?" do
|
11
|
+
bug "WTR-367", :watir do
|
12
|
+
it "returns true if the element exists (page context)" do
|
13
|
+
bug "WTR-330", :watir do
|
14
|
+
browser.option(:id, "nor").should exist
|
15
|
+
browser.option(:id, /nor/).should exist
|
16
|
+
end
|
17
|
+
browser.option(:value, "2").should exist
|
18
|
+
browser.option(:value, /2/).should exist
|
19
|
+
browser.option(:text, "Norway").should exist
|
20
|
+
browser.option(:text, /Norway/).should exist
|
21
|
+
browser.option(:class, "scandinavia").should exist
|
22
|
+
browser.option(:index, 1).should exist
|
23
|
+
browser.option(:xpath, "//option[@id='nor']").should exist
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns true if the element exists (select_list context)" do
|
28
|
+
bug "WTR-330", :watir do
|
29
|
+
browser.select_list(:name, "new_user_country").option(:id, "nor").should exist
|
30
|
+
browser.select_list(:name, "new_user_country").option(:id, /nor/).should exist
|
31
|
+
end
|
32
|
+
|
33
|
+
browser.select_list(:name, "new_user_country").option(:value, "2").should exist
|
34
|
+
browser.select_list(:name, "new_user_country").option(:value, /2/).should exist
|
35
|
+
browser.select_list(:name, "new_user_country").option(:text, "Norway").should exist
|
36
|
+
browser.select_list(:name, "new_user_country").option(:text, /Norway/).should exist
|
37
|
+
browser.select_list(:name, "new_user_country").option(:class, "scandinavia").should exist
|
38
|
+
browser.select_list(:name, "new_user_country").option(:index, 1).should exist
|
39
|
+
browser.select_list(:name, "new_user_country").option(:xpath, "//option[@id='nor']").should exist
|
40
|
+
browser.select_list(:name, "new_user_country").option(:xpath, "//option[@id='nor']").should exist
|
41
|
+
browser.select_list(:name, "new_user_country").option(:label, "Germany").should exist
|
42
|
+
end
|
43
|
+
|
44
|
+
bug "WTR-367", :watir do
|
45
|
+
it "returns false if the element does not exist (page context)" do
|
46
|
+
bug "WTR-330", :watir do
|
47
|
+
browser.option(:id, "no_such_id").should_not exist
|
48
|
+
browser.option(:id, /no_such_id/).should_not exist
|
49
|
+
end
|
50
|
+
browser.option(:value, "no_such_value").should_not exist
|
51
|
+
browser.option(:value, /no_such_value/).should_not exist
|
52
|
+
browser.option(:text, "no_such_text").should_not exist
|
53
|
+
browser.option(:text, /no_such_text/).should_not exist
|
54
|
+
browser.option(:class, "no_such_class").should_not exist
|
55
|
+
browser.option(:index, 1337).should_not exist
|
56
|
+
browser.option(:xpath, "//option[@id='no_such_id']").should_not exist
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns false if the element does not exist (select_list context)" do
|
61
|
+
bug "WTR-330", :watir do
|
62
|
+
browser.select_list(:name, "new_user_country").option(:id, "no_such_id").should_not exist
|
63
|
+
browser.select_list(:name, "new_user_country").option(:id, /no_such_id/).should_not exist
|
64
|
+
end
|
65
|
+
|
66
|
+
browser.select_list(:name, "new_user_country").option(:value, "no_such_value").should_not exist
|
67
|
+
browser.select_list(:name, "new_user_country").option(:value, /no_such_value/).should_not exist
|
68
|
+
browser.select_list(:name, "new_user_country").option(:text, "no_such_text").should_not exist
|
69
|
+
browser.select_list(:name, "new_user_country").option(:text, /no_such_text/).should_not exist
|
70
|
+
browser.select_list(:name, "new_user_country").option(:class, "no_such_class").should_not exist
|
71
|
+
browser.select_list(:name, "new_user_country").option(:index, 1337).should_not exist
|
72
|
+
browser.select_list(:name, "new_user_country").option(:xpath, "//option[@id='no_such_id']").should_not exist
|
73
|
+
end
|
74
|
+
|
75
|
+
it "raises TypeError when 'what' argument is invalid" do
|
76
|
+
bug "WTR-367", :watir do
|
77
|
+
lambda { browser.option(:id, 3.14).exists? }.should raise_error(TypeError)
|
78
|
+
end
|
79
|
+
|
80
|
+
lambda { browser.select_list(:name, "new_user_country").option(:id, 3.14).exists? }.should raise_error(TypeError)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
84
|
+
bug "WTR-367", :watir do
|
85
|
+
lambda { browser.option(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
86
|
+
end
|
87
|
+
lambda { browser.select_list(:name, "new_user_country").option(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#select" do
|
92
|
+
bug "WTR-367", :watir do
|
93
|
+
it "selects the chosen option (page context)" do
|
94
|
+
browser.option(:text, "Denmark").select
|
95
|
+
browser.select_list(:name, "new_user_country").selected_options.should == ["Denmark"]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "selects the chosen option (select_list context)" do
|
100
|
+
browser.select_list(:name, "new_user_country").option(:text, "Denmark").select
|
101
|
+
browser.select_list(:name, "new_user_country").selected_options.should == ["Denmark"]
|
102
|
+
end
|
103
|
+
|
104
|
+
bug "WTR-367, WTR-329", :watir do
|
105
|
+
it "selects the option when found by text (page context)" do
|
106
|
+
browser.option(:text, 'Sweden').select
|
107
|
+
browser.option(:text, 'Sweden').should be_selected
|
108
|
+
end
|
109
|
+
|
110
|
+
it "selects the option when found by text (select_list context)" do
|
111
|
+
browser.select_list(:name, 'new_user_country').option(:text, 'Sweden').select
|
112
|
+
browser.select_list(:name, 'new_user_country').option(:text, 'Sweden').should be_selected
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it "fires the onclick event (page context)" do
|
117
|
+
bug "WTR-367, WTR-335", :watir do
|
118
|
+
browser.option(:text, "Username 3").select
|
119
|
+
end
|
120
|
+
browser.text_field(:id, 'delete_user_comment').value.should == 'Don\'t do it!'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "fires onclick event (select_list context)" do
|
124
|
+
browser.select_list(:id, 'delete_user_username').option(:text, "Username 3").select
|
125
|
+
browser.text_field(:id, 'delete_user_comment').value.should == 'Don\'t do it!'
|
126
|
+
end
|
127
|
+
|
128
|
+
bug "WTR-367", :watir do
|
129
|
+
it "raises UnknownObjectException if the option does not exist (page context)" do
|
130
|
+
lambda { browser.option(:text, "no_such_text").select }.should raise_error(UnknownObjectException)
|
131
|
+
lambda { browser.option(:text, /missing/).select }.should raise_error(UnknownObjectException)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "raises UnknownObjectException if the option does not exist (select_list context)" do
|
136
|
+
lambda { browser.select_list(:name, "new_user_country").option(:text, "no_such_text").select }.should raise_error(UnknownObjectException)
|
137
|
+
lambda { browser.select_list(:name, "new_user_country").option(:text, /missing/).select }.should raise_error(UnknownObjectException)
|
138
|
+
end
|
139
|
+
|
140
|
+
bug "WTR-367", :watir do
|
141
|
+
it "raises MissingWayOfFindingObjectException when given a bad 'how' (page context)" do
|
142
|
+
lambda { browser.option(:missing, "Denmark").select }.should raise_error(MissingWayOfFindingObjectException)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "raises MissingWayOfFindingObjectException when given a bad 'how' (select_list context)" do
|
147
|
+
lambda { browser.select_list(:name, "new_user_country").option(:missing, "Denmark").select }.should raise_error(MissingWayOfFindingObjectException)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
bug "WTR-331", :watir do
|
152
|
+
describe "#class_name" do
|
153
|
+
bug "WTR-367", :watir do
|
154
|
+
it "is able to get attributes (page context)" do
|
155
|
+
browser.option(:text, 'Sweden').class_name.should == "scandinavia"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
it "is able to get attributes (select_list context)" do
|
160
|
+
browser.select_list(:name, "new_user_country").option(:text , 'Sweden').class_name.should == "scandinavia"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "#respond_to?" do
|
166
|
+
it "returns true for all attribute methods" do
|
167
|
+
browser.select_list(:name, "new_user_country").option(:text, 'Sweden').should respond_to(:class_name)
|
168
|
+
browser.select_list(:name, "new_user_country").option(:text, 'Sweden').should respond_to(:id)
|
169
|
+
browser.select_list(:name, "new_user_country").option(:text, 'Sweden').should respond_to(:text)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
|
4
|
+
describe "P" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
# Exists method
|
11
|
+
describe "#exist?" do
|
12
|
+
it "returns true if the 'p' exists" do
|
13
|
+
browser.p(:id, "lead").should exist
|
14
|
+
browser.p(:id, /lead/).should exist
|
15
|
+
browser.p(:text, "Dubito, ergo cogito, ergo sum.").should exist
|
16
|
+
browser.p(:text, /Dubito, ergo cogito, ergo sum/).should exist
|
17
|
+
browser.p(:class, "lead").should exist
|
18
|
+
browser.p(:class, /lead/).should exist
|
19
|
+
browser.p(:index, 0).should exist
|
20
|
+
browser.p(:xpath, "//p[@id='lead']").should exist
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns false if the 'p' doesn't exist" do
|
24
|
+
browser.p(:id, "no_such_id").should_not exist
|
25
|
+
browser.p(:id, /no_such_id/).should_not exist
|
26
|
+
browser.p(:text, "no_such_text").should_not exist
|
27
|
+
browser.p(:text, /no_such_text/).should_not exist
|
28
|
+
browser.p(:class, "no_such_class").should_not exist
|
29
|
+
browser.p(:class, /no_such_class/).should_not exist
|
30
|
+
browser.p(:index, 1337).should_not exist
|
31
|
+
browser.p(:xpath, "//p[@id='no_such_id']").should_not exist
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises TypeError when 'what' argument is invalid" do
|
35
|
+
lambda { browser.p(:id, 3.14).exists? }.should raise_error(TypeError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
39
|
+
lambda { browser.p(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Attribute methods
|
44
|
+
describe "#class_name" do
|
45
|
+
it "returns the class attribute" do
|
46
|
+
browser.p(:index, 0).class_name.should == 'lead'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
50
|
+
browser.p(:index, 2).class_name.should == ''
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
54
|
+
lambda { browser.p(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#id" do
|
59
|
+
it "returns the id attribute" do
|
60
|
+
browser.p(:index, 0).id.should == "lead"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
64
|
+
browser.p(:index, 2).id.should == ''
|
65
|
+
end
|
66
|
+
|
67
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
68
|
+
lambda { browser.p(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
|
69
|
+
lambda { browser.p(:index, 1337).id }.should raise_error(UnknownObjectException)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#title" do
|
74
|
+
it "returns the title attribute" do
|
75
|
+
browser.p(:index, 0).title.should == 'Lorem ipsum'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
79
|
+
browser.p(:index, 2).title.should == ''
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
83
|
+
lambda { browser.p(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
|
84
|
+
lambda { browser.p(:xpath, "//p[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#text" do
|
89
|
+
it "returns the text of the p" do
|
90
|
+
browser.p(:index, 1).text.should == 'Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns an empty string if the element doesn't contain any text" do
|
94
|
+
browser.p(:index, 4).text.should == ''
|
95
|
+
end
|
96
|
+
|
97
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
98
|
+
lambda { browser.p(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
|
99
|
+
lambda { browser.p(:xpath , "//p[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#value" do
|
104
|
+
it "returns the value attribute" do
|
105
|
+
browser.p(:index, 1).value.should == "invalid_attribute"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
109
|
+
browser.p(:index, 2).value.should == ''
|
110
|
+
end
|
111
|
+
|
112
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
113
|
+
lambda { browser.p(:id , "no_such_id").value }.should raise_error(UnknownObjectException)
|
114
|
+
lambda { browser.p(:index , 1337).value }.should raise_error(UnknownObjectException)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#respond_to?" do
|
119
|
+
it "returns true for all attribute methods" do
|
120
|
+
browser.p(:index, 0).should respond_to(:class_name)
|
121
|
+
browser.p(:index, 0).should respond_to(:id)
|
122
|
+
browser.p(:index, 0).should respond_to(:title)
|
123
|
+
browser.p(:index, 0).should respond_to(:text)
|
124
|
+
browser.p(:index, 0).should respond_to(:value)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Other
|
129
|
+
describe "#to_s" do
|
130
|
+
it "returns a human readable representation of the element" do
|
131
|
+
browser.p(:index, 0).to_s.should == "tag: p\n" +
|
132
|
+
" id: lead\n" +
|
133
|
+
" class: lead\n" +
|
134
|
+
" title: Lorem ipsum\n" +
|
135
|
+
" text: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur eu pede. Ut justo. Praesent feugiat, elit in feugiat iaculis, sem risus rutrum justo, eget fermentum dolor arcu non nunc."
|
136
|
+
end
|
137
|
+
|
138
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
139
|
+
lambda { browser.p(:xpath, "//p[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
|
4
|
+
describe "Pre" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
8
|
+
end
|
9
|
+
|
10
|
+
# Exists method
|
11
|
+
describe "#exist?" do
|
12
|
+
it "returns true if the 'p' exists" do
|
13
|
+
browser.pre(:id, "rspec").should exist
|
14
|
+
browser.pre(:id, /rspec/).should exist
|
15
|
+
browser.pre(:text, 'browser.pre(:id, "rspec").should exist').should exist
|
16
|
+
browser.pre(:text, /browser\.pre/).should exist
|
17
|
+
browser.pre(:class, "ruby").should exist
|
18
|
+
browser.pre(:class, /ruby/).should exist
|
19
|
+
browser.pre(:index, 0).should exist
|
20
|
+
browser.pre(:xpath, "//pre[@id='rspec']").should exist
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns false if the 'p' doesn't exist" do
|
24
|
+
browser.pre(:id, "no_such_id").should_not exist
|
25
|
+
browser.pre(:id, /no_such_id/).should_not exist
|
26
|
+
browser.pre(:text, "no_such_text").should_not exist
|
27
|
+
browser.pre(:text, /no_such_text/).should_not exist
|
28
|
+
browser.pre(:class, "no_such_class").should_not exist
|
29
|
+
browser.pre(:class, /no_such_class/).should_not exist
|
30
|
+
browser.pre(:index, 1337).should_not exist
|
31
|
+
browser.pre(:xpath, "//pre[@id='no_such_id']").should_not exist
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises TypeError when 'what' argument is invalid" do
|
35
|
+
lambda { browser.pre(:id, 3.14).exists? }.should raise_error(TypeError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
39
|
+
lambda { browser.pre(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Attribute methods
|
44
|
+
describe "#class_name" do
|
45
|
+
it "returns the class attribute" do
|
46
|
+
browser.pre(:id, 'rspec').class_name.should == 'ruby'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
50
|
+
browser.pre(:index, 0).class_name.should == ''
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
54
|
+
lambda { browser.pre(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#id" do
|
59
|
+
it "returns the id attribute" do
|
60
|
+
browser.pre(:class, 'ruby').id.should == "rspec"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
64
|
+
browser.pre(:index, 0).id.should == ''
|
65
|
+
end
|
66
|
+
|
67
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
68
|
+
lambda { browser.pre(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
|
69
|
+
lambda { browser.pre(:index, 1337).id }.should raise_error(UnknownObjectException)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#title" do
|
74
|
+
it "returns the title attribute" do
|
75
|
+
browser.pre(:class, 'brainfuck').title.should == 'The brainfuck language is an esoteric programming language noted for its extreme minimalism'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
79
|
+
browser.pre(:index, 0).title.should == ''
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
83
|
+
lambda { browser.pre(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
|
84
|
+
lambda { browser.pre(:xpath, "//pre[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#text" do
|
89
|
+
it "returns the text of the p" do
|
90
|
+
browser.pre(:class, 'haskell').text.should == 'main = putStrLn "Hello World"'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns an empty string if the element doesn't contain any text" do
|
94
|
+
browser.pre(:index, 0).text.should == ''
|
95
|
+
end
|
96
|
+
|
97
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
98
|
+
lambda { browser.pre(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
|
99
|
+
lambda { browser.pre(:xpath , "//pre[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#respond_to?" do
|
104
|
+
it "returns true for all attribute methods" do
|
105
|
+
browser.image(:index, 0).should respond_to(:class_name)
|
106
|
+
browser.image(:index, 0).should respond_to(:id)
|
107
|
+
browser.image(:index, 0).should respond_to(:title)
|
108
|
+
browser.image(:index, 0).should respond_to(:text)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Other
|
113
|
+
describe "#to_s" do
|
114
|
+
bug "WTR-350", :watir do
|
115
|
+
it "returns a human readable representation of the element" do
|
116
|
+
browser.pre(:index, 0).to_s.should == "tag: pre"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it "raises UnknownObjectException if the p doesn't exist" do
|
121
|
+
lambda { browser.pre(:xpath, "//pre[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|