watir 7.2.0 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/chrome.yml +1 -1
  3. data/.github/workflows/edge.yml +1 -1
  4. data/.github/workflows/firefox.yml +1 -1
  5. data/.github/workflows/ie.yml +1 -1
  6. data/.github/workflows/safari.yml +1 -1
  7. data/.github/workflows/unit.yml +1 -1
  8. data/.rubocop.yml +25 -12
  9. data/.rubocop_todo.yml +8 -1
  10. data/CHANGES.md +6 -1
  11. data/LICENSE +2 -2
  12. data/lib/watir/capabilities.rb +1 -1
  13. data/lib/watir/locators/anchor/selector_builder.rb +3 -0
  14. data/lib/watir/locators/element/matcher.rb +2 -1
  15. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
  16. data/lib/watir/locators/text_field/matcher.rb +0 -4
  17. data/lib/watir/version.rb +1 -1
  18. data/spec/locator_spec_helper.rb +0 -8
  19. data/spec/unit/capabilities_spec.rb +553 -561
  20. data/spec/unit/element_locator_spec.rb +89 -78
  21. data/spec/unit/match_elements/button_spec.rb +69 -62
  22. data/spec/unit/match_elements/element_spec.rb +303 -309
  23. data/spec/unit/match_elements/text_field_spec.rb +76 -73
  24. data/spec/unit/selector_builder/anchor_spec.rb +39 -33
  25. data/spec/unit/selector_builder/button_spec.rb +209 -202
  26. data/spec/unit/selector_builder/cell_spec.rb +48 -42
  27. data/spec/unit/selector_builder/element_spec.rb +634 -627
  28. data/spec/unit/selector_builder/row_spec.rb +119 -113
  29. data/spec/unit/selector_builder/text_field_spec.rb +195 -188
  30. data/spec/unit/selector_builder/textarea_spec.rb +22 -14
  31. data/spec/unit/wait_spec.rb +85 -81
  32. data/spec/watirspec/adjacent_spec.rb +249 -247
  33. data/spec/watirspec/after_hooks_spec.rb +161 -159
  34. data/spec/watirspec/alert_spec.rb +61 -58
  35. data/spec/watirspec/browser_spec.rb +409 -409
  36. data/spec/watirspec/capabilities_spec.rb +89 -99
  37. data/spec/watirspec/cookies_spec.rb +120 -118
  38. data/spec/watirspec/drag_and_drop_spec.rb +26 -24
  39. data/spec/watirspec/element_hidden_spec.rb +66 -60
  40. data/spec/watirspec/elements/area_spec.rb +49 -47
  41. data/spec/watirspec/elements/areas_spec.rb +27 -25
  42. data/spec/watirspec/elements/button_spec.rb +253 -251
  43. data/spec/watirspec/elements/buttons_spec.rb +36 -34
  44. data/spec/watirspec/elements/checkbox_spec.rb +48 -36
  45. data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
  46. data/spec/watirspec/elements/collections_spec.rb +126 -119
  47. data/spec/watirspec/elements/date_field_spec.rb +185 -183
  48. data/spec/watirspec/elements/date_fields_spec.rb +29 -27
  49. data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
  50. data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
  51. data/spec/watirspec/elements/dd_spec.rb +87 -85
  52. data/spec/watirspec/elements/dds_spec.rb +27 -25
  53. data/spec/watirspec/elements/del_spec.rb +106 -104
  54. data/spec/watirspec/elements/dels_spec.rb +26 -24
  55. data/spec/watirspec/elements/div_spec.rb +225 -221
  56. data/spec/watirspec/elements/divs_spec.rb +37 -35
  57. data/spec/watirspec/elements/dl_spec.rb +110 -108
  58. data/spec/watirspec/elements/dls_spec.rb +28 -26
  59. data/spec/watirspec/elements/dt_spec.rb +86 -84
  60. data/spec/watirspec/elements/dts_spec.rb +27 -25
  61. data/spec/watirspec/elements/element_spec.rb +794 -775
  62. data/spec/watirspec/elements/elements_spec.rb +40 -38
  63. data/spec/watirspec/elements/em_spec.rb +62 -60
  64. data/spec/watirspec/elements/ems_spec.rb +28 -26
  65. data/spec/watirspec/elements/filefield_spec.rb +116 -114
  66. data/spec/watirspec/elements/filefields_spec.rb +28 -26
  67. data/spec/watirspec/elements/font_spec.rb +20 -18
  68. data/spec/watirspec/elements/form_spec.rb +51 -49
  69. data/spec/watirspec/elements/forms_spec.rb +29 -27
  70. data/spec/watirspec/elements/frame_spec.rb +89 -87
  71. data/spec/watirspec/elements/frames_spec.rb +27 -25
  72. data/spec/watirspec/elements/hidden_spec.rb +81 -79
  73. data/spec/watirspec/elements/hiddens_spec.rb +28 -26
  74. data/spec/watirspec/elements/hn_spec.rb +59 -57
  75. data/spec/watirspec/elements/hns_spec.rb +26 -24
  76. data/spec/watirspec/elements/iframe_spec.rb +195 -191
  77. data/spec/watirspec/elements/iframes_spec.rb +31 -29
  78. data/spec/watirspec/elements/image_spec.rb +148 -146
  79. data/spec/watirspec/elements/images_spec.rb +26 -24
  80. data/spec/watirspec/elements/input_spec.rb +9 -7
  81. data/spec/watirspec/elements/ins_spec.rb +106 -104
  82. data/spec/watirspec/elements/inses_spec.rb +26 -24
  83. data/spec/watirspec/elements/label_spec.rb +56 -54
  84. data/spec/watirspec/elements/labels_spec.rb +26 -24
  85. data/spec/watirspec/elements/li_spec.rb +76 -74
  86. data/spec/watirspec/elements/link_spec.rb +173 -177
  87. data/spec/watirspec/elements/links_spec.rb +45 -43
  88. data/spec/watirspec/elements/lis_spec.rb +27 -25
  89. data/spec/watirspec/elements/list_spec.rb +44 -42
  90. data/spec/watirspec/elements/map_spec.rb +57 -55
  91. data/spec/watirspec/elements/maps_spec.rb +27 -25
  92. data/spec/watirspec/elements/meta_spec.rb +16 -14
  93. data/spec/watirspec/elements/metas_spec.rb +26 -24
  94. data/spec/watirspec/elements/ol_spec.rb +56 -65
  95. data/spec/watirspec/elements/ols_spec.rb +26 -24
  96. data/spec/watirspec/elements/option_spec.rb +91 -89
  97. data/spec/watirspec/elements/p_spec.rb +81 -79
  98. data/spec/watirspec/elements/pre_spec.rb +77 -75
  99. data/spec/watirspec/elements/pres_spec.rb +26 -24
  100. data/spec/watirspec/elements/ps_spec.rb +26 -24
  101. data/spec/watirspec/elements/radio_spec.rb +251 -249
  102. data/spec/watirspec/elements/radios_spec.rb +28 -26
  103. data/spec/watirspec/elements/select_list_spec.rb +537 -526
  104. data/spec/watirspec/elements/select_lists_spec.rb +32 -30
  105. data/spec/watirspec/elements/span_spec.rb +112 -110
  106. data/spec/watirspec/elements/spans_spec.rb +26 -24
  107. data/spec/watirspec/elements/strong_spec.rb +58 -58
  108. data/spec/watirspec/elements/strongs_spec.rb +28 -26
  109. data/spec/watirspec/elements/table_spec.rb +192 -139
  110. data/spec/watirspec/elements/tables_spec.rb +28 -26
  111. data/spec/watirspec/elements/tbody_spec.rb +74 -72
  112. data/spec/watirspec/elements/tbodys_spec.rb +40 -38
  113. data/spec/watirspec/elements/td_spec.rb +66 -64
  114. data/spec/watirspec/elements/tds_spec.rb +41 -39
  115. data/spec/watirspec/elements/text_field_spec.rb +206 -204
  116. data/spec/watirspec/elements/text_fields_spec.rb +30 -28
  117. data/spec/watirspec/elements/textarea_spec.rb +20 -18
  118. data/spec/watirspec/elements/textareas_spec.rb +18 -16
  119. data/spec/watirspec/elements/tfoot_spec.rb +65 -63
  120. data/spec/watirspec/elements/tfoots_spec.rb +42 -40
  121. data/spec/watirspec/elements/thead_spec.rb +65 -63
  122. data/spec/watirspec/elements/theads_spec.rb +42 -40
  123. data/spec/watirspec/elements/tr_spec.rb +48 -46
  124. data/spec/watirspec/elements/trs_spec.rb +42 -40
  125. data/spec/watirspec/elements/ul_spec.rb +56 -54
  126. data/spec/watirspec/elements/uls_spec.rb +26 -24
  127. data/spec/watirspec/radio_set_spec.rb +269 -267
  128. data/spec/watirspec/screenshot_spec.rb +20 -18
  129. data/spec/watirspec/scroll_spec.rb +152 -148
  130. data/spec/watirspec/shadow_root_spec.rb +86 -83
  131. data/spec/watirspec/user_editable_spec.rb +200 -198
  132. data/spec/watirspec/wait_spec.rb +289 -295
  133. data/spec/watirspec/window_switching_spec.rb +422 -434
  134. data/spec/watirspec_helper.rb +1 -23
  135. data/watir.gemspec +5 -4
  136. metadata +44 -33
  137. data/spec/watirspec/attributes_spec.rb +0 -18
  138. data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
  139. data/spec/watirspec/special_chars_spec.rb +0 -23
