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
@@ -6,235 +6,239 @@ require 'watirspec_helper'
6
6
  # TODO: fix duplication with frame_spec
7
7
  #
8
8
 
9
- describe 'IFrame' do
10
- before :each do
11
- browser.goto(WatirSpec.url_for('iframes.html'))
12
- end
13
-
14
- it 'handles crossframe javascript' do
15
- browser.goto WatirSpec.url_for('iframes.html')
16
-
17
- expect(browser.iframe(id: 'iframe_1').text_field(name: 'senderElement').value).to eq 'send_this_value'
18
- expect(browser.iframe(id: 'iframe_2').text_field(name: 'recieverElement').value).to eq 'old_value'
19
- browser.iframe(id: 'iframe_1').button(id: 'send').click
20
- expect(browser.iframe(id: 'iframe_2').text_field(name: 'recieverElement').value).to eq 'send_this_value'
21
- end
22
-
23
- it 'locates an element defined by Selenium Element' do
24
- iframe = browser.iframe(id: 'iframe_1').locate
25
- se_element = iframe.instance_variable_get(:@element)
26
- iframe2 = browser.element(element: se_element).to_subtype
27
- expect(iframe2).to eq iframe
28
- end
29
-
30
- describe '#wd' do
31
- it 'returns a Watir::FramedDriver instance' do
32
- iframe = browser.iframe(id: 'iframe_1')
33
- expect(iframe.wd).to be_a(Watir::FramedDriver)
9
+ module Watir
10
+ describe IFrame do
11
+ before do
12
+ browser.goto(WatirSpec.url_for('iframes.html'))
34
13
  end
35
14
 
36
- it 'properly delegates driver commands' do
37
- iframe = browser.iframe(id: 'iframe_1')
38
- expect(iframe.wd.title).to eq 'Iframes'
39
- end
15
+ it 'handles crossframe javascript' do
16
+ browser.goto WatirSpec.url_for('iframes.html')
40
17
 
