watir 7.2.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/chrome.yml +9 -1
  3. data/.github/workflows/edge.yml +10 -2
  4. data/.github/workflows/firefox.yml +10 -2
  5. data/.github/workflows/ie.yml +1 -1
  6. data/.github/workflows/safari.yml +1 -1
  7. data/.github/workflows/unit.yml +3 -3
  8. data/.rubocop.yml +36 -14
  9. data/.rubocop_todo.yml +8 -1
  10. data/CHANGES.md +17 -1
  11. data/LICENSE +2 -2
  12. data/lib/watir/capabilities.rb +2 -12
  13. data/lib/watir/cookies.rb +7 -2
  14. data/lib/watir/elements/date_field.rb +2 -2
  15. data/lib/watir/elements/date_time_field.rb +2 -2
  16. data/lib/watir/elements/select.rb +3 -3
  17. data/lib/watir/locators/anchor/selector_builder.rb +3 -0
  18. data/lib/watir/locators/element/matcher.rb +2 -1
  19. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
  20. data/lib/watir/locators/element/selector_builder.rb +1 -1
  21. data/lib/watir/locators/text_field/matcher.rb +1 -5
  22. data/lib/watir/version.rb +1 -1
  23. data/lib/watir.rb +1 -0
  24. data/lib/watirspec/implementation.rb +1 -1
  25. data/lib/watirspec.rb +1 -1
  26. data/spec/locator_spec_helper.rb +3 -15
  27. data/spec/unit/capabilities_spec.rb +552 -561
  28. data/spec/unit/element_locator_spec.rb +89 -78
  29. data/spec/unit/match_elements/button_spec.rb +69 -62
  30. data/spec/unit/match_elements/element_spec.rb +303 -309
  31. data/spec/unit/match_elements/text_field_spec.rb +76 -73
  32. data/spec/unit/selector_builder/anchor_spec.rb +39 -33
  33. data/spec/unit/selector_builder/button_spec.rb +209 -202
  34. data/spec/unit/selector_builder/cell_spec.rb +48 -42
  35. data/spec/unit/selector_builder/element_spec.rb +632 -627
  36. data/spec/unit/selector_builder/row_spec.rb +119 -113
  37. data/spec/unit/selector_builder/text_field_spec.rb +195 -188
  38. data/spec/unit/selector_builder/textarea_spec.rb +22 -14
  39. data/spec/unit/wait_spec.rb +85 -81
  40. data/spec/watirspec/adjacent_spec.rb +249 -247
  41. data/spec/watirspec/after_hooks_spec.rb +161 -159
  42. data/spec/watirspec/alert_spec.rb +61 -58
  43. data/spec/watirspec/browser_spec.rb +411 -409
  44. data/spec/watirspec/capabilities_spec.rb +99 -112
  45. data/spec/watirspec/cookies_spec.rb +144 -115
  46. data/spec/watirspec/drag_and_drop_spec.rb +26 -24
  47. data/spec/watirspec/element_hidden_spec.rb +66 -60
  48. data/spec/watirspec/elements/area_spec.rb +49 -47
  49. data/spec/watirspec/elements/areas_spec.rb +27 -25
  50. data/spec/watirspec/elements/button_spec.rb +253 -251
  51. data/spec/watirspec/elements/buttons_spec.rb +36 -34
  52. data/spec/watirspec/elements/checkbox_spec.rb +48 -36
  53. data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
  54. data/spec/watirspec/elements/collections_spec.rb +126 -119
  55. data/spec/watirspec/elements/date_field_spec.rb +202 -183
  56. data/spec/watirspec/elements/date_fields_spec.rb +29 -27
  57. data/spec/watirspec/elements/date_time_field_spec.rb +216 -195
  58. data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
  59. data/spec/watirspec/elements/dd_spec.rb +87 -85
  60. data/spec/watirspec/elements/dds_spec.rb +27 -25
  61. data/spec/watirspec/elements/del_spec.rb +106 -104
  62. data/spec/watirspec/elements/dels_spec.rb +26 -24
  63. data/spec/watirspec/elements/div_spec.rb +225 -221
  64. data/spec/watirspec/elements/divs_spec.rb +37 -35
  65. data/spec/watirspec/elements/dl_spec.rb +110 -108
  66. data/spec/watirspec/elements/dls_spec.rb +28 -26
  67. data/spec/watirspec/elements/dt_spec.rb +86 -84
  68. data/spec/watirspec/elements/dts_spec.rb +27 -25
  69. data/spec/watirspec/elements/element_spec.rb +794 -775
  70. data/spec/watirspec/elements/elements_spec.rb +40 -38
  71. data/spec/watirspec/elements/em_spec.rb +62 -60
  72. data/spec/watirspec/elements/ems_spec.rb +28 -26
  73. data/spec/watirspec/elements/filefield_spec.rb +116 -114
  74. data/spec/watirspec/elements/filefields_spec.rb +28 -26
  75. data/spec/watirspec/elements/font_spec.rb +20 -18
  76. data/spec/watirspec/elements/form_spec.rb +51 -49
  77. data/spec/watirspec/elements/forms_spec.rb +29 -27
  78. data/spec/watirspec/elements/frame_spec.rb +89 -87
  79. data/spec/watirspec/elements/frames_spec.rb +27 -25
  80. data/spec/watirspec/elements/hidden_spec.rb +81 -79
  81. data/spec/watirspec/elements/hiddens_spec.rb +28 -26
  82. data/spec/watirspec/elements/hn_spec.rb +59 -57
  83. data/spec/watirspec/elements/hns_spec.rb +26 -24
  84. data/spec/watirspec/elements/iframe_spec.rb +195 -191
  85. data/spec/watirspec/elements/iframes_spec.rb +31 -29
  86. data/spec/watirspec/elements/image_spec.rb +148 -146
  87. data/spec/watirspec/elements/images_spec.rb +26 -24
  88. data/spec/watirspec/elements/input_spec.rb +9 -7
  89. data/spec/watirspec/elements/ins_spec.rb +106 -104
  90. data/spec/watirspec/elements/inses_spec.rb +26 -24
  91. data/spec/watirspec/elements/label_spec.rb +56 -54
  92. data/spec/watirspec/elements/labels_spec.rb +26 -24
  93. data/spec/watirspec/elements/li_spec.rb +76 -74
  94. data/spec/watirspec/elements/link_spec.rb +173 -177
  95. data/spec/watirspec/elements/links_spec.rb +45 -43
  96. data/spec/watirspec/elements/lis_spec.rb +27 -25
  97. data/spec/watirspec/elements/list_spec.rb +44 -42
  98. data/spec/watirspec/elements/map_spec.rb +57 -55
  99. data/spec/watirspec/elements/maps_spec.rb +27 -25
  100. data/spec/watirspec/elements/meta_spec.rb +16 -14
  101. data/spec/watirspec/elements/metas_spec.rb +26 -24
  102. data/spec/watirspec/elements/ol_spec.rb +56 -65
  103. data/spec/watirspec/elements/ols_spec.rb +26 -24
  104. data/spec/watirspec/elements/option_spec.rb +91 -89
  105. data/spec/watirspec/elements/p_spec.rb +81 -79
  106. data/spec/watirspec/elements/pre_spec.rb +77 -75
  107. data/spec/watirspec/elements/pres_spec.rb +26 -24
  108. data/spec/watirspec/elements/ps_spec.rb +26 -24
  109. data/spec/watirspec/elements/radio_spec.rb +251 -249
  110. data/spec/watirspec/elements/radios_spec.rb +28 -26
  111. data/spec/watirspec/elements/select_list_spec.rb +537 -526
  112. data/spec/watirspec/elements/select_lists_spec.rb +32 -30
  113. data/spec/watirspec/elements/span_spec.rb +112 -110
  114. data/spec/watirspec/elements/spans_spec.rb +26 -24
  115. data/spec/watirspec/elements/strong_spec.rb +58 -58
  116. data/spec/watirspec/elements/strongs_spec.rb +28 -26
  117. data/spec/watirspec/elements/table_spec.rb +192 -139
  118. data/spec/watirspec/elements/tables_spec.rb +28 -26
  119. data/spec/watirspec/elements/tbody_spec.rb +74 -72
  120. data/spec/watirspec/elements/tbodys_spec.rb +40 -38
  121. data/spec/watirspec/elements/td_spec.rb +66 -64
  122. data/spec/watirspec/elements/tds_spec.rb +41 -39
  123. data/spec/watirspec/elements/text_field_spec.rb +206 -204
  124. data/spec/watirspec/elements/text_fields_spec.rb +30 -28
  125. data/spec/watirspec/elements/textarea_spec.rb +20 -18
  126. data/spec/watirspec/elements/textareas_spec.rb +18 -16
  127. data/spec/watirspec/elements/tfoot_spec.rb +65 -63
  128. data/spec/watirspec/elements/tfoots_spec.rb +42 -40
  129. data/spec/watirspec/elements/thead_spec.rb +65 -63
  130. data/spec/watirspec/elements/theads_spec.rb +42 -40
  131. data/spec/watirspec/elements/tr_spec.rb +48 -46
  132. data/spec/watirspec/elements/trs_spec.rb +42 -40
  133. data/spec/watirspec/elements/ul_spec.rb +56 -54
  134. data/spec/watirspec/elements/uls_spec.rb +26 -24
  135. data/spec/watirspec/radio_set_spec.rb +269 -267
  136. data/spec/watirspec/screenshot_spec.rb +20 -18
  137. data/spec/watirspec/scroll_spec.rb +152 -148
  138. data/spec/watirspec/shadow_root_spec.rb +88 -83
  139. data/spec/watirspec/support/rspec_matchers.rb +34 -25
  140. data/spec/watirspec/user_editable_spec.rb +200 -198
  141. data/spec/watirspec/wait_spec.rb +289 -295
  142. data/spec/watirspec/window_switching_spec.rb +423 -434
  143. data/spec/watirspec_helper.rb +1 -23
  144. data/watir.gemspec +6 -5
  145. metadata +47 -37
  146. data/spec/watirspec/attributes_spec.rb +0 -18
  147. data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
  148. data/spec/watirspec/special_chars_spec.rb +0 -23
  149. data/support/travis.sh +0 -15