@@ -2,343 +2,345 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'RadioSet' do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
8
- end
9
-
10
- # Exists method
11
- describe '#exists?' do
12
- it 'returns true if matches any radio_set button' do
13
- expect(browser.radio_set(id: 'new_user_newsletter_yes')).to exist
14
- expect(browser.radio_set(id: /new_user_newsletter_yes/)).to exist
15
- expect(browser.radio_set(name: 'new_user_newsletter')).to exist
16
- expect(browser.radio_set(name: /new_user_newsletter/)).to exist
17
- expect(browser.radio_set(value: 'yes')).to exist
18
- expect(browser.radio_set(value: /yes/)).to exist
19
- expect(browser.radio_set(class: 'huge')).to exist
20
- expect(browser.radio_set(class: /huge/)).to exist
21
- expect(browser.radio_set(index: 0)).to exist
22
- expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_yes']")).to exist
23
- end
24
-
25
- it 'returns false if no radio button exists' do
26
- expect(browser.radio_set(id: 'no_such_id')).to_not exist
27
- expect(browser.radio_set(id: /no_such_id/)).to_not exist
28
- expect(browser.radio_set(name: 'no_such_name')).to_not exist
29
- expect(browser.radio_set(name: /no_such_name/)).to_not exist
30
- expect(browser.radio_set(value: 'no_such_value')).to_not exist
31
- expect(browser.radio_set(value: /no_such_value/)).to_not exist
32
- expect(browser.radio_set(text: 'no_such_text')).to_not exist
33
- expect(browser.radio_set(text: /no_such_text/)).to_not exist
34
- expect(browser.radio_set(class: 'no_such_class')).to_not exist
35
- expect(browser.radio_set(class: /no_such_class/)).to_not exist
36
- expect(browser.radio_set(index: 1337)).to_not exist
37
- expect(browser.radio_set(xpath: "input[@id='no_such_id']")).to_not exist
38
- end
39
-
40
- it 'returns the first radio set if given no args' do
41
- expect(browser.radio_set).to exist
42
- end
43
-
44
- it "raises TypeError when 'what' argument is invalid" do
45
- expect { browser.radio_set(id: 3.14).exists? }.to raise_error(TypeError)
46
- end
47
- end
5
+ module Watir
6
+ describe RadioSet do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
9
+ end
10
+
11
+ # Exists method
12
+ describe '#exists?' do
13
+ it 'returns true if matches any radio_set button' do
14
+ expect(browser.radio_set(id: 'new_user_newsletter_yes')).to exist
15
+ expect(browser.radio_set(id: /new_user_newsletter_yes/)).to exist
16
+ expect(browser.radio_set(name: 'new_user_newsletter')).to exist
17
+ expect(browser.radio_set(name: /new_user_newsletter/)).to exist
18
+ expect(browser.radio_set(value: 'yes')).to exist
19
+ expect(browser.radio_set(value: /yes/)).to exist
20
+ expect(browser.radio_set(class: 'huge')).to exist
21
+ expect(browser.radio_set(class: /huge/)).to exist
22
+ expect(browser.radio_set(index: 0)).to exist
23
+ expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_yes']")).to exist
24
+ end
48
25
 