41
- it 'properly delegates element commands' do
42
- iframe = browser.iframe(id: 'iframe_1')
43
- expect(iframe.wd.attribute('id')).to eq 'iframe_1'
18
+ expect(browser.iframe(id: 'iframe_1').text_field(name: 'senderElement').value).to eq 'send_this_value'
19
+ expect(browser.iframe(id: 'iframe_2').text_field(name: 'recieverElement').value).to eq 'old_value'
20
+ browser.iframe(id: 'iframe_1').button(id: 'send').click
21
+ expect(browser.iframe(id: 'iframe_2').text_field(name: 'recieverElement').value).to eq 'send_this_value'
22
+ end
23
+
24
+ it 'locates an element defined by Selenium Element' do
25
+ iframe = browser.iframe(id: 'iframe_1').locate
26
+ se_element = iframe.instance_variable_get(:@element)
27
+ iframe2 = browser.element(element: se_element).to_subtype
28
+ expect(iframe2).to eq iframe
29
+ end
30
+
31
+ describe '#wd' do
32
+ it 'returns a Watir::FramedDriver instance' do
33
+ iframe = browser.iframe(id: 'iframe_1')
34
+ expect(iframe.wd).to be_a(Watir::FramedDriver)
35
+ end
36
+
37
+ it 'properly delegates driver commands' do
38
+ iframe = browser.iframe(id: 'iframe_1')
39
+ expect(iframe.wd.title).to eq 'Iframes'
40
+ end
41
+
42
+ it 'properly delegates element commands' do
43
+ iframe = browser.iframe(id: 'iframe_1')
44
+ expect(iframe.wd.attribute('id')).to eq 'iframe_1'
45
+ end
46
+ end
47
+
48
+ describe '#exist?' do
49
+ it 'returns true if the iframe exists' do
50
+ expect(browser.iframe(id: 'iframe_1')).to exist
51
+ expect(browser.iframe(name: 'iframe1')).to exist
52
+ expect(browser.iframe(index: 0)).to exist
53
+ expect(browser.iframe(class: 'half')).to exist
54
+ expect(browser.iframe(xpath: "//iframe[@id='iframe_1']")).to exist
55
+ expect(browser.iframe(src: 'iframe_1.html')).to exist
56
+ expect(browser.iframe(id: /iframe/)).to exist
57
+ expect(browser.iframe(name: /iframe/)).to exist
58
+ expect(browser.iframe(src: /iframe_1/)).to exist
59
+ expect(browser.iframe(class: /half/)).to exist
60
+ end
61
+
62
+ it 'returns the first iframe if given no args' do
63
+ expect(browser.iframe).to exist
64
+ end
65
+
66
+ it "returns false if the iframe doesn't exist" do
67
+ expect(browser.iframe(id: 'no_such_id')).not_to exist
68
+ expect(browser.iframe(name: 'no_such_text')).not_to exist
69
+ expect(browser.iframe(index: 1337)).not_to exist
70
+ expect(browser.iframe(src: 'no_such_src')).not_to exist
71
+ expect(browser.iframe(class: 'no_such_class')).not_to exist
72
+ expect(browser.iframe(id: /no_such_id/)).not_to exist
73
+ expect(browser.iframe(name: /no_such_text/)).not_to exist
74
+ expect(browser.iframe(src: /no_such_src/)).not_to exist
75
+ expect(browser.iframe(class: /no_such_class/)).not_to exist
76
+ expect(browser.iframe(xpath: "//iframe[@id='no_such_id']")).not_to exist
77
+ end
78
+
79
+ it 'returns true if an element in an iframe does exist' do
80
+ expect(browser.iframe.element(css: '#senderElement')).to exist
81
+ expect(browser.iframe.element(id: 'senderElement')).to exist
82
+ end
83
+
84
+ it 'returns true for multiple elements that exist in an iframe with a parent selector' do
85
+ expect(browser.div(class: 'wrapper').iframe.element(id: 'first_grandson')).to exist
86
+ expect(browser.div(class: 'wrapper').iframe.element(id: 'second_grandson')).to exist
87
+ end
88
+
89
+ it 'returns false if an element in an iframe does not exist' do
90
+ expect(browser.iframe.element(css: '#no_such_id')).not_to exist
91
+ expect(browser.iframe.element(id: 'no_such_id')).not_to exist
92
+ end
93
+
94
+ it 'returns true if an element outside an iframe exists after checking for one inside that does exist' do
95
+ existing_element = browser.element(css: '#iframe_1')
96
+ expect(existing_element).to exist
97
+ expect(browser.iframe.element(css: '#senderElement')).to exist
98
+ expect(existing_element).to exist
99
+ end
100
+
101
+ it 'returns true if an element outside an iframe exists after checking for one inside that does not exist' do
102
+ existing_element = browser.element(css: '#iframe_1')
103
+ expect(existing_element).to exist
104
+ expect(browser.iframe.element(css: '#no_such_id')).not_to exist
105
+ expect(existing_element).to exist
106
+ end
107
+
108
+ it 'returns true if an element exists in a frame generated in a collection' do
109
+ nested_element = browser.body.iframes.first.div
110
+ expect(nested_element).to exist
111
+ end
112
+
113
+ it 'returns false for sub-element of a non-existing iframe' do
114
+ expect(browser.iframe(id: 'no_such_id').element).not_to exist
115
+ end
116
+
117
+ it 'handles nested iframes' do
118
+ browser.goto(WatirSpec.url_for('nested_iframes.html'))
119
+ browser.iframe(id: 'two').iframe(id: 'three').link(id: 'four').click
120
+
121
+ expect {
122
+ browser.wait_until { |b| b.title == 'definition_lists' }
123
+ }.not_to raise_exception
124
+ end
125
+
126
+ it "raises TypeError when 'what' argument is invalid" do
127
+ expect { browser.iframe(id: 3.14).exists? }.to raise_error(TypeError)
128
+ end
129
+ end
130
+
131
+ it 'handles all locators for element which do not exist' do
132
+ expect(browser.iframe(index: 0).div(id: 'invalid')).not_to exist
133
+ end
134
+
135
+ describe '#present?' do
136
+ it 'returns true if the iframe present' do
137
+ expect(browser.iframe(id: 'iframe_1')).to be_present
138
+ end
139
+
140
+ it 'returns false if the iframe is not present' do
141
+ expect(browser.iframe(id: 'no_such_id')).not_to be_present
142
+ end
143
+ end
144
+
145
+ it 'switches between iframe and parent when needed' do
146
+ expect {
147
+ browser.iframe(id: 'iframe_1').elements.each do |element|
148
+ element.text
149
+ browser.h1.text
150
+ end
151
+ }.not_to raise_exception
44
152
  end