@@ -1,36 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  if defined?(RSpec)
4
- RSpec::Matchers.define :have_deprecated do |deprecation|
5
- match do |actual|
6
- # Suppresses logging output to stdout while ensuring that it is still happening
7
- default_output = Selenium::WebDriver.logger.io
8
- io = StringIO.new
9
- Watir.logger.output = io
4
+ LEVELS = %w[warning info deprecated].freeze
10
5
 
11
- actual.call
6
+ LEVELS.each do |level|
7
+ RSpec::Matchers.define "have_#{level}" do |entry|
8
+ match do |actual|
9
+ # Suppresses logging output to stdout while ensuring that it is still happening
10
+ default_output = Watir.logger.io
11
+ io = StringIO.new
12
+ Watir.logger.output = io
12
13
 
13
- Watir.logger.output = default_output
14
- @deprecations_found = (io.rewind && io.read).scan(/DEPRECATION\] \[:([^\]]*)\]/).flatten.map(&:to_sym)
15
- expect(Array(deprecation).sort).to eq(@deprecations_found.sort)
16
- end
14
+ begin
15
+ actual.call
16
+ rescue StandardError => e
17
+ raise e, 'Can not evaluate output when statement raises an exception'
18
+ ensure
19
+ Watir.logger.output = default_output
20
+ end
17
21
 