49
- # Attribute methods
50
- describe '#name' do
51
- it 'returns the name attribute if the radio exists' do
52
- expect(browser.radio_set(id: 'new_user_newsletter_yes').name).to eq 'new_user_newsletter'
53
- end
26
+ it 'returns false if no radio button exists' do
27
+ expect(browser.radio_set(id: 'no_such_id')).not_to exist
28
+ expect(browser.radio_set(id: /no_such_id/)).not_to exist
29
+ expect(browser.radio_set(name: 'no_such_name')).not_to exist
30
+ expect(browser.radio_set(name: /no_such_name/)).not_to exist
31
+ expect(browser.radio_set(value: 'no_such_value')).not_to exist
32
+ expect(browser.radio_set(value: /no_such_value/)).not_to exist
33
+ expect(browser.radio_set(text: 'no_such_text')).not_to exist
34
+ expect(browser.radio_set(text: /no_such_text/)).not_to exist
35
+ expect(browser.radio_set(class: 'no_such_class')).not_to exist
36
+ expect(browser.radio_set(class: /no_such_class/)).not_to exist
37
+ expect(browser.radio_set(index: 1337)).not_to exist
38
+ expect(browser.radio_set(xpath: "input[@id='no_such_id']")).not_to exist
39
+ end
54
40
 
55
- it 'returns an empty string if the radio exists and there is not name' do
56
- expect(browser.radio_set(id: 'new_user_newsletter_absolutely').name).to eq ''
57
- end
41
+ it 'returns the first radio set if given no args' do
42
+ expect(browser.radio_set).to exist
43
+ end
58
44
 
59
- it "raises UnknownObjectException if the radio doesn't exist" do
60
- expect { browser.radio_set(index: 1337).name }.to raise_unknown_object_exception
45
+ it "raises TypeError when 'what' argument is invalid" do
46
+ expect { browser.radio_set(id: 3.14).exists? }.to raise_error(TypeError)
47
+ end
61
48
  end
62
- end
63
49
 
64
- context 'without name specified' do
65
- it 'Finds specified radio' do
66
- expect(browser.radio_set(id: 'new_user_newsletter_absolutely').count).to eq 1
67
- expect(browser.radio_set(id: 'new_user_newsletter_absolutely').radios.size).to eq 1
68
- expect(browser.radio_set(id: 'new_user_newsletter_absolutely').radio(value: 'absolutely').exist?).to be true
69
- end
70
- end
50
+ # Attribute methods
51
+ describe '#name' do
52
+ it 'returns the name attribute if the radio exists' do
53
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').name).to eq 'new_user_newsletter'
54
+ end
71
55
 