45
- end
46
153
 
47
- describe '#exist?' do
48
- it 'returns true if the iframe exists' do
49
- expect(browser.iframe(id: 'iframe_1')).to exist
50
- expect(browser.iframe(name: 'iframe1')).to exist
51
- expect(browser.iframe(index: 0)).to exist
52
- expect(browser.iframe(class: 'half')).to exist
53
- expect(browser.iframe(xpath: "//iframe[@id='iframe_1']")).to exist
54
- expect(browser.iframe(src: 'iframe_1.html')).to exist
55
- expect(browser.iframe(id: /iframe/)).to exist
56
- expect(browser.iframe(name: /iframe/)).to exist
57
- expect(browser.iframe(src: /iframe_1/)).to exist
58
- expect(browser.iframe(class: /half/)).to exist
154
+ it 'switches when the frame is created by subtype' do
155
+ subtype = browser.iframe.to_subtype
156
+ expect { subtype.element.locate }.not_to raise_exception
59
157
  end
60
158
 
61
- it 'returns the first iframe if given no args' do
62
- expect(browser.iframe).to exist
63
- end
159
+ it 'switches back to top level browsing context' do
160
+ # Point driver to browsing context of first iframe
161
+ browser.iframes.first.ps.locate
64
162
 
65
- it "returns false if the iframe doesn't exist" do
66
- expect(browser.iframe(id: 'no_such_id')).to_not exist
67
- expect(browser.iframe(name: 'no_such_text')).to_not exist
68
- expect(browser.iframe(index: 1337)).to_not exist
69
- expect(browser.iframe(src: 'no_such_src')).to_not exist
70
- expect(browser.iframe(class: 'no_such_class')).to_not exist
71
- expect(browser.iframe(id: /no_such_id/)).to_not exist
72
- expect(browser.iframe(name: /no_such_text/)).to_not exist
73
- expect(browser.iframe(src: /no_such_src/)).to_not exist
74
- expect(browser.iframe(class: /no_such_class/)).to_not exist
75
- expect(browser.iframe(xpath: "//iframe[@id='no_such_id']")).to_not exist
163
+ expect(browser.h1s.first.text).to be == 'Iframes'
76
164
  end
77
165
 
78
- it 'returns true if an element in an iframe does exist' do
79
- expect(browser.iframe.element(css: '#senderElement')).to exist
80
- expect(browser.iframe.element(id: 'senderElement')).to exist
166
+ it 'raises UnknownFrameException when accessing elements inside non-existing iframe' do
167
+ expect { browser.iframe(name: 'no_such_name').p(index: 0).id }.to raise_unknown_frame_exception
81
168
  end
82
169
 
83
- it 'returns true for multiple elements that exist in an iframe with a parent selector' do
84
- expect(browser.div(class: 'wrapper').iframe.element(id: 'first_grandson')).to exist
85
- expect(browser.div(class: 'wrapper').iframe.element(id: 'second_grandson')).to exist
170
+ it 'raises UnknownFrameException when accessing a non-existing iframe' do
171
+ expect { browser.iframe(name: 'no_such_name').id }.to raise_unknown_frame_exception
86
172
  end
87
173
 
88
- it 'returns false if an element in an iframe does not exist' do
89
- expect(browser.iframe.element(css: '#no_such_id')).to_not exist
90
- expect(browser.iframe.element(id: 'no_such_id')).to_not exist
174
+ it 'raises UnknownFrameException when accessing a non-existing subframe' do
175
+ expect { browser.iframe(name: 'iframe1').iframe(name: 'no_such_name').id }.to raise_unknown_frame_exception
91
176
  end