18
- failure_message do
19
- but_message = if @deprecations_found.nil? || @deprecations_found.empty?
20
- 'no deprecations were found'
21
- else
22
- "instead these deprecations were found: [#{@deprecations_found.join(', ')}]"
23
- end
24
- "expected :#{deprecation} to have been deprecated, but #{but_message}"
25
- end
22
+ @entries_found = (io.rewind && io.read).scan(/\[:([^\]]*)\]/).flatten.map(&:to_sym)
23
+ expect(Array(entry).sort).to eq(@entries_found.sort)
24
+ end
26
25
 
27
- failure_message_when_negated do
28
- but_message = "it was found among these deprecations: [#{@deprecations_found.join(', ')}]"
29
- "expected :#{deprecation} not to have been deprecated, but #{but_message}"
30
- end
26
+ failure_message do
27
+ but_message = if @entries_found.nil? || @entries_found.empty?
28
+ "no #{entry} entries were reported"
29
+ else
30
+ "instead these entries were found: [#{@entries_found.join(', ')}]"
31
+ end
32
+ "expected :#{entry} to have been logged, but #{but_message}"
33
+ end
31
34
 
32
- def supports_block_expectations?
33
- true
35
+ failure_message_when_negated do
36
+ but_message = "it was found among these entries: [#{@entries_found.join(', ')}]"
37
+ "expected :#{entry} not to have been logged, but #{but_message}"
38
+ end
39
+
40
+ def supports_block_expectations?
41
+ true
42
+ end
34
43
  end