72
- describe '#type' do
73
- it 'returns the type attribute if the radio set exists' do
74
- expect(browser.radio_set.type).to eq 'radio'
75
- end
56
+ it 'returns an empty string if the radio exists and there is not name' do
57
+ expect(browser.radio_set(id: 'new_user_newsletter_absolutely').name).to eq ''
58
+ end
76
59
 
77
- it "raises UnknownObjectException if the radio doesn't exist" do
78
- expect { browser.radio_set(index: 1337).type }.to raise_unknown_object_exception
60
+ it "raises UnknownObjectException if the radio doesn't exist" do
61
+ expect { browser.radio_set(index: 1337).name }.to raise_unknown_object_exception
62
+ end
79
63
  end
80
- end
81
64
 
82
- describe '#value' do
83
- it 'returns the value attributes of the selected radio button' do
84
- expect(browser.radio_set(id: 'new_user_newsletter_yes').value).to eq 'yes'
65
+ context 'without name specified' do
66
+ it 'Finds specified radio' do
67
+ expect(browser.radio_set(id: 'new_user_newsletter_absolutely').count).to eq 1
68
+ expect(browser.radio_set(id: 'new_user_newsletter_absolutely').radios.size).to eq 1
69
+ expect(browser.radio_set(id: 'new_user_newsletter_absolutely').radio(value: 'absolutely').exist?).to be true
70
+ end
85
71
  end
86
72
 
87
- it "raises UnknownObjectException if the radio doesn't exist" do
88
- expect { browser.radio_set(index: 1337).value }.to raise_unknown_object_exception
89
- end
90
- end
73
+ describe '#type' do
74
+ it 'returns the type attribute if the radio set exists' do
75
+ expect(browser.radio_set.type).to eq 'radio'
76
+ end
91
77
 
92
- describe '#text' do
93
- it 'returns the text of the selected radio button' do
94
- expect(browser.radio_set(id: 'new_user_newsletter_yes').text).to eq 'Yes'
78
+ it "raises UnknownObjectException if the radio doesn't exist" do
79
+ expect { browser.radio_set(index: 1337).type }.to raise_unknown_object_exception
80
+ end
95
81
  end
96
82
 
97
- it "raises UnknownObjectException if the radio set doesn't exist" do
98
- expect { browser.radio_set(index: 1337).text }.to raise_unknown_object_exception
99
- end
100
- end
83
+ describe '#value' do
84
+ it 'returns the value attributes of the selected radio button' do
85
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').value).to eq 'yes'
86
+ end
101
87
 
102
- describe '#respond_to?' do
103
- it 'returns true for all attribute methods' do
104
- expect(browser.radio_set(index: 0)).to_not respond_to(:class_name)
105
- expect(browser.radio_set(index: 0)).to_not respond_to(:id)
106
- expect(browser.radio_set(index: 0)).to respond_to(:name)
107
- expect(browser.radio_set(index: 0)).to_not respond_to(:title)
108
- expect(browser.radio_set(index: 0)).to respond_to(:type)
109
- expect(browser.radio_set(index: 0)).to respond_to(:value)
110
- expect(browser.radio_set(index: 0)).to respond_to(:text)
111
- expect(browser.radio_set(index: 0)).to_not respond_to(:clear)
88
+ it "raises UnknownObjectException if the radio doesn't exist" do
89
+ expect { browser.radio_set(index: 1337).value }.to raise_unknown_object_exception
90
+ end
112
91
  end
113
- end
114
92
 
115
- # Access methods
116
- describe '#enabled?' do
117
- it 'returns true if any radio button in the set is enabled' do
118
- expect(browser.radio_set(id: 'new_user_newsletter_nah')).to be_enabled
119
- expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_nah']")).to be_enabled
120
- end
93
+ describe '#text' do
94
+ it 'returns the text of the selected radio button' do
95
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').text).to eq 'Yes'
96
+ end
121
97
 
122
- it 'returns false if all radio buttons are disabled' do
123
- expect(browser.radio_set(id: 'new_user_newsletter_none')).to_not be_enabled
124
- expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_none']")).to_not be_enabled
98
+ it "raises UnknownObjectException if the radio set doesn't exist" do
99
+ expect { browser.radio_set(index: 1337).text }.to raise_unknown_object_exception
100
+ end
125
101
  end
126
102
 
127
- it "raises UnknownObjectException if the radio button doesn't exist" do
128
- expect { browser.radio_set(id: 'no_such_id').enabled? }.to raise_unknown_object_exception
129
- expect { browser.radio_set(xpath: "//input[@id='no_such_id']").enabled? }.to raise_unknown_object_exception
103
+ describe '#respond_to?' do
104
+ it 'returns true for all attribute methods' do
105
+ expect(browser.radio_set(index: 0)).not_to respond_to(:class_name)
106
+ expect(browser.radio_set(index: 0)).not_to respond_to(:id)
107
+ expect(browser.radio_set(index: 0)).to respond_to(:name)
108
+ expect(browser.radio_set(index: 0)).not_to respond_to(:title)
109
+ expect(browser.radio_set(index: 0)).to respond_to(:type)
110
+ expect(browser.radio_set(index: 0)).to respond_to(:value)
111
+ expect(browser.radio_set(index: 0)).to respond_to(:text)
112
+ expect(browser.radio_set(index: 0)).not_to respond_to(:clear)
113
+ end
130
114
  end