92
177
 
93
- it 'returns true if an element outside an iframe exists after checking for one inside that does exist' do
94
- existing_element = browser.element(css: '#iframe_1')
95
- expect(existing_element).to exist
96
- expect(browser.iframe.element(css: '#senderElement')).to exist
97
- expect(existing_element).to exist
178
+ it 'raises UnknownObjectException when accessing a non-existing element inside an existing iframe' do
179
+ expect { browser.iframe(index: 0).p(index: 1337).id }.to raise_unknown_object_exception
98
180
  end
99
181
 
100
- it 'returns true if an element outside an iframe exists after checking for one inside that does not exist' do
101
- existing_element = browser.element(css: '#iframe_1')
102
- expect(existing_element).to exist
103
- expect(browser.iframe.element(css: '#no_such_id')).to_not exist
104
- expect(existing_element).to exist
182
+ it "raises NoMethodError when trying to access attributes it doesn't have" do
183
+ expect { browser.iframe(index: 0).foo }.to raise_error(NoMethodError)
105
184
  end
106
185
 
107
- it 'returns true if an element exists in a frame generated in a collection' do
108
- nested_element = browser.body.iframes.first.div
109
- expect(nested_element).to exist
186
+ it 'is able to set a field' do
187
+ browser.iframe(index: 0).text_field(name: 'senderElement').set('new value')
188
+ expect(browser.iframe(index: 0).text_field(name: 'senderElement').value).to eq 'new value'
110
189
  end
111
190
 
112
- it 'returns false for sub-element of a non-existing iframe' do
113
- expect(browser.iframe(id: 'no_such_id').element).to_not exist
191
+ it 'will suggest looking in an iframe when iframes exist' do
192
+ msg = 'Maybe look in an iframe?'
193
+ expect { browser.text_field(name: 'senderElement').set('no') }.to raise_unknown_object_exception(msg)
114
194
  end
115
195
 
116
- it 'handles nested iframes' do
196
+ it 'will suggest looking in a nested iframe when iframes exist' do
117
197
  browser.goto(WatirSpec.url_for('nested_iframes.html'))
118
- browser.iframe(id: 'two').iframe(id: 'three').link(id: 'four').click
119
-
120
- expect {
121
- browser.wait_until { |b| b.title == 'definition_lists' }
122
- }.not_to raise_exception
198
+ top = browser.iframe(id: 'two')
199
+ expect { top.link(id: 'four').click }.to raise_unknown_object_exception('Maybe look in an iframe?')
123
200
  end
124
201
 
125
- it "raises TypeError when 'what' argument is invalid" do
126
- expect { browser.iframe(id: 3.14).exists? }.to raise_error(TypeError)
202
+ describe '#execute_script' do
203
+ it 'executes the given javascript in the specified frame',
204
+ except: {browser: :safari, reason: 'Safari does not strip text'} do
205
+ frame = browser.iframe(index: 0)
206
+ expect(frame.div(id: 'set_by_js').text).to eq ''
207
+ inner_html = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
208
+ script = "document.getElementById('set_by_js').innerHTML = '#{inner_html}'"
209
+ frame.execute_script script
210
+ text = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
211
+ expect(frame.div(id: 'set_by_js').text).to eq text
212
+ end
127
213
  end
128
- end
129
214
 
130
- it 'handles all locators for element which do not exist' do
131
- expect(browser.iframe(index: 0).div(id: 'invalid')).to_not exist
132
- end
133
-
134
- describe '#present?' do
135
- it 'returns true if the iframe present' do
136
- expect(browser.iframe(id: 'iframe_1')).to be_present
215
+ describe '#html' do
216
+ it 'returns the full HTML source of the iframe' do
217
+ browser.goto WatirSpec.url_for('iframes.html')
218
+ expect(browser.iframe.html.downcase).to include('<title>iframe 1</title>')
219
+ end
137
220
  end