35
44
  end
36
45
 
@@ -2,204 +2,206 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe Watir::UserEditable do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
8
- end
9
-
10
- describe '#append' do
11
- it 'appends the text to the text field', except: {browser: :safari, reason: 'incorrectly clears first'} do
12
- browser.text_field(name: 'new_user_occupation').append(' Append This')
13
- expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer Append This'
14
- end
15
-
16
- it 'appends multi-byte characters', except: {browser: :safari, reason: 'incorrectly clears first'} do
17
- browser.text_field(name: 'new_user_occupation').append(' ijij')
18
- expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer ijij'
19
- end
20
-
21
- it 'raises NotImplementedError if the object is content editable element' do
22
- msg = '#append method is not supported with contenteditable element'
23
- expect { browser.div(id: 'contenteditable').append('bar') }.to raise_exception(NotImplementedError, msg)
24
- end
25
-
26
- it 'raises ObjectReadOnlyException if the object is read only' do
27
- expect { browser.text_field(id: 'new_user_code').append('Append This') }.to raise_object_read_only_exception
28
- end
29
-
30
- it 'raises ObjectDisabledException if the object is disabled' do
31
- expect { browser.text_field(name: 'new_user_species').append('Append This') }.to raise_object_disabled_exception
32
- end
33
-
34
- it "raises UnknownObjectException if the object doesn't exist" do
35
- expect { browser.text_field(name: 'no_such_name').append('Append This') }.to raise_unknown_object_exception
36
- end
37
- end
38
-
39
- describe '#clear' do
40
- it 'removes all text from the text field' do
41
- browser.text_field(name: 'new_user_occupation').clear
42
- expect(browser.text_field(name: 'new_user_occupation').value).to be_empty
43
- browser.textarea(id: 'delete_user_comment').clear
44
- expect(browser.textarea(id: 'delete_user_comment').value).to be_empty
45
- end
46
-
47
- it 'removes all text from the content editable element' do
48
- browser.div(id: 'contenteditable').clear
49
- expect(browser.div(id: 'contenteditable').text).to eq ''
50
- end
51
-
52
- it "raises UnknownObjectException if the text field doesn't exist" do
53
- expect { browser.text_field(id: 'no_such_id').clear }.to raise_unknown_object_exception
54
- end
55
-
56
- it 'raises ObjectReadOnlyException if the object is read only' do
57
- expect { browser.text_field(id: 'new_user_code').clear }.to raise_object_read_only_exception
58
- end
59
- end
60
-
61
- describe '#value=' do
62
- it 'sets the value of the element' do
63
- browser.text_field(id: 'new_user_email').value = 'Hello Cruel World'
64
- expect(browser.text_field(id: 'new_user_email').value).to eq 'Hello Cruel World'
65
- end
66
-
67
- it 'is able to set multi-byte characters' do
68
- browser.text_field(name: 'new_user_occupation').value = 'ijij'
69
- expect(browser.text_field(name: 'new_user_occupation').value).to eq 'ijij'
70
- end
71
-
72
- it 'sets the value of a textarea element' do
73
- browser.textarea(id: 'delete_user_comment').value = 'Hello Cruel World'
74
- expect(browser.textarea(id: 'delete_user_comment').value).to eq 'Hello Cruel World'
75
- end
76
-
77
- it "raises UnknownObjectException if the text field doesn't exist" do
78
- expect { browser.text_field(name: 'no_such_name').value = 'yo' }.to raise_unknown_object_exception
79
- end
80
- end
81
-
82
- describe '#set' do
83
- it 'sets the value of the element' do
84
- browser.text_field(id: 'new_user_email').set('Bye Cruel World')
85
- expect(browser.text_field(id: 'new_user_email').value).to eq 'Bye Cruel World'
86
- end
87
-
88
- it 'sets the value of a textarea element' do
89
- browser.textarea(id: 'delete_user_comment').set('Hello Cruel World')
90
- expect(browser.textarea(id: 'delete_user_comment').value).to eq 'Hello Cruel World'
91
- end
92
-
93
- it 'sets the value of a content editable element' do
94
- browser.div(id: 'contenteditable').set('Bar')
95
- expect(browser.div(id: 'contenteditable').text).to eq 'Bar'
96
- end
97
-
98
- it 'fires events' do
99
- browser.text_field(id: 'new_user_username').set('Hello World')
100
- expect(browser.span(id: 'current_length').text).to eq '11'
101
- end
102
-
103
- it 'sets the value of a password field' do
104
- browser.text_field(name: 'new_user_password').set('secret')
105
- expect(browser.text_field(name: 'new_user_password').value).to eq 'secret'
106
- end
107
-
108
- it 'sets the value when accessed through the enclosing Form' do
109
- browser.form(id: 'new_user').text_field(name: 'new_user_password').set('secret')
110
- expect(browser.form(id: 'new_user').text_field(name: 'new_user_password').value).to eq 'secret'
111
- end
112
-
113
- it 'is able to set multi-byte characters' do
114
- browser.text_field(name: 'new_user_occupation').set('ijij')
115
- expect(browser.text_field(name: 'new_user_occupation').value).to eq 'ijij'
116
- end
117
-
118
- it 'sets the value to a concatenation of multiple arguments' do
119
- browser.text_field(id: 'new_user_email').set('Bye', 'Cruel', 'World')
120
- expect(browser.text_field(id: 'new_user_email').value).to eq 'ByeCruelWorld'
121
- end
122
-
123
- it 'sets the value to blank when no arguments are provided' do
124
- browser.text_field(id: 'new_user_email').set
125
- expect(browser.text_field(id: 'new_user_email').value).to eq ''
126
- end
127
-
128
- it "raises UnknownObjectException if the text field doesn't exist" do
129
- expect { browser.text_field(id: 'no_such_id').set('secret') }.to raise_unknown_object_exception
130
- end
131
-
132
- it 'raises ObjectReadOnlyException if the object is read only' do
133
- expect { browser.text_field(id: 'new_user_code').set('Foo') }.to raise_object_read_only_exception
134
- end
135
- end
136
-
137
- describe '#set!' do
138
- it 'sets the value of the element' do
139
- browser.text_field(id: 'new_user_email').set!('Bye Cruel World')
140
- expect(browser.text_field(id: 'new_user_email').value).to eq 'Bye Cruel World'
141
- end
142
-
143
- it 'sets the value of a textarea element' do
144
- browser.textarea(id: 'delete_user_comment').set!('Hello Cruel World')
145
- expect(browser.textarea(id: 'delete_user_comment').value).to eq 'Hello Cruel World'
146
- end
147
-
148
- it 'sets the value of a content editable element' do
149
- browser.div(id: 'contenteditable').set!('foo')
150
- expect(browser.div(id: 'contenteditable').text).to eq 'foo'
151
- end
152
-
153
- it 'fires events' do
154
- browser.text_field(id: 'new_user_username').set!('Hello World')
155
- expect(browser.span(id: 'current_length').text).to eq '11'
156
- end
157
-
158
- it 'sets the value of a password field' do
159
- browser.text_field(name: 'new_user_password').set!('secret')
160
- expect(browser.text_field(name: 'new_user_password').value).to eq 'secret'
161
- end
162
-
163
- it 'sets the value when accessed through the enclosing Form' do
164
- browser.form(id: 'new_user').text_field(name: 'new_user_password').set!('secret')
165
- expect(browser.form(id: 'new_user').text_field(name: 'new_user_password').value).to eq 'secret'
166
- end
167
-
168
- it 'is able to set multi-byte characters' do
169
- browser.text_field(name: 'new_user_occupation').set!('ijij')
170
- expect(browser.text_field(name: 'new_user_occupation').value).to eq 'ijij'
171
- end
172
-
173
- it 'sets the value to a concatenation of multiple arguments' do
174
- browser.text_field(id: 'new_user_email').set!('Bye', 'Cruel', 'World')
175
- expect(browser.text_field(id: 'new_user_email').value).to eq 'ByeCruelWorld'
176
- end
177
-
178
- it 'sets the value to blank when no arguments are provided' do
179
- browser.text_field(id: 'new_user_email').set!
180
- expect(browser.text_field(id: 'new_user_email').value).to eq ''
181
- end
182
-
183
- it 'raises ArgumentError for special keys' do
184
- expect { browser.text_field(id: 'new_user_email').set!('a', :tab) }.to raise_error(ArgumentError)
185
- end
186
-
187
- it "raises UnknownObjectException if the text field doesn't exist" do
188
- expect { browser.text_field(id: 'no_such_id').set!('secret') }.to raise_unknown_object_exception
189
- end
190
-
191
- it "raises Exception if the value of text field doesn't match" do
192
- element = browser.text_field(id: 'new_user_password')
193
- allow(element).to receive(:value).and_return('wrong')
194
- msg = "#set! value: 'wrong' does not match expected input: 'secret'"
195
- expect { element.set!('secret') }.to raise_exception(Watir::Exception::Error, msg)
196
- end
197
-
198
- it "raises Exception if the text of content editable element doesn't match" do
199
- element = browser.div(id: 'contenteditable')
200
- allow(element).to receive(:text).and_return('wrong')
201
- msg = "#set! text: 'wrong' does not match expected input: 'secret'"
202
- expect { element.set!('secret') }.to raise_exception(Watir::Exception::Error, msg)
5
+ module Watir
6
+ describe UserEditable do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
9
+ end
10
+
11
+ describe '#append' do
12
+ it 'appends the text to the text field', except: {browser: :safari, reason: 'incorrectly clears first'} do
13
+ browser.text_field(name: 'new_user_occupation').append(' Append This')
14
+ expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer Append This'
15
+ end
16
+
17
+ it 'appends multi-byte characters', except: {browser: :safari, reason: 'incorrectly clears first'} do
18
+ browser.text_field(name: 'new_user_occupation').append(' ijij')
19
+ expect(browser.text_field(name: 'new_user_occupation').value).to eq 'Developer ijij'
20
+ end
21
+
22
+ it 'raises NotImplementedError if the object is content editable element' do
23
+ msg = '#append method is not supported with contenteditable element'
24
+ expect { browser.div(id: 'contenteditable').append('bar') }.to raise_exception(NotImplementedError, msg)
25
+ end
26
+
27
+ it 'raises ObjectReadOnlyException if the object is read only' do
28
+ expect { browser.text_field(id: 'new_user_code').append('Append This') }.to raise_object_read_only_exception
29
+ end
30
+
31
+ it 'raises ObjectDisabledException if the object is disabled' do
32
+ expect { browser.text_field(name: 'new_user_species').append('Append This') }.to raise_object_disabled_exception
33
+ end
34
+
35
+ it "raises UnknownObjectException if the object doesn't exist" do
36
+ expect { browser.text_field(name: 'no_such_name').append('Append This') }.to raise_unknown_object_exception
37
+ end
38
+ end
39
+
40
+ describe '#clear' do
41
+ it 'removes all text from the text field' do
42
+ browser.text_field(name: 'new_user_occupation').clear
43
+ expect(browser.text_field(name: 'new_user_occupation').value).to be_empty
44
+ browser.textarea(id: 'delete_user_comment').clear
45
+ expect(browser.textarea(id: 'delete_user_comment').value).to be_empty
46
+ end
47
+
48
+ it 'removes all text from the content editable element' do
49
+ browser.div(id: 'contenteditable').clear
50
+ expect(browser.div(id: 'contenteditable').text).to eq ''
51
+ end
52
+
53
+ it "raises UnknownObjectException if the text field doesn't exist" do
54
+ expect { browser.text_field(id: 'no_such_id').clear }.to raise_unknown_object_exception
55
+ end
56
+
57
+ it 'raises ObjectReadOnlyException if the object is read only' do
58
+ expect { browser.text_field(id: 'new_user_code').clear }.to raise_object_read_only_exception
59
+ end
60
+ end
61
+
62
+ describe '#value=' do
63
+ it 'sets the value of the element' do
64
+ browser.text_field(id: 'new_user_email').value = 'Hello Cruel World'
65
+ expect(browser.text_field(id: 'new_user_email').value).to eq 'Hello Cruel World'
66
+ end
67
+
68
+ it 'is able to set multi-byte characters' do
69
+ browser.text_field(name: 'new_user_occupation').value = 'ijij'
70
+ expect(browser.text_field(name: 'new_user_occupation').value).to eq 'ijij'
71
+ end
72
+
73
+ it 'sets the value of a textarea element' do
74
+ browser.textarea(id: 'delete_user_comment').value = 'Hello Cruel World'
75
+ expect(browser.textarea(id: 'delete_user_comment').value).to eq 'Hello Cruel World'
76
+ end
77
+
78
+ it "raises UnknownObjectException if the text field doesn't exist" do
79
+ expect { browser.text_field(name: 'no_such_name').value = 'yo' }.to raise_unknown_object_exception
80
+ end
81
+ end
82
+
83
+ describe '#set' do
84
+ it 'sets the value of the element' do
85
+ browser.text_field(id: 'new_user_email').set('Bye Cruel World')
86
+ expect(browser.text_field(id: 'new_user_email').value).to eq 'Bye Cruel World'
87
+ end
88
+
89
+ it 'sets the value of a textarea element' do
90
+ browser.textarea(id: 'delete_user_comment').set('Hello Cruel World')
91
+ expect(browser.textarea(id: 'delete_user_comment').value).to eq 'Hello Cruel World'
92
+ end
93
+
94
+ it 'sets the value of a content editable element' do
95
+ browser.div(id: 'contenteditable').set('Bar')
96
+ expect(browser.div(id: 'contenteditable').text).to eq 'Bar'
97
+ end
98
+
99
+ it 'fires events' do
100
+ browser.text_field(id: 'new_user_username').set('Hello World')
101
+ expect(browser.span(id: 'current_length').text).to eq '11'
102
+ end
103
+
104
+ it 'sets the value of a password field' do
105
+ browser.text_field(name: 'new_user_password').set('secret')
106
+ expect(browser.text_field(name: 'new_user_password').value).to eq 'secret'
107
+ end
108
+
109
+ it 'sets the value when accessed through the enclosing Form' do
110
+ browser.form(id: 'new_user').text_field(name: 'new_user_password').set('secret')
111
+ expect(browser.form(id: 'new_user').text_field(name: 'new_user_password').value).to eq 'secret'
112
+ end
113
+
114
+ it 'is able to set multi-byte characters' do
115
+ browser.text_field(name: 'new_user_occupation').set('ijij')
116
+ expect(browser.text_field(name: 'new_user_occupation').value).to eq 'ijij'
117
+ end
118
+
119
+ it 'sets the value to a concatenation of multiple arguments' do
120
+ browser.text_field(id: 'new_user_email').set('Bye', 'Cruel', 'World')
121
+ expect(browser.text_field(id: 'new_user_email').value).to eq 'ByeCruelWorld'
122
+ end
123
+
124
+ it 'sets the value to blank when no arguments are provided' do
125
+ browser.text_field(id: 'new_user_email').set
126
+ expect(browser.text_field(id: 'new_user_email').value).to eq ''
127
+ end
128
+
129
+ it "raises UnknownObjectException if the text field doesn't exist" do
130
+ expect { browser.text_field(id: 'no_such_id').set('secret') }.to raise_unknown_object_exception
131
+ end
132
+
133
+ it 'raises ObjectReadOnlyException if the object is read only' do
134
+ expect { browser.text_field(id: 'new_user_code').set('Foo') }.to raise_object_read_only_exception
135
+ end
136
+ end
137
+
138
+ describe '#set!' do
139
+ it 'sets the value of the element' do
140
+ browser.text_field(id: 'new_user_email').set!('Bye Cruel World')
141
+ expect(browser.text_field(id: 'new_user_email').value).to eq 'Bye Cruel World'
142
+ end
143
+
144
+ it 'sets the value of a textarea element' do
145
+ browser.textarea(id: 'delete_user_comment').set!('Hello Cruel World')
146
+ expect(browser.textarea(id: 'delete_user_comment').value).to eq 'Hello Cruel World'
147
+ end
148
+
149
+ it 'sets the value of a content editable element' do
150
+ browser.div(id: 'contenteditable').set!('foo')
151
+ expect(browser.div(id: 'contenteditable').text).to eq 'foo'
152
+ end
153
+
154
+ it 'fires events' do
155
+ browser.text_field(id: 'new_user_username').set!('Hello World')
156
+ expect(browser.span(id: 'current_length').text).to eq '11'
157
+ end
158
+
159
+ it 'sets the value of a password field' do
160
+ browser.text_field(name: 'new_user_password').set!('secret')
161
+ expect(browser.text_field(name: 'new_user_password').value).to eq 'secret'
162
+ end
163
+
164
+ it 'sets the value when accessed through the enclosing Form' do
165
+ browser.form(id: 'new_user').text_field(name: 'new_user_password').set!('secret')
166
+ expect(browser.form(id: 'new_user').text_field(name: 'new_user_password').value).to eq 'secret'
167
+ end
168
+
169
+ it 'is able to set multi-byte characters' do
170
+ browser.text_field(name: 'new_user_occupation').set!('ijij')
171
+ expect(browser.text_field(name: 'new_user_occupation').value).to eq 'ijij'
172
+ end
173
+
174
+ it 'sets the value to a concatenation of multiple arguments' do
175
+ browser.text_field(id: 'new_user_email').set!('Bye', 'Cruel', 'World')
176
+ expect(browser.text_field(id: 'new_user_email').value).to eq 'ByeCruelWorld'
177
+ end
178
+
179
+ it 'sets the value to blank when no arguments are provided' do
180
+ browser.text_field(id: 'new_user_email').set!
181
+ expect(browser.text_field(id: 'new_user_email').value).to eq ''
182
+ end
183
+
184
+ it 'raises ArgumentError for special keys' do
185
+ expect { browser.text_field(id: 'new_user_email').set!('a', :tab) }.to raise_error(ArgumentError)
186
+ end
187
+
188
+ it "raises UnknownObjectException if the text field doesn't exist" do
189
+ expect { browser.text_field(id: 'no_such_id').set!('secret') }.to raise_unknown_object_exception
190
+ end
191
+
192
+ it "raises Exception if the value of text field doesn't match" do
193
+ element = browser.text_field(id: 'new_user_password')
194
+ allow(element).to receive(:value).and_return('wrong')
195
+ msg = "#set! value: 'wrong' does not match expected input: 'secret'"
196
+ expect { element.set!('secret') }.to raise_exception(Watir::Exception::Error, msg)
197
+ end
198
+
199
+ it "raises Exception if the text of content editable element doesn't match" do
200
+ element = browser.div(id: 'contenteditable')
201
+ allow(element).to receive(:text).and_return('wrong')
202
+ msg = "#set! text: 'wrong' does not match expected input: 'secret'"
203
+ expect { element.set!('secret') }.to raise_exception(Watir::Exception::Error, msg)
204
+ end
203
205
  end
204
206
  end
205
207
  end