131
- end
132
115
 
133
- describe '#disabled?' do
134
- it 'returns false if the any radio button in the set is enabled' do
135
- expect(browser.radio_set(id: 'new_user_newsletter_nah')).to_not be_disabled
136
- expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_nah']")).to_not be_disabled
137
- end
116
+ # Access methods
117
+ describe '#enabled?' do
118
+ it 'returns true if any radio button in the set is enabled' do
119
+ expect(browser.radio_set(id: 'new_user_newsletter_nah')).to be_enabled
120
+ expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_nah']")).to be_enabled
121
+ end
138
122
 
139
- it 'returns true if all radio buttons are disabled' do
140
- expect(browser.radio_set(id: 'new_user_newsletter_none')).to be_disabled
141
- expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_none']")).to be_disabled
142
- end
123
+ it 'returns false if all radio buttons are disabled' do
124
+ expect(browser.radio_set(id: 'new_user_newsletter_none')).not_to be_enabled
125
+ expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_none']")).not_to be_enabled
126
+ end
143
127
 
144
- it 'should raise UnknownObjectException when the radio set does not exist' do
145
- expect { browser.radio_set(index: 1337).disabled? }.to raise_unknown_object_exception
128
+ it "raises UnknownObjectException if the radio button doesn't exist" do
129
+ expect { browser.radio_set(id: 'no_such_id').enabled? }.to raise_unknown_object_exception
130
+ expect { browser.radio_set(xpath: "//input[@id='no_such_id']").enabled? }.to raise_unknown_object_exception
131
+ end
146
132
  end
147
- end
148
133
 
149
- # Other
150
- describe '#radio' do
151
- it 'returns first instance of Radio if no arguments specified' do
152
- radio = browser.radio_set(id: 'new_user_newsletter_yes').radio
153
- expect(radio).to be_instance_of(Watir::Radio)
154
- expect(radio.value).to eq 'yes'
155
- end
134
+ describe '#disabled?' do
135
+ it 'returns false if the any radio button in the set is enabled' do
136
+ expect(browser.radio_set(id: 'new_user_newsletter_nah')).not_to be_disabled
137
+ expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_nah']")).not_to be_disabled
138
+ end
156
139
 
157
- it 'returns provided instance of Radio if element has no name' do
158
- radio = browser.radio_set(id: 'new_user_newsletter_absolutely').radio
159
- expect(radio).to be_instance_of(Watir::Radio)
160
- expect(radio.value).to eq 'absolutely'
161
- end
140
+ it 'returns true if all radio buttons are disabled' do
141
+ expect(browser.radio_set(id: 'new_user_newsletter_none')).to be_disabled
142
+ expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_none']")).to be_disabled
143
+ end
162
144
 
163
- it 'returns an instance of Radio matching the provided value' do
164
- radio = browser.radio_set(id: 'new_user_newsletter_yes').radio(id: 'new_user_newsletter_no')
165
- expect(radio).to be_instance_of(Watir::Radio)
166
- expect(radio.value).to eq 'no'
145
+ it 'raises UnknownObjectException when the radio set does not exist' do
146
+ expect { browser.radio_set(index: 1337).disabled? }.to raise_unknown_object_exception
147
+ end
167
148
  end
168
149
 
169
- it 'does not exist when using bad locator' do
170
- radio = browser.radio_set(id: 'new_user_newsletter_yes').radio(id: 'new_user_newsletter_not_there')
171
- expect(radio).to_not exist
172
- end
150
+ # Other
151
+ describe '#radio' do
152
+ it 'returns first instance of Radio if no arguments specified' do
153
+ radio = browser.radio_set(id: 'new_user_newsletter_yes').radio
154
+ expect(radio).to be_instance_of(Watir::Radio)
155
+ expect(radio.value).to eq 'yes'
156
+ end
173
157
 
174
- it 'raises Unknown Object Exception if it specifies the wrong name' do
175
- radio_set = browser.radio_set(id: 'new_user_newsletter_yes')
176
- expect { radio_set.radio(name: '') }.to raise_unknown_object_exception
177
- expect { radio_set.radio(name: 'foo') }.to raise_unknown_object_exception
178
- end
179
- end
158
+ it 'returns provided instance of Radio if element has no name' do
159
+ radio = browser.radio_set(id: 'new_user_newsletter_absolutely').radio
160
+ expect(radio).to be_instance_of(Watir::Radio)
161
+ expect(radio.value).to eq 'absolutely'
162
+ end
180
163
 
181
- describe '#radios' do
182
- it 'returns array of all radios in the set if no arguments specified' do
183
- radios = browser.radio_set(id: 'new_user_newsletter_yes').radios
184
- expect(radios).to be_instance_of(Watir::RadioCollection)
185
- values = %w[yes no certainly nah nah]
186
- expect(radios.map(&:value)).to match_array values
187
- end
164
+ it 'returns an instance of Radio matching the provided value' do
165
+ radio = browser.radio_set(id: 'new_user_newsletter_yes').radio(id: 'new_user_newsletter_no')
166
+ expect(radio).to be_instance_of(Watir::Radio)
167
+ expect(radio.value).to eq 'no'
168
+ end
188
169
 