138
221
 
139
- it 'returns false if the iframe is not present' do
140
- expect(browser.iframe(id: 'no_such_id')).not_to be_present
141
- end
142
- end
143
-
144
- it 'switches between iframe and parent when needed' do
145
- browser.iframe(id: 'iframe_1').elements.each do |element|
146
- element.text
147
- browser.h1.text
148
- end
149
- end
150
-
151
- it 'switches when the frame is created by subtype' do
152
- subtype = browser.iframe.to_subtype
153
- expect { subtype.element.locate }.to_not raise_exception
154
- end
155
-
156
- it 'switches back to top level browsing context' do
157
- # Point driver to browsing context of first iframe
158
- browser.iframes.first.ps.locate
159
-
160
- expect(browser.h1s.first.text).to be == 'Iframes'
161
- end
162
-
163
- it 'raises UnknownFrameException when accessing elements inside non-existing iframe' do
164
- expect { browser.iframe(name: 'no_such_name').p(index: 0).id }.to raise_unknown_frame_exception
165
- end
166
-
167
- it 'raises UnknownFrameException when accessing a non-existing iframe' do
168
- expect { browser.iframe(name: 'no_such_name').id }.to raise_unknown_frame_exception
169
- end
170
-
171
- it 'raises UnknownFrameException when accessing a non-existing subframe' do
172
- expect { browser.iframe(name: 'iframe1').iframe(name: 'no_such_name').id }.to raise_unknown_frame_exception
173
- end
174
-
175
- it 'raises UnknownObjectException when accessing a non-existing element inside an existing iframe' do
176
- expect { browser.iframe(index: 0).p(index: 1337).id }.to raise_unknown_object_exception
177
- end
178
-
179
- it "raises NoMethodError when trying to access attributes it doesn't have" do
180
- expect { browser.iframe(index: 0).foo }.to raise_error(NoMethodError)
181
- end
182
-
183
- it 'is able to set a field' do
184
- browser.iframe(index: 0).text_field(name: 'senderElement').set('new value')
185
- expect(browser.iframe(index: 0).text_field(name: 'senderElement').value).to eq 'new value'
186
- end
187
-
188
- it 'will suggest looking in an iframe when iframes exist' do
189
- msg = 'Maybe look in an iframe?'
190
- expect { browser.text_field(name: 'senderElement').set('no') }.to raise_unknown_object_exception(msg)
191
- end
192
-
193
- it 'will suggest looking in a nested iframe when iframes exist' do
194
- browser.goto(WatirSpec.url_for('nested_iframes.html'))
195
- top = browser.iframe(id: 'two')
196
- expect { top.link(id: 'four').click }.to raise_unknown_object_exception('Maybe look in an iframe?')
197
- end
198
-
199
- describe '#execute_script' do
200
- it 'executes the given javascript in the specified frame',
201
- except: {browser: :safari, reason: 'Safari does not strip text'} do
202
- frame = browser.iframe(index: 0)
203
- expect(frame.div(id: 'set_by_js').text).to eq ''
204
- inner_html = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
205
- script = "document.getElementById('set_by_js').innerHTML = '#{inner_html}'"
206
- frame.execute_script script
207
- text = 'Art consists of limitation. The most beautiful part of every picture is the frame.'
208
- expect(frame.div(id: 'set_by_js').text).to eq text
222
+ describe '#text' do
223
+ it 'returns the text inside the iframe' do
224
+ browser.goto WatirSpec.url_for('iframes.html')
225
+ expect(browser.iframe.text).to include('Frame 1')
226
+ end
209
227
  end
210
228
  end
211
229
 
212
- describe '#html' do
213
- it 'returns the full HTML source of the iframe' do
230
+ describe FramedDriver do
231
+ it 'raises name error if method is not defined on driver or element' do
214
232
  browser.goto WatirSpec.url_for('iframes.html')
215
- expect(browser.iframe.html.downcase).to include('<title>iframe 1</title>')
233
+ expect(browser.iframe(id: 'iframe_1').wd).not_to respond_to :foo
234
+ expect { browser.iframe(id: 'iframe_1').wd.foo }.to raise_exception NoMethodError
216
235
  end
