watir 6.0.0.beta5 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/CHANGES.md +10 -1
- data/Gemfile +4 -0
- data/README.md +37 -23
- data/Rakefile +6 -10
- data/appveyor.yml +13 -0
- data/lib/watir.rb +20 -21
- data/lib/watir/alert.rb +21 -5
- data/lib/watir/browser.rb +9 -3
- data/lib/watir/elements/checkbox.rb +0 -1
- data/lib/watir/elements/element.rb +92 -50
- data/lib/watir/elements/form.rb +1 -2
- data/lib/watir/elements/iframe.rb +6 -2
- data/lib/watir/elements/image.rb +1 -1
- data/lib/watir/elements/option.rb +0 -1
- data/lib/watir/elements/radio.rb +0 -1
- data/lib/watir/elements/select.rb +1 -10
- data/lib/watir/extensions/select_text.rb +1 -1
- data/lib/watir/legacy_wait.rb +126 -0
- data/lib/watir/locators/text_field/locator.rb +0 -3
- data/lib/watir/locators/text_field/selector_builder.rb +1 -4
- data/lib/watir/locators/text_field/selector_builder/xpath.rb +0 -2
- data/lib/watir/locators/text_field/validator.rb +1 -9
- data/lib/watir/row_container.rb +1 -1
- data/lib/watir/user_editable.rb +7 -5
- data/lib/watir/wait.rb +56 -135
- data/lib/watir/wait/timer.rb +29 -2
- data/lib/watir/window.rb +11 -1
- data/lib/watirspec.rb +81 -0
- data/lib/watirspec/guards.rb +58 -0
- data/lib/watirspec/implementation.rb +33 -0
- data/lib/watirspec/rake_tasks.rb +115 -0
- data/lib/watirspec/runner.rb +53 -0
- data/lib/watirspec/server.rb +99 -0
- data/lib/watirspec/server/app.rb +62 -0
- data/spec/browser_spec.rb +5 -5
- data/spec/click_spec.rb +1 -1
- data/spec/container_spec.rb +1 -1
- data/spec/element_locator_spec.rb +1 -1
- data/spec/element_spec.rb +20 -34
- data/spec/implementation_spec.rb +24 -0
- data/spec/input_spec.rb +1 -1
- data/spec/spec_helper.rb +35 -3
- data/spec/special_chars_spec.rb +1 -1
- data/spec/watirspec/.gitignore +2 -0
- data/spec/watirspec/after_hooks_spec.rb +179 -0
- data/spec/watirspec/alert_spec.rb +101 -0
- data/spec/watirspec/browser_spec.rb +291 -0
- data/spec/watirspec/cookies_spec.rb +147 -0
- data/spec/watirspec/drag_and_drop_spec.rb +49 -0
- data/spec/watirspec/element_hidden_spec.rb +65 -0
- data/spec/watirspec/elements/area_spec.rb +76 -0
- data/spec/watirspec/elements/areas_spec.rb +42 -0
- data/spec/watirspec/elements/button_spec.rb +270 -0
- data/spec/watirspec/elements/buttons_spec.rb +55 -0
- data/spec/watirspec/elements/checkbox_spec.rb +279 -0
- data/spec/watirspec/elements/checkboxes_spec.rb +44 -0
- data/spec/watirspec/elements/collections_spec.rb +16 -0
- data/spec/watirspec/elements/dd_spec.rb +126 -0
- data/spec/watirspec/elements/dds_spec.rb +42 -0
- data/spec/watirspec/elements/del_spec.rb +128 -0
- data/spec/watirspec/elements/dels_spec.rb +40 -0
- data/spec/watirspec/elements/div_spec.rb +199 -0
- data/spec/watirspec/elements/divs_spec.rb +42 -0
- data/spec/watirspec/elements/dl_spec.rb +144 -0
- data/spec/watirspec/elements/dls_spec.rb +43 -0
- data/spec/watirspec/elements/dt_spec.rb +126 -0
- data/spec/watirspec/elements/dts_spec.rb +42 -0
- data/spec/watirspec/elements/element_spec.rb +361 -0
- data/spec/watirspec/elements/elements_spec.rb +15 -0
- data/spec/watirspec/elements/em_spec.rb +100 -0
- data/spec/watirspec/elements/ems_spec.rb +43 -0
- data/spec/watirspec/elements/filefield_spec.rb +181 -0
- data/spec/watirspec/elements/filefields_spec.rb +43 -0
- data/spec/watirspec/elements/font_spec.rb +29 -0
- data/spec/watirspec/elements/form_spec.rb +70 -0
- data/spec/watirspec/elements/forms_spec.rb +44 -0
- data/spec/watirspec/elements/frame_spec.rb +121 -0
- data/spec/watirspec/elements/frames_spec.rb +41 -0
- data/spec/watirspec/elements/hidden_spec.rb +102 -0
- data/spec/watirspec/elements/hiddens_spec.rb +43 -0
- data/spec/watirspec/elements/hn_spec.rb +96 -0
- data/spec/watirspec/elements/hns_spec.rb +38 -0
- data/spec/watirspec/elements/iframe_spec.rb +174 -0
- data/spec/watirspec/elements/iframes_spec.rb +47 -0
- data/spec/watirspec/elements/image_spec.rb +164 -0
- data/spec/watirspec/elements/images_spec.rb +40 -0
- data/spec/watirspec/elements/ins_spec.rb +129 -0
- data/spec/watirspec/elements/inses_spec.rb +40 -0
- data/spec/watirspec/elements/label_spec.rb +79 -0
- data/spec/watirspec/elements/labels_spec.rb +40 -0
- data/spec/watirspec/elements/li_spec.rb +115 -0
- data/spec/watirspec/elements/link_spec.rb +174 -0
- data/spec/watirspec/elements/links_spec.rb +44 -0
- data/spec/watirspec/elements/lis_spec.rb +42 -0
- data/spec/watirspec/elements/map_spec.rb +79 -0
- data/spec/watirspec/elements/maps_spec.rb +41 -0
- data/spec/watirspec/elements/meta_spec.rb +23 -0
- data/spec/watirspec/elements/metas_spec.rb +40 -0
- data/spec/watirspec/elements/ol_spec.rb +89 -0
- data/spec/watirspec/elements/ols_spec.rb +40 -0
- data/spec/watirspec/elements/option_spec.rb +152 -0
- data/spec/watirspec/elements/p_spec.rb +115 -0
- data/spec/watirspec/elements/pre_spec.rb +115 -0
- data/spec/watirspec/elements/pres_spec.rb +40 -0
- data/spec/watirspec/elements/ps_spec.rb +40 -0
- data/spec/watirspec/elements/radio_spec.rb +263 -0
- data/spec/watirspec/elements/radios_spec.rb +43 -0
- data/spec/watirspec/elements/select_list_spec.rb +379 -0
- data/spec/watirspec/elements/select_lists_spec.rb +46 -0
- data/spec/watirspec/elements/span_spec.rb +129 -0
- data/spec/watirspec/elements/spans_spec.rb +40 -0
- data/spec/watirspec/elements/strong_spec.rb +92 -0
- data/spec/watirspec/elements/strongs_spec.rb +43 -0
- data/spec/watirspec/elements/table_nesting_spec.rb +51 -0
- data/spec/watirspec/elements/table_spec.rb +146 -0
- data/spec/watirspec/elements/tables_spec.rb +42 -0
- data/spec/watirspec/elements/tbody_spec.rb +96 -0
- data/spec/watirspec/elements/tbodys_spec.rb +62 -0
- data/spec/watirspec/elements/td_spec.rb +71 -0
- data/spec/watirspec/elements/tds_spec.rb +53 -0
- data/spec/watirspec/elements/text_field_spec.rb +302 -0
- data/spec/watirspec/elements/text_fields_spec.rb +44 -0
- data/spec/watirspec/elements/textarea_spec.rb +26 -0
- data/spec/watirspec/elements/textareas_spec.rb +24 -0
- data/spec/watirspec/elements/tfoot_spec.rb +91 -0
- data/spec/watirspec/elements/tfoots_spec.rb +68 -0
- data/spec/watirspec/elements/thead_spec.rb +91 -0
- data/spec/watirspec/elements/theads_spec.rb +68 -0
- data/spec/watirspec/elements/tr_spec.rb +80 -0
- data/spec/watirspec/elements/trs_spec.rb +61 -0
- data/spec/watirspec/elements/ul_spec.rb +79 -0
- data/spec/watirspec/elements/uls_spec.rb +39 -0
- data/spec/watirspec/html/alerts.html +12 -0
- data/spec/watirspec/html/aria_attributes.html +9 -0
- data/spec/watirspec/html/class_locator.html +8 -0
- data/spec/watirspec/html/clicks.html +19 -0
- data/spec/watirspec/html/closeable.html +13 -0
- data/spec/watirspec/html/collections.html +15 -0
- data/spec/watirspec/html/css/jquery-ui-1.8.17.custom.css +287 -0
- data/spec/watirspec/html/data_attributes.html +9 -0
- data/spec/watirspec/html/definition_lists.html +48 -0
- data/spec/watirspec/html/drag_and_drop.html +106 -0
- data/spec/watirspec/html/font.html +10 -0
- data/spec/watirspec/html/forms_with_input_elements.html +170 -0
- data/spec/watirspec/html/frame_1.html +22 -0
- data/spec/watirspec/html/frame_2.html +16 -0
- data/spec/watirspec/html/frames.html +11 -0
- data/spec/watirspec/html/hover.html +12 -0
- data/spec/watirspec/html/iframe_1.html +22 -0
- data/spec/watirspec/html/iframes.html +12 -0
- data/spec/watirspec/html/images.html +28 -0
- data/spec/watirspec/html/images/1.gif +0 -0
- data/spec/watirspec/html/images/2.gif +0 -0
- data/spec/watirspec/html/images/3.gif +0 -0
- data/spec/watirspec/html/images/button.png +0 -0
- data/spec/watirspec/html/images/circle.png +0 -0
- data/spec/watirspec/html/images/map.gif +0 -0
- data/spec/watirspec/html/images/map2.gif +0 -0
- data/spec/watirspec/html/images/minus.gif +0 -0
- data/spec/watirspec/html/images/originaltriangle.png +0 -0
- data/spec/watirspec/html/images/plus.gif +0 -0
- data/spec/watirspec/html/images/square.png +0 -0
- data/spec/watirspec/html/images/triangle.png +0 -0
- data/spec/watirspec/html/inner_outer.html +5 -0
- data/spec/watirspec/html/javascript/helpers.js +16 -0
- data/spec/watirspec/html/javascript/jquery-1.7.1.min.js +4 -0
- data/spec/watirspec/html/javascript/jquery-ui-1.8.17.custom.min.js +68 -0
- data/spec/watirspec/html/keylogger.html +15 -0
- data/spec/watirspec/html/modal_dialog.html +9 -0
- data/spec/watirspec/html/multiple_ids.html +14 -0
- data/spec/watirspec/html/nested_frame_1.html +1 -0
- data/spec/watirspec/html/nested_frame_2.html +9 -0
- data/spec/watirspec/html/nested_frame_3.html +14 -0
- data/spec/watirspec/html/nested_frames.html +10 -0
- data/spec/watirspec/html/nested_iframe_2.html +12 -0
- data/spec/watirspec/html/nested_iframes.html +9 -0
- data/spec/watirspec/html/nested_tables.html +203 -0
- data/spec/watirspec/html/non_control_elements.html +135 -0
- data/spec/watirspec/html/removed_element.html +24 -0
- data/spec/watirspec/html/right_click.html +11 -0
- data/spec/watirspec/html/special_chars.html +12 -0
- data/spec/watirspec/html/tables.html +121 -0
- data/spec/watirspec/html/timeout_window_location.html +19 -0
- data/spec/watirspec/html/uneven_table.html +20 -0
- data/spec/watirspec/html/wait.html +65 -0
- data/spec/watirspec/html/watirspec.css +0 -0
- data/spec/watirspec/html/window_switching.html +12 -0
- data/spec/watirspec/relaxed_locate_spec.rb +214 -0
- data/spec/watirspec/screenshot_spec.rb +29 -0
- data/spec/watirspec/wait_spec.rb +304 -0
- data/spec/watirspec/window_switching_spec.rb +411 -0
- data/spec/{implementation.rb → watirspec_helper.rb} +13 -13
- data/support/appveyor.cmd +9 -0
- data/support/doctest_helper.rb +5 -1
- data/support/travis.sh +0 -1
- data/watir.gemspec +3 -4
- metadata +323 -30
- data/.gitmodules +0 -3
@@ -0,0 +1,43 @@
|
|
1
|
+
require "watirspec_helper"
|
2
|
+
|
3
|
+
describe "Radios" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with selectors" do
|
10
|
+
it "returns the matching elements" do
|
11
|
+
expect(browser.radios(value: "yes").to_a).to eq [browser.radio(value: "yes")]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#length" do
|
16
|
+
it "returns the number of radios" do
|
17
|
+
expect(browser.radios.length).to eq 6
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#[]" do
|
22
|
+
it "returns the radio button at the given index" do
|
23
|
+
expect(browser.radios[0].id).to eq "new_user_newsletter_yes"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#each" do
|
28
|
+
it "iterates through radio buttons correctly" do
|
29
|
+
count = 0
|
30
|
+
|
31
|
+
browser.radios.each_with_index do |r, index|
|
32
|
+
expect(r.name).to eq browser.radio(index: index).name
|
33
|
+
expect(r.id).to eq browser.radio(index: index).id
|
34
|
+
expect(r.value).to eq browser.radio(index: index).value
|
35
|
+
|
36
|
+
count += 1
|
37
|
+
end
|
38
|
+
|
39
|
+
expect(count).to be > 0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,379 @@
|
|
1
|
+
require "watirspec_helper"
|
2
|
+
|
3
|
+
describe "SelectList" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
|
7
|
+
end
|
8
|
+
|
9
|
+
# Exists method
|
10
|
+
describe "#exists?" do
|
11
|
+
it "returns true if the select list exists" do
|
12
|
+
expect(browser.select_list(id: 'new_user_country')).to exist
|
13
|
+
expect(browser.select_list(id: /new_user_country/)).to exist
|
14
|
+
expect(browser.select_list(name: 'new_user_country')).to exist
|
15
|
+
expect(browser.select_list(name: /new_user_country/)).to exist
|
16
|
+
expect(browser.select_list(class: 'country')).to exist
|
17
|
+
expect(browser.select_list(class: /country/)).to exist
|
18
|
+
expect(browser.select_list(index: 0)).to exist
|
19
|
+
expect(browser.select_list(xpath: "//select[@id='new_user_country']")).to exist
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns the first select if given no args" do
|
23
|
+
expect(browser.select_list).to exist
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns false if the select list doesn't exist" do
|
27
|
+
expect(browser.select_list(id: 'no_such_id')).to_not exist
|
28
|
+
expect(browser.select_list(id: /no_such_id/)).to_not exist
|
29
|
+
expect(browser.select_list(name: 'no_such_name')).to_not exist
|
30
|
+
expect(browser.select_list(name: /no_such_name/)).to_not exist
|
31
|
+
expect(browser.select_list(value: 'no_such_value')).to_not exist
|
32
|
+
expect(browser.select_list(value: /no_such_value/)).to_not exist
|
33
|
+
expect(browser.select_list(text: 'no_such_text')).to_not exist
|
34
|
+
expect(browser.select_list(text: /no_such_text/)).to_not exist
|
35
|
+
expect(browser.select_list(class: 'no_such_class')).to_not exist
|
36
|
+
expect(browser.select_list(class: /no_such_class/)).to_not exist
|
37
|
+
expect(browser.select_list(index: 1337)).to_not exist
|
38
|
+
expect(browser.select_list(xpath: "//select[@id='no_such_id']")).to_not exist
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises TypeError when 'what' argument is invalid" do
|
42
|
+
expect { browser.select_list(id: 3.14).exists? }.to raise_error(TypeError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
46
|
+
expect { browser.select_list(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Attribute methods
|
51
|
+
describe "#class_name" do
|
52
|
+
it "returns the class name of the select list" do
|
53
|
+
expect(browser.select_list(name: 'new_user_country').class_name).to eq 'country'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "raises UnknownObjectException if the select list doesn't exist" do
|
57
|
+
expect { browser.select_list(name: 'no_such_name').class_name }.to raise_unknown_object_exception
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#id" do
|
62
|
+
it "returns the id of the element" do
|
63
|
+
expect(browser.select_list(index: 0).id).to eq "new_user_country"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises UnknownObjectException if the select list doesn't exist" do
|
67
|
+
expect { browser.select_list(index: 1337).id }.to raise_unknown_object_exception
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#name" do
|
72
|
+
it "returns the name of the element" do
|
73
|
+
expect(browser.select_list(index: 0).name).to eq "new_user_country"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "raises UnknownObjectException if the select list doesn't exist" do
|
77
|
+
expect { browser.select_list(index: 1337).name }.to raise_unknown_object_exception
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#multiple?" do
|
82
|
+
it "knows whether the select list allows multiple selections" do
|
83
|
+
expect(browser.select_list(index: 0)).to_not be_multiple
|
84
|
+
expect(browser.select_list(index: 1)).to be_multiple
|
85
|
+
end
|
86
|
+
|
87
|
+
it "raises UnknownObjectException if the select list doesn't exist" do
|
88
|
+
expect { browser.select_list(index: 1337).multiple? }.to raise_unknown_object_exception
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#value" do
|
93
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
94
|
+
it "returns the value of the selected option" do
|
95
|
+
expect(browser.select_list(index: 0).value).to eq "2"
|
96
|
+
browser.select_list(index: 0).select(/Sweden/)
|
97
|
+
expect(browser.select_list(index: 0).value).to eq "3"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "raises UnknownObjectException if the select list doesn't exist" do
|
102
|
+
expect { browser.select_list(index: 1337).value }.to raise_unknown_object_exception
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#respond_to?" do
|
107
|
+
it "returns true for all attribute methods" do
|
108
|
+
expect(browser.select_list(index: 0)).to respond_to(:class_name)
|
109
|
+
expect(browser.select_list(index: 0)).to respond_to(:id)
|
110
|
+
expect(browser.select_list(index: 0)).to respond_to(:name)
|
111
|
+
expect(browser.select_list(index: 0)).to respond_to(:value)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Access methods
|
116
|
+
describe "#enabled?" do
|
117
|
+
it "returns true if the select list is enabled" do
|
118
|
+
expect(browser.select_list(name: 'new_user_country')).to be_enabled
|
119
|
+
end
|
120
|
+
|
121
|
+
it "returns false if the select list is disabled" do
|
122
|
+
expect(browser.select_list(name: 'new_user_role')).to_not be_enabled
|
123
|
+
end
|
124
|
+
|
125
|
+
it "raises UnknownObjectException if the select_list doesn't exist" do
|
126
|
+
expect { browser.select_list(name: 'no_such_name').enabled? }.to raise_unknown_object_exception
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#disabled?" do
|
131
|
+
it "returns true if the select list is disabled" do
|
132
|
+
expect(browser.select_list(index: 2)).to be_disabled
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns false if the select list is enabled" do
|
136
|
+
expect(browser.select_list(index: 0)).to_not be_disabled
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should raise UnknownObjectException when the select list does not exist" do
|
140
|
+
expect { browser.select_list(index: 1337).disabled? }.to raise_unknown_object_exception
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# Other
|
145
|
+
describe "#option" do
|
146
|
+
it "returns an instance of Option" do
|
147
|
+
option = browser.select_list(name: "new_user_country").option(text: "Denmark")
|
148
|
+
expect(option).to be_instance_of(Watir::Option)
|
149
|
+
expect(option.value).to eq "1"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "#options" do
|
154
|
+
it "returns all the options" do
|
155
|
+
options = browser.select_list(name: "new_user_country").options
|
156
|
+
expect(options.map(&:text)).to eq ["Denmark", "Norway", "Sweden", "United Kingdom", "USA", "Germany"]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#selected_options" do
|
161
|
+
it "should raise UnknownObjectException if the select list doesn't exist" do
|
162
|
+
expect { browser.select_list(name: 'no_such_name').selected_options }.to raise_unknown_object_exception
|
163
|
+
end
|
164
|
+
|
165
|
+
it "gets the currently selected item(s)" do
|
166
|
+
expect(browser.select_list(name: "new_user_country").selected_options.map(&:text)).to eq ["Norway"]
|
167
|
+
expect(browser.select_list(name: "new_user_languages").selected_options.map(&:text)).to eq ["English", "Norwegian"]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "#clear" do
|
172
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
173
|
+
it "clears the selection when possible" do
|
174
|
+
browser.select_list(name: "new_user_languages").clear
|
175
|
+
expect(browser.select_list(name: "new_user_languages").selected_options).to be_empty
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it "does not clear selections if the select list does not allow multiple selections" do
|
180
|
+
expect {
|
181
|
+
browser.select_list(name: "new_user_country").clear
|
182
|
+
}.to raise_error(/you can only clear multi-selects/)
|
183
|
+
|
184
|
+
expect(browser.select_list(name: "new_user_country").selected_options.map(&:text)).to eq ["Norway"]
|
185
|
+
end
|
186
|
+
|
187
|
+
it "raises UnknownObjectException if the select list doesn't exist" do
|
188
|
+
expect { browser.select_list(name: 'no_such_name').clear }.to raise_unknown_object_exception
|
189
|
+
end
|
190
|
+
|
191
|
+
not_compliant_on :safari do
|
192
|
+
bug "Not firing events", :phantomjs do
|
193
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
194
|
+
it "fires onchange event" do
|
195
|
+
browser.select_list(name: "new_user_languages").clear
|
196
|
+
expect(messages.size).to eq 2
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it "doesn't fire onchange event for already cleared option" do
|
202
|
+
browser.select_list(name: "new_user_languages").option.clear
|
203
|
+
expect(messages.size).to eq 0
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "#include?" do
|
209
|
+
it "returns true if the given option exists by text" do
|
210
|
+
expect(browser.select_list(name: 'new_user_country')).to include('Denmark')
|
211
|
+
end
|
212
|
+
|
213
|
+
it "returns true if the given option exists by label" do
|
214
|
+
expect(browser.select_list(name: 'new_user_country')).to include('Germany')
|
215
|
+
end
|
216
|
+
|
217
|
+
it "returns false if the given option doesn't exist" do
|
218
|
+
expect(browser.select_list(name: 'new_user_country')).to_not include('Ireland')
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "#selected?" do
|
223
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
224
|
+
it "returns true if the given option is selected by text" do
|
225
|
+
browser.select_list(name: 'new_user_country').select('Denmark')
|
226
|
+
expect(browser.select_list(name: 'new_user_country')).to be_selected('Denmark')
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
it "returns false if the given option is not selected by text" do
|
231
|
+
expect(browser.select_list(name: 'new_user_country')).to_not be_selected('Sweden')
|
232
|
+
end
|
233
|
+
|
234
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
235
|
+
it "returns true if the given option is selected by label" do
|
236
|
+
browser.select_list(name: 'new_user_country').select('Germany')
|
237
|
+
expect(browser.select_list(name: 'new_user_country')).to be_selected('Germany')
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
it "returns false if the given option is not selected by label" do
|
242
|
+
expect(browser.select_list(name: 'new_user_country')).to_not be_selected('Germany')
|
243
|
+
end
|
244
|
+
|
245
|
+
it "raises UnknownObjectException if the option doesn't exist" do
|
246
|
+
expect { browser.select_list(name: 'new_user_country').selected?('missing_option') }.to raise_unknown_object_exception
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "#select" do
|
251
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
252
|
+
context "when interacting with options" do
|
253
|
+
it "selects the given item when given a String" do
|
254
|
+
browser.select_list(name: "new_user_country").select("Denmark")
|
255
|
+
expect(browser.select_list(name: "new_user_country").selected_options.map(&:text)).to eq ["Denmark"]
|
256
|
+
end
|
257
|
+
|
258
|
+
it "selects options by label" do
|
259
|
+
browser.select_list(name: "new_user_country").select("Germany")
|
260
|
+
expect(browser.select_list(name: "new_user_country").selected_options.map(&:text)).to eq ["Germany"]
|
261
|
+
end
|
262
|
+
|
263
|
+
it "selects the given item when given a Regexp" do
|
264
|
+
browser.select_list(name: "new_user_country").select(/Denmark/)
|
265
|
+
expect(browser.select_list(name: "new_user_country").selected_options.map(&:text)).to eq ["Denmark"]
|
266
|
+
end
|
267
|
+
|
268
|
+
it "selects the given item when given an Xpath" do
|
269
|
+
browser.select_list(xpath: "//select[@name='new_user_country']").select("Denmark")
|
270
|
+
expect(browser.select_list(xpath: "//select[@name='new_user_country']").selected_options.map(&:text)).to eq ["Denmark"]
|
271
|
+
end
|
272
|
+
|
273
|
+
it "selects multiple items using :name and a String" do
|
274
|
+
browser.select_list(name: "new_user_languages").clear
|
275
|
+
browser.select_list(name: "new_user_languages").select("Danish")
|
276
|
+
browser.select_list(name: "new_user_languages").select("Swedish")
|
277
|
+
expect(browser.select_list(name: "new_user_languages").selected_options.map(&:text)).to eq ["Danish", "Swedish"]
|
278
|
+
end
|
279
|
+
|
280
|
+
it "selects multiple items using :name and a Regexp" do
|
281
|
+
browser.select_list(name: "new_user_languages").clear
|
282
|
+
browser.select_list(name: "new_user_languages").select(/ish/)
|
283
|
+
expect(browser.select_list(name: "new_user_languages").selected_options.map(&:text)).to eq ["Danish", "English", "Swedish"]
|
284
|
+
end
|
285
|
+
|
286
|
+
it "selects multiple items using :xpath" do
|
287
|
+
browser.select_list(xpath: "//select[@name='new_user_languages']").clear
|
288
|
+
browser.select_list(xpath: "//select[@name='new_user_languages']").select(/ish/)
|
289
|
+
expect(browser.select_list(xpath: "//select[@name='new_user_languages']").selected_options.map(&:text)).to eq ["Danish", "English", "Swedish"]
|
290
|
+
end
|
291
|
+
|
292
|
+
it "selects empty options" do
|
293
|
+
browser.select_list(id: "delete_user_username").select("")
|
294
|
+
expect(browser.select_list(id: "delete_user_username").selected_options.map(&:text)).to eq [""]
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
it "returns the value selected" do
|
300
|
+
expect(browser.select_list(name: "new_user_languages").select("Danish")).to eq "Danish"
|
301
|
+
end
|
302
|
+
|
303
|
+
it "returns the first matching value if there are multiple matches" do
|
304
|
+
expect(browser.select_list(name: "new_user_languages").select(/ish/)).to eq "Danish"
|
305
|
+
end
|
306
|
+
|
307
|
+
not_compliant_on :safari do
|
308
|
+
bug "Not firing events", :phantomjs do
|
309
|
+
it "fires onchange event when selecting an item" do
|
310
|
+
browser.select_list(id: "new_user_languages").select("Danish")
|
311
|
+
expect(messages).to eq ['changed language']
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
bug "Not firing events", :phantomjs do
|
316
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
317
|
+
it "doesn't fire onchange event when selecting an already selected item" do
|
318
|
+
browser.select_list(id: "new_user_languages").clear # removes the two pre-selected options
|
319
|
+
browser.select_list(id: "new_user_languages").select("English")
|
320
|
+
expect(messages.size).to eq 3
|
321
|
+
|
322
|
+
browser.select_list(id: "new_user_languages").select("English")
|
323
|
+
expect(messages.size).to eq 3
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
it "returns the text of the selected option" do
|
330
|
+
expect(browser.select_list(id: "new_user_languages").select("English")).to eq "English"
|
331
|
+
end
|
332
|
+
|
333
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
334
|
+
it "returns an empty string when selecting an option that disappears when selected" do
|
335
|
+
expect(browser.select_list(id: 'obsolete').select('sweden')).to eq ''
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
it "selects options with a single-quoted value" do
|
340
|
+
browser.select_list(id: 'single-quote').select("'foo'")
|
341
|
+
end
|
342
|
+
|
343
|
+
it "raises NoValueFoundException if the option doesn't exist" do
|
344
|
+
expect { browser.select_list(name: "new_user_country").select("missing_option") }.to raise_error(Watir::Exception::NoValueFoundException)
|
345
|
+
expect { browser.select_list(name: "new_user_country").select(/missing_option/) }.to raise_error(Watir::Exception::NoValueFoundException)
|
346
|
+
end
|
347
|
+
|
348
|
+
it "raises ObjectDisabledException if the option is disabled" do
|
349
|
+
expect { browser.select_list(name: "new_user_languages").select("Russian") }.to raise_object_disabled_exception
|
350
|
+
end
|
351
|
+
|
352
|
+
it "raises a TypeError if argument is not a String, Regexp or Numeric" do
|
353
|
+
expect { browser.select_list(id: "new_user_languages").select([]) }.to raise_error(TypeError)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
# deprecate?
|
358
|
+
describe "#select_value" do
|
359
|
+
it "selects the item by value string" do
|
360
|
+
browser.select_list(name: "new_user_languages").clear
|
361
|
+
browser.select_list(name: "new_user_languages").select_value("2")
|
362
|
+
expect(browser.select_list(name: "new_user_languages").selected_options.map(&:text)).to eq %w[English]
|
363
|
+
end
|
364
|
+
|
365
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
366
|
+
it "selects the items by value regexp" do
|
367
|
+
browser.select_list(name: "new_user_languages").clear
|
368
|
+
browser.select_list(name: "new_user_languages").select_value(/1|3/)
|
369
|
+
expect(browser.select_list(name: "new_user_languages").selected_options.map(&:text)).to eq %w[Danish Norwegian]
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
it "raises NoValueFoundException if the option doesn't exist" do
|
374
|
+
expect { browser.select_list(name: "new_user_languages").select_value("no_such_option") }.to raise_error(Watir::Exception::NoValueFoundException)
|
375
|
+
expect { browser.select_list(name: "new_user_languages").select_value(/no_such_option/) }.to raise_error(Watir::Exception::NoValueFoundException)
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "watirspec_helper"
|
2
|
+
|
3
|
+
describe "SelectLists" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with selectors" do
|
10
|
+
it "returns the matching elements" do
|
11
|
+
expect(browser.select_lists(name: "delete_user_username").to_a).to eq [browser.select_list(name: "delete_user_username")]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#length" do
|
16
|
+
it "returns the correct number of select lists on the page" do
|
17
|
+
expect(browser.select_lists.length).to eq 6
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#[]" do
|
22
|
+
it "returns the correct item" do
|
23
|
+
expect(browser.select_lists[0].value).to eq "2"
|
24
|
+
expect(browser.select_lists[0].name).to eq "new_user_country"
|
25
|
+
expect(browser.select_lists[0]).to_not be_multiple
|
26
|
+
expect(browser.select_lists[1]).to be_multiple
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#each" do
|
31
|
+
it "iterates through the select lists correctly" do
|
32
|
+
count = 0
|
33
|
+
|
34
|
+
browser.select_lists.each_with_index do |l, index|
|
35
|
+
expect(browser.select_list(index: index).name).to eq l.name
|
36
|
+
expect(browser.select_list(index: index).id).to eq l.id
|
37
|
+
expect(browser.select_list(index: index).value).to eq l.value
|
38
|
+
|
39
|
+
count += 1
|
40
|
+
end
|
41
|
+
|
42
|
+
expect(count).to be > 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|