189
- it 'returns RadioCollection matching the provided value' do
190
- radios = browser.radio_set(id: 'new_user_newsletter_yes').radios(id: /new_user_newsletter_n/)
191
- expect(radios).to be_instance_of(Watir::RadioCollection)
192
- expect(radios.map(&:value)).to eq %w[no nah]
193
- end
170
+ it 'does not exist when using bad locator' do
171
+ radio = browser.radio_set(id: 'new_user_newsletter_yes').radio(id: 'new_user_newsletter_not_there')
172
+ expect(radio).not_to exist
173
+ end
194
174
 
195
- it 'returns provided instance of Radio if element has no name' do
196
- radios = browser.radio_set(id: 'new_user_newsletter_absolutely').radios
197
- expect(radios).to be_instance_of(Watir::RadioCollection)
198
- expect(radios.size).to eq 1
199
- expect(radios.first.value).to eq 'absolutely'
175
+ it 'raises Unknown Object Exception if it specifies the wrong name' do
176
+ radio_set = browser.radio_set(id: 'new_user_newsletter_yes')
177
+ expect { radio_set.radio(name: '') }.to raise_unknown_object_exception
178
+ expect { radio_set.radio(name: 'foo') }.to raise_unknown_object_exception
179
+ end
200
180
  end
201
181
 
202
- it 'returns empty collection if specified radio does not exist' do
203
- radios = browser.radio_set(id: 'new_user_newsletter_yes').radios(id: 'new_user_newsletter_not_there')
204
- expect(radios).to be_empty
205
- end
182
+ describe '#radios' do
183
+ it 'returns array of all radios in the set if no arguments specified' do
184
+ radios = browser.radio_set(id: 'new_user_newsletter_yes').radios
185
+ expect(radios).to be_instance_of(Watir::RadioCollection)
186
+ values = %w[yes no certainly nah nah]
187
+ expect(radios.map(&:value)).to match_array values
188
+ end
206
189
 
207
- it 'raises empty collection if it specifies the wrong name' do
208
- radio_set = browser.radio_set(id: 'new_user_newsletter_yes')
209
- expect { radio_set.radios(name: '') }.to raise_unknown_object_exception
210
- end
190
+ it 'returns RadioCollection matching the provided value' do
191
+ radios = browser.radio_set(id: 'new_user_newsletter_yes').radios(id: /new_user_newsletter_n/)
192
+ expect(radios).to be_instance_of(Watir::RadioCollection)
193
+ expect(radios.map(&:value)).to eq %w[no nah]
194
+ end
211
195
 
212
- it 'returns the radio button at the specified index' do
213
- radio_set = browser.radio_set(id: 'new_user_newsletter_yes')
214
- expect(radio_set[1]).to be_a Watir::Radio
215
- end
216
- end
196
+ it 'returns provided instance of Radio if element has no name' do
197
+ radios = browser.radio_set(id: 'new_user_newsletter_absolutely').radios
198
+ expect(radios).to be_instance_of(Watir::RadioCollection)
199
+ expect(radios.size).to eq 1
200
+ expect(radios.first.value).to eq 'absolutely'
201
+ end
217
202
 
218
- describe '#selected' do
219
- it "should raise UnknownObjectException if the radio set doesn't exist" do
220
- expect { browser.radio_set(name: 'no_such_name').selected }.to raise_unknown_object_exception
221
- end
203
+ it 'returns empty collection if specified radio does not exist' do
204
+ radios = browser.radio_set(id: 'new_user_newsletter_yes').radios(id: 'new_user_newsletter_not_there')
205
+ expect(radios).to be_empty
206
+ end
222
207
 
223
- it 'gets the currently selected radio' do
224
- expect(browser.radio_set(id: 'new_user_newsletter_no').selected.text).to eq 'Yes'
225
- expect(browser.radio_set(id: 'new_user_newsletter_no').selected.value).to eq 'yes'
226
- end
227
- end
208
+ it 'raises empty collection if it specifies the wrong name' do
209
+ radio_set = browser.radio_set(id: 'new_user_newsletter_yes')
210
+ expect { radio_set.radios(name: '') }.to raise_unknown_object_exception
211
+ end
228
212
 
229
- describe '#include?' do
230
- it 'returns true if the given radio exists by text' do
231
- expect(browser.radio_set(id: 'new_user_newsletter_no')).to include('Yes')
213
+ it 'returns the radio button at the specified index' do
214
+ radio_set = browser.radio_set(id: 'new_user_newsletter_yes')
215
+ expect(radio_set[1]).to be_a Watir::Radio
216
+ end
232
217
  end
233
218
 
234
- it "returns false if the given option doesn't exist" do
235
- expect(browser.radio_set(id: 'new_user_newsletter_no')).to_not include('Mother')
236
- end
237
- end
219
+ describe '#selected' do
220
+ it "raises UnknownObjectException if the radio set doesn't exist" do
221
+ expect { browser.radio_set(name: 'no_such_name').selected }.to raise_unknown_object_exception
222
+ end
238
223
 