217
- end
218
236
 
219
- describe '#text' do
220
- it 'returns the text inside the iframe' do
237
+ it 'raises exception when attempting to switch to a non-frame element' do
221
238
  browser.goto WatirSpec.url_for('iframes.html')
222
- expect(browser.iframe.text).to include('Frame 1')
239
+ element = browser.h1.wd
240
+ fd = described_class.new(element, browser)
241
+ expect { fd.switch! }.to raise_exception Watir::Exception::UnknownFrameException
223
242
  end
224
243
  end
225
244
  end
226
-
227
- describe 'FramedDriver' do
228
- it 'raises name error if method is not defined on driver or element' do
229
- browser.goto WatirSpec.url_for('iframes.html')
230
- expect(browser.iframe(id: 'iframe_1').wd).not_to respond_to :foo
231
- expect { browser.iframe(id: 'iframe_1').wd.foo }.to raise_exception NoMethodError
232
- end
233
-
234
- it 'raises exception when attempting to switch to a non-frame element' do
235
- browser.goto WatirSpec.url_for('iframes.html')
236
- element = browser.h1.wd
237
- fd = Watir::FramedDriver.new(element, browser)
238
- expect { fd.switch! }.to raise_exception Watir::Exception::UnknownFrameException
239
- end
240
- end
@@ -2,46 +2,48 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'IFrames' do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('iframes.html'))
8
- end
5
+ module Watir
6
+ describe IFrameCollection do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('iframes.html'))
9
+ end
9
10
 
10
- describe 'with selectors' do
11
- it 'returns the matching elements' do
12
- expect(browser.iframes(id: 'iframe_2').to_a).to eq [browser.iframe(id: 'iframe_2')]
11
+ describe 'with selectors' do
12
+ it 'returns the matching elements' do
13
+ expect(browser.iframes(id: 'iframe_2').to_a).to eq [browser.iframe(id: 'iframe_2')]
14
+ end
13
15
  end
14
- end
15
16
 
16
- describe 'eql?' do
17
- it 'matches equality of iframe with that from a collection' do
18
- expect(browser.iframes.last).to eq browser.iframe(id: 'iframe_3')
17
+ describe 'eql?' do
18
+ it 'matches equality of iframe with that from a collection' do
19
+ expect(browser.iframes.last).to eq browser.iframe(id: 'iframe_3')
20
+ end
19
21
  end
20
- end
21
22
 
22
- describe '#length' do
23
- it 'returns the correct number of iframes' do
24
- expect(browser.iframes.length).to eq 3
23
+ describe '#length' do
24
+ it 'returns the correct number of iframes' do
25
+ expect(browser.iframes.length).to eq 3
26
+ end
25
27
  end
26
- end
27
28
 
28
- describe '#[]' do
29
- it 'returns the iframe at the given index' do
30
- expect(browser.iframes[0].id).to eq 'iframe_1'
29
+ describe '#[]' do
30
+ it 'returns the iframe at the given index' do
31
+ expect(browser.iframes[0].id).to eq 'iframe_1'
32
+ end
31
33
  end
32
- end
33
34
 
34
- describe '#each' do
35
- it 'iterates through frames correctly' do
36
- count = 0
35
+ describe '#each' do
36
+ it 'iterates through frames correctly' do
37
+ count = 0
37
38
 
38
- browser.iframes.each_with_index do |f, index|
39
- expect(f.name).to eq browser.iframe(index: index).name
40
- expect(f.id).to eq browser.iframe(index: index).id
41
- count += 1
42
- end
39
+ browser.iframes.each_with_index do |f, index|
40
+ expect(f.name).to eq browser.iframe(index: index).name
41
+ expect(f.id).to eq browser.iframe(index: index).id
42
+ count += 1
43
+ end
43
44
 
44
- expect(count).to be > 0
45
+ expect(count).to be > 0
46
+ end
45
47
  end
46
48
  end
47
49
  end