239
- describe '#selected?' do
240
- it 'returns true if the given option is selected by text' do
241
- browser.radio_set(id: 'new_user_newsletter_yes').select('No')
242
- expect(browser.radio_set(id: 'new_user_newsletter_yes')).to be_selected('No')
224
+ it 'gets the currently selected radio' do
225
+ expect(browser.radio_set(id: 'new_user_newsletter_no').selected.text).to eq 'Yes'
226
+ expect(browser.radio_set(id: 'new_user_newsletter_no').selected.value).to eq 'yes'
227
+ end
243
228
  end
244
229
 
245
- it 'returns false if the given option is not selected by text' do
246
- expect(browser.radio_set(id: 'new_user_newsletter_yes')).to_not be_selected('Probably')
247
- end
230
+ describe '#include?' do
231
+ it 'returns true if the given radio exists by text' do
232
+ expect(browser.radio_set(id: 'new_user_newsletter_no')).to include('Yes')
233
+ end
248
234
 
249
- it "raises UnknownObjectException if the radio button doesn't exist" do
250
- expect { browser.radio_set(id: 'new_user_newsletter_yes').selected?('missing_option') }
251
- .to raise_unknown_object_exception
235
+ it "returns false if the given option doesn't exist" do
236
+ expect(browser.radio_set(id: 'new_user_newsletter_no')).not_to include('Mother')
237
+ end
252
238
  end
253
- end
254
239
 
255
- describe '#select' do
256
- context 'when interacting with radios' do
257
- it 'selects radio text by String' do
258
- browser.radio_set(id: 'new_user_newsletter_yes').select('Probably')
259
- expect(browser.radio_set(id: 'new_user_newsletter_yes').selected.text).to eq 'Probably'
240
+ describe '#selected?' do
241
+ it 'returns true if the given option is selected by text' do
242
+ browser.radio_set(id: 'new_user_newsletter_yes').select('No')
243
+ expect(browser.radio_set(id: 'new_user_newsletter_yes')).to be_selected('No')
260
244
  end
261
245
 
262
- it 'selects radio text by Regexp' do
263
- browser.radio_set(id: 'new_user_newsletter_yes').select(/Prob/)
264
- expect(browser.radio_set(id: 'new_user_newsletter_yes').selected.text).to eq 'Probably'
246
+ it 'returns false if the given option is not selected by text' do
247
+ expect(browser.radio_set(id: 'new_user_newsletter_yes')).not_to be_selected('Probably')
265
248
  end
266
249
 
267
- it 'selects the radio text when given an Xpath' do
268
- browser.radio_set(xpath: "//input[@id='new_user_newsletter_no']").select('Probably')
269
- expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_no']").selected.text).to eq 'Probably'
250
+ it "raises UnknownObjectException if the radio button doesn't exist" do
251
+ expect { browser.radio_set(id: 'new_user_newsletter_yes').selected?('missing_option') }
252
+ .to raise_unknown_object_exception
270
253
  end
254
+ end
271
255
 
272
- it 'selects radio value by string' do
273
- browser.radio_set(id: 'new_user_newsletter_yes').select('no')
274
- expect(browser.radio_set(id: 'new_user_newsletter_yes').selected.text).to eq 'No'
256
+ describe '#select' do
257
+ context 'when interacting with radios' do
258
+ it 'selects radio text by String' do
259
+ browser.radio_set(id: 'new_user_newsletter_yes').select('Probably')
260
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').selected.text).to eq 'Probably'
261
+ end
262
+
263
+ it 'selects radio text by Regexp' do
264
+ browser.radio_set(id: 'new_user_newsletter_yes').select(/Prob/)
265
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').selected.text).to eq 'Probably'
266
+ end
267
+
268
+ it 'selects the radio text when given an Xpath' do
269
+ browser.radio_set(xpath: "//input[@id='new_user_newsletter_no']").select('Probably')
270
+ expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_no']").selected.text).to eq 'Probably'
271
+ end
272
+
273
+ it 'selects radio value by string' do
274
+ browser.radio_set(id: 'new_user_newsletter_yes').select('no')
275
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').selected.text).to eq 'No'
276
+ end
277
+
278
+ it 'selects radio value by regexp' do
279
+ browser.radio_set(id: 'new_user_newsletter_yes').select(/nah/)
280
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').selected.text).to eq 'Probably'
281
+ end
275
282
  end
276
283
 
277
- it 'selects radio value by regexp' do
278
- browser.radio_set(id: 'new_user_newsletter_yes').select(/nah/)
279
- expect(browser.radio_set(id: 'new_user_newsletter_yes').selected.text).to eq 'Probably'
284
+ it 'returns the value selected' do
285
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').select('no')).to eq 'no'
280
286
  end
281
- end
282
-
283
- it 'returns the value selected' do
284
- expect(browser.radio_set(id: 'new_user_newsletter_yes').select('no')).to eq 'no'
285
- end
286
287
 
287
- it 'fires onchange event when selecting a radio' do
288
- browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'certainly').set
289
- expect(messages).to eq ['changed: new_user_newsletter']
288
+ it 'fires onchange event when selecting a radio' do
289
+ browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'certainly').set
290
+ expect(messages).to eq ['changed: new_user_newsletter']
290
291
 
291
- browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'certainly').set
292
- expect(messages).to eq ['changed: new_user_newsletter'] # no event fired here - didn't change
292
+ browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'certainly').set
293
+ expect(messages).to eq ['changed: new_user_newsletter'] # no event fired here - didn't change
293
294
 
294
- browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'yes').set
295
- browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'certainly').set
296
- list = ['changed: new_user_newsletter', 'clicked: new_user_newsletter_yes', 'changed: new_user_newsletter']
297
- expect(messages).to eq list
298
- end
295
+ browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'yes').set
296
+ browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'certainly').set
297
+ list = ['changed: new_user_newsletter', 'clicked: new_user_newsletter_yes', 'changed: new_user_newsletter']
298
+ expect(messages).to eq list
299
+ end
299
300
 
300
- it "doesn't fire onchange event when selecting an already selected radio" do
301
- browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'no').set
301
+ it "doesn't fire onchange event when selecting an already selected radio" do
302
+ browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'no').set
302
303
 
303
- browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'no').set
304
- expect(messages.size).to eq 1
304
+ browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'no').set
305
+ expect(messages.size).to eq 1
305
306
 
306
- browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'no').set
307
- expect(messages.size).to eq 1
307
+ browser.radio_set(id: 'new_user_newsletter_yes').radio(value: 'no').set
308
+ expect(messages.size).to eq 1
309
+ end
308
310
  end
309
- end
310
311
 
311
- describe '#eql?' do
312
- it 'returns true when located by any radio button' do
313
- rs = browser.radio_set(id: 'new_user_newsletter_yes')
314
- expect(browser.radio_set(id: /new_user_newsletter_no/)).to eql rs
315
- expect(browser.radio_set(name: 'new_user_newsletter', index: 2)).to eql rs
316
- expect(browser.radio_set(name: /new_user_newsletter/)).to eql rs
317
- expect(browser.radio_set(value: 'yes')).to eql rs
318
- expect(browser.radio_set(value: /yes/)).to eql rs
319
- expect(browser.radio_set(class: 'huge')).to eql rs
320
- expect(browser.radio_set(class: /huge/)).to eql rs
321
- expect(browser.radio_set(index: 0)).to eql rs
322
- expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_probably']")).to eql rs
312
+ describe '#eql?' do
313
+ it 'returns true when located by any radio button' do
314
+ rs = browser.radio_set(id: 'new_user_newsletter_yes')
315
+ expect(browser.radio_set(id: /new_user_newsletter_no/)).to eql rs
316
+ expect(browser.radio_set(name: 'new_user_newsletter', index: 2)).to eql rs
317
+ expect(browser.radio_set(name: /new_user_newsletter/)).to eql rs
318
+ expect(browser.radio_set(value: 'yes')).to eql rs
319
+ expect(browser.radio_set(value: /yes/)).to eql rs
320
+ expect(browser.radio_set(class: 'huge')).to eql rs
321
+ expect(browser.radio_set(class: /huge/)).to eql rs
322
+ expect(browser.radio_set(index: 0)).to eql rs
323
+ expect(browser.radio_set(xpath: "//input[@id='new_user_newsletter_probably']")).to eql rs
324
+ end
323
325
  end
324
- end
325
326
 
326
- it 'returns the text of the selected radio' do
327
- expect(browser.radio_set(id: 'new_user_newsletter_yes').select('No')).to eq 'No'
328
- end
327
+ it 'returns the text of the selected radio' do
328
+ expect(browser.radio_set(id: 'new_user_newsletter_yes').select('No')).to eq 'No'
329
+ end
329
330
 
330
- it "raises UnknownObjectException if the radio doesn't exist" do
331
- expect { browser.radio_set(id: 'new_user_newsletter_yes').select('missing_option') }
332
- .to raise_unknown_object_exception
333
- expect { browser.radio_set(id: 'new_user_newsletter_yes').select(/missing_option/) }
334
- .to raise_unknown_object_exception
335
- end
331
+ it "raises UnknownObjectException if the radio doesn't exist" do
332
+ expect { browser.radio_set(id: 'new_user_newsletter_yes').select('missing_option') }
333
+ .to raise_unknown_object_exception
334
+ expect { browser.radio_set(id: 'new_user_newsletter_yes').select(/missing_option/) }
335
+ .to raise_unknown_object_exception
336
+ end
336
337
 
337
- it 'raises ObjectDisabledException if the option is disabled' do
338
- expect { browser.radio_set(id: 'new_user_newsletter_none').select('None') }.to raise_object_disabled_exception
339
- end
338
+ it 'raises ObjectDisabledException if the option is disabled' do
339
+ expect { browser.radio_set(id: 'new_user_newsletter_none').select('None') }.to raise_object_disabled_exception
340
+ end
340
341
 
341
- it 'raises a TypeError if argument is not a String, Regexp or Numeric' do
342
- expect { browser.radio_set(id: 'new_user_newsletter_yes').select([]) }.to raise_error(TypeError)
342
+ it 'raises a TypeError if argument is not a String, Regexp or Numeric' do
343
+ expect { browser.radio_set(id: 'new_user_newsletter_yes').select([]) }.to raise_error(TypeError)
344
+ end
343
345
  end
344
346
  end