Skip to content

Commit 32edfbe

Browse files
authored
[rb] update safari tests (#16768)
* [rb] update guards for safari tests * [rb] guard safari tests broken by Safari 26.5 regression * automatically retry safari pairing attempts
1 parent 26794a0 commit 32edfbe

9 files changed

Lines changed: 66 additions & 46 deletions

File tree

rb/spec/integration/selenium/webdriver/action_builder_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ module WebDriver
2424
describe ActionBuilder, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do
2525
after { driver.action.clear_all_actions }
2626

27-
describe '#send_keys' do
28-
it 'sends keys to the active element', except: {browser: %i[safari safari_preview]} do
27+
describe '#send_keys', except: {browser: %i[safari safari_preview]} do
28+
it 'sends keys to the active element' do
2929
driver.navigate.to url_for('bodyTypingTest.html')
3030
keylogger = driver.find_element(id: 'body_result')
3131

@@ -38,7 +38,7 @@ module WebDriver
3838
expect(driver.find_element(id: 'result').text.strip).to be_empty
3939
end
4040

41-
it 'sends keys to element', only: {browser: %i[chrome edge firefox]} do
41+
it 'sends keys to element' do
4242
driver.navigate.to url_for('formPage.html')
4343

4444
input = driver.find_element(css: '#working')
@@ -72,8 +72,8 @@ module WebDriver
7272
end
7373
end
7474

75-
describe 'multiple key presses' do
76-
it 'sends keys with shift pressed', except: {browser: %i[safari safari_preview]} do
75+
describe 'multiple key presses', except: {browser: %i[safari safari_preview]} do
76+
it 'sends keys with shift pressed' do
7777
driver.navigate.to url_for('javascriptPage.html')
7878

7979
event_input = driver.find_element(id: 'theworks')
@@ -107,7 +107,7 @@ module WebDriver
107107
end
108108
end
109109

110-
describe '#release_actions' do
110+
describe '#release_actions', except: {browser: %i[safari safari_preview]} do
111111
it 'releases pressed keys' do
112112
driver.navigate.to url_for('javascriptPage.html')
113113

@@ -139,7 +139,7 @@ module WebDriver
139139
end
140140
end
141141

142-
describe '#click' do
142+
describe '#click', except: {browser: %i[safari safari_preview]} do
143143
it 'clicks provided element' do
144144
driver.navigate.to url_for('javascriptPage.html')
145145
element = driver.find_element(id: 'clickField')
@@ -159,15 +159,15 @@ module WebDriver
159159
# https://issues.chromium.org/issues/400087471
160160
before { reset_driver! if GlobalTestEnv.rbe? && GlobalTestEnv.browser == :chrome }
161161

162-
it 'presses pointer twice', except: {browser: %i[safari safari_preview]} do
162+
it 'presses pointer twice' do
163163
driver.navigate.to url_for('javascriptPage.html')
164164
element = driver.find_element(id: 'doubleClickField')
165165

166166
driver.action.double_click(element).perform
167167
expect(element.property(:value)).to eq('DoubleClicked')
168168
end
169169

170-
it 'executes with equivalent pointer methods', except: {browser: %i[safari safari_preview]} do
170+
it 'executes with equivalent pointer methods' do
171171
driver.navigate.to url_for('javascriptPage.html')
172172
element = driver.find_element(id: 'doubleClickField')
173173

@@ -197,7 +197,7 @@ module WebDriver
197197
end
198198
end
199199

200-
describe '#move_to' do
200+
describe '#move_to', except: {browser: %i[safari safari_preview]} do
201201
it 'moves to element' do
202202
driver.navigate.to url_for('javascriptPage.html')
203203
element = driver.find_element(id: 'clickField')
@@ -220,7 +220,7 @@ module WebDriver
220220
end
221221
end
222222

223-
describe '#drag_and_drop' do
223+
describe '#drag_and_drop', except: {browser: %i[safari safari_preview]} do
224224
it 'moves one element to another' do
225225
driver.navigate.to url_for('droppableItems.html')
226226

@@ -237,7 +237,7 @@ module WebDriver
237237
end
238238
end
239239

240-
describe '#drag_and_drop_by' do
240+
describe '#drag_and_drop_by', except: {browser: %i[safari safari_preview]} do
241241
it 'moves one element a provided distance' do
242242
driver.navigate.to url_for('droppableItems.html')
243243

@@ -253,7 +253,7 @@ module WebDriver
253253
end
254254
end
255255

256-
describe '#move_to_location' do
256+
describe '#move_to_location', except: {browser: %i[safari safari_preview]} do
257257
it 'moves pointer to specified coordinates' do
258258
driver.navigate.to url_for('javascriptPage.html')
259259
element = driver.find_element(id: 'clickField')
@@ -390,7 +390,7 @@ module WebDriver
390390
end
391391

392392
it 'raises MoveTargetOutOfBoundsError when origin offset is out of viewport',
393-
only: {browser: %i[chrome edge firefox]} do
393+
except: {browser: %i[safari safari_preview]} do
394394
driver.navigate.to url_for('scrolling_tests/frame_with_nested_scrolling_frame.html')
395395
scroll_origin = WheelActions::ScrollOrigin.viewport(-10, -10)
396396

rb/spec/integration/selenium/webdriver/driver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module WebDriver
6060
expect(driver.page_source).to match(%r{<title>XHTML Test Page</title>}i)
6161
end
6262

63-
it 'refreshes the page' do
63+
it 'refreshes the page', except: {browser: %i[safari safari_preview]} do
6464
driver.navigate.to url_for('javascriptPage.html')
6565
short_wait { driver.find_element(id: 'updatediv') }.click
6666
expect(driver.find_element(id: 'dynamo').text).to eq('Fish and chips!')

rb/spec/integration/selenium/webdriver/element_spec.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module WebDriver
2626
open_file 'formPage.html'
2727
element = wait_for_element(id: 'imageButton')
2828
expect { element.click }.not_to raise_error
29-
reset_driver!(time: 1) if %i[safari safari_preview].include? GlobalTestEnv.browser
3029
end
3130

3231
# Safari returns "click intercepted" error instead of "element click intercepted"
@@ -50,8 +49,6 @@ module WebDriver
5049

5150
expect { button.click }.to raise_exception(Error::StaleElementReferenceError,
5251
/errors#staleelementreferenceexception/)
53-
54-
reset_driver!(time: 1) if %i[safari safari_preview].include? GlobalTestEnv.browser
5552
end
5653

5754
describe '#submit' do
@@ -203,12 +200,12 @@ module WebDriver
203200
expect(element.dom_attribute(prop_or_attr)).to eq 'true'
204201
end
205202

206-
it '#property updates to false after click' do
203+
it '#property updates to false after click', except: {browser: %i[safari safari_preview]} do
207204
element.click
208205
expect(element.property(prop_or_attr)).to be false
209206
end
210207

211-
it '#attribute updates to nil after click' do
208+
it '#attribute updates to nil after click', except: {browser: %i[safari safari_preview]} do
212209
element.click
213210
expect(element.attribute(prop_or_attr)).to be_nil
214211
end
@@ -235,12 +232,12 @@ module WebDriver
235232
expect(element.dom_attribute(prop_or_attr)).to be_nil
236233
end
237234

238-
it '#property updates to true after click' do
235+
it '#property updates to true after click', except: {browser: %i[safari safari_preview]} do
239236
element.click
240237
expect(element.property(prop_or_attr)).to be true
241238
end
242239

243-
it '#attribute updates to String after click' do
240+
it '#attribute updates to String after click', except: {browser: %i[safari safari_preview]} do
244241
element.click
245242
expect(element.attribute(prop_or_attr)).to eq 'true'
246243
end
@@ -457,7 +454,7 @@ module WebDriver
457454
expect { element.clear }.not_to raise_error
458455
end
459456

460-
it 'gets and set selected' do
457+
it 'gets and set selected', except: {browser: %i[safari safari_preview]} do
461458
open_file 'formPage.html'
462459

463460
cheese = wait_for_element(id: 'cheese')
@@ -529,7 +526,7 @@ module WebDriver
529526
end
530527

531528
# IE - https://github.com/SeleniumHQ/selenium/pull/4043
532-
it 'drags and drop', except: {browser: :ie} do
529+
it 'drags and drop', except: [{browser: :ie}, {browser: %i[safari safari_preview]}] do
533530
open_file 'dragAndDropTest.html'
534531

535532
img1 = wait_for_element(id: 'test1')

rb/spec/integration/selenium/webdriver/manager_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ module WebDriver
2626
before { driver.navigate.to url_for('xhtmlTest.html') }
2727

2828
after do
29-
if GlobalTestEnv.rbe? && GlobalTestEnv.browser == :chrome
29+
if (GlobalTestEnv.rbe? && GlobalTestEnv.browser == :chrome) ||
30+
%i[safari safari_preview].include?(GlobalTestEnv.browser)
3031
reset_driver!
3132
else
3233
driver.manage.delete_all_cookies

rb/spec/integration/selenium/webdriver/navigation_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
module Selenium
2222
module WebDriver
2323
describe Navigation do
24-
it 'navigates back and forward' do
24+
it 'navigates back and forward', except: {browser: %i[safari safari_preview]} do
2525
form_title = 'We Leave From Here'
2626
result_title = 'We Arrive Here'
2727
form_url = url_for 'formPage.html'
@@ -46,7 +46,7 @@ module WebDriver
4646
expect(driver.title).to eq(result_title)
4747
end
4848

49-
it 'refreshes the page' do
49+
it 'refreshes the page', except: {browser: %i[safari safari_preview]} do
5050
changed_title = 'Changed'
5151

5252
driver.navigate.to url_for('javascriptPage.html')

rb/spec/integration/selenium/webdriver/spec_support/test_environment.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,11 @@ def driver_instance(...)
7272
@driver_instance || create_driver!(...)
7373
end
7474

75-
def reset_driver!(time: 0, **opts, &block)
75+
def reset_driver!(**opts, &block)
7676
# do not reset if the test was marked skipped
7777
return if opts.delete(:example)&.metadata&.fetch(:skip, nil)
7878

7979
quit_driver
80-
sleep time
8180
driver_instance(**opts, &block)
8281
end
8382

@@ -203,10 +202,12 @@ def root
203202
def create_driver!(listener: nil, http_client: nil, **, &block)
204203
check_for_previous_error
205204
http_client ||= Remote::Http::Default.new(read_timeout: 30)
205+
@safari_pairing_attempts ||= 0
206206

207207
method = :"#{driver}_driver"
208208
opts = {options: build_options(**), listener: listener, http_client: http_client}
209209
instance = private_methods.include?(method) ? send(method, **opts) : WebDriver::Driver.for(driver, **opts)
210+
@safari_pairing_attempts = 0
210211
@create_driver_error_count -= 1 unless @create_driver_error_count.zero?
211212
if block
212213
begin
@@ -218,6 +219,7 @@ def create_driver!(listener: nil, http_client: nil, **, &block)
218219
@driver_instance = instance
219220
end
220221
rescue StandardError => e
222+
retry if safari_pairing_retry?(e)
221223
@create_driver_error = e
222224
@create_driver_error_count += 1
223225
raise e
@@ -247,6 +249,21 @@ def current_env
247249

248250
MAX_ERRORS = 4
249251

252+
# Safari Driver is slow to release previous sessions especially on Grid.
253+
SAFARI_PAIRING_RETRIES = 5
254+
SAFARI_PAIRING_INTERVAL = 1
255+
256+
def safari_pairing_retry?(error)
257+
msg = 'instance is already paired'
258+
return false unless browser.to_s.include?('safari') && error.message.to_s.include?(msg)
259+
return false if @safari_pairing_attempts >= SAFARI_PAIRING_RETRIES
260+
261+
@safari_pairing_attempts += 1
262+
WebDriver.logger.warn("Safari pairing busy; retry #{@safari_pairing_attempts}/#{SAFARI_PAIRING_RETRIES}")
263+
sleep SAFARI_PAIRING_INTERVAL
264+
true
265+
end
266+
250267
class DriverInstantiationError < StandardError
251268
end
252269

rb/spec/integration/selenium/webdriver/target_locator_spec.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ module WebDriver
111111
end
112112
end
113113

114-
it 'switches to a window and back when given a block' do
114+
it 'switches to a window and back when given a block', except: {browser: %i[safari safari_preview]} do
115115
driver.navigate.to url_for('xhtmlTest.html')
116116

117117
driver.find_element(link: 'Open new window').click
@@ -125,7 +125,7 @@ module WebDriver
125125
wait.until { driver.title == 'XHTML Test Page' }
126126
end
127127

128-
it 'handles exceptions inside the block' do
128+
it 'handles exceptions inside the block', except: {browser: %i[safari safari_preview]} do
129129
driver.navigate.to url_for('xhtmlTest.html')
130130

131131
driver.find_element(link: 'Open new window').click
@@ -139,7 +139,7 @@ module WebDriver
139139
expect(driver.title).to eq('XHTML Test Page')
140140
end
141141

142-
it 'switches to a window without a block' do
142+
it 'switches to a window without a block', except: {browser: %i[safari safari_preview]} do
143143
driver.navigate.to url_for('xhtmlTest.html')
144144

145145
driver.find_element(link: 'Open new window').click
@@ -151,7 +151,7 @@ module WebDriver
151151
expect(driver.title).to eq('We Arrive Here')
152152
end
153153

154-
it 'uses the original window if the block closes the popup' do
154+
it 'uses the original window if the block closes the popup', except: {browser: %i[safari safari_preview]} do
155155
driver.navigate.to url_for('xhtmlTest.html')
156156

157157
driver.find_element(link: 'Open new window').click
@@ -168,8 +168,8 @@ module WebDriver
168168
end
169169
end
170170

171-
context 'with more than two windows', except: [{browser: %i[safari safari_preview]},
172-
{driver: :remote, browser: :ie}] do
171+
context 'with more than two windows', except: [{driver: :remote, browser: :ie},
172+
{browser: %i[safari safari_preview]}] do
173173
it 'closes current window via block' do
174174
driver.navigate.to url_for('xhtmlTest.html')
175175
wait_for_element(link: 'Create a new anonymous window')
@@ -237,7 +237,8 @@ module WebDriver
237237
end
238238
end
239239

240-
it 'switches to a window and execute a block when current window is closed' do
240+
it 'switches to a window and execute a block when current window is closed',
241+
except: {browser: %i[safari safari_preview]} do
241242
driver.navigate.to url_for('xhtmlTest.html')
242243
driver.find_element(link: 'Open new window').click
243244
wait.until { driver.window_handles.size == 2 }
@@ -265,7 +266,7 @@ module WebDriver
265266

266267
# Edge BUG - https://connect.microsoft.com/IE/feedback/details/1850030
267268
describe 'alerts' do
268-
it 'allows the user to accept an alert' do
269+
it 'allows the user to accept an alert', except: {browser: %i[safari safari_preview]} do
269270
driver.navigate.to url_for('alerts.html')
270271
driver.find_element(id: 'alert').click
271272

@@ -276,7 +277,7 @@ module WebDriver
276277
expect(driver.title).to eq('Testing Alerts')
277278
end
278279

279-
it 'allows the user to dismiss an alert' do
280+
it 'allows the user to dismiss an alert', except: {browser: %i[safari safari_preview]} do
280281
driver.navigate.to url_for('alerts.html')
281282
driver.find_element(id: 'alert').click
282283

@@ -287,7 +288,7 @@ module WebDriver
287288
expect(driver.title).to eq('Testing Alerts')
288289
end
289290

290-
it 'allows the user to set the value of a prompt' do
291+
it 'allows the user to set the value of a prompt', except: {browser: %i[safari safari_preview]} do
291292
driver.navigate.to url_for('alerts.html')
292293
driver.find_element(id: 'prompt').click
293294

@@ -299,7 +300,7 @@ module WebDriver
299300
expect(text).to eq('cheese')
300301
end
301302

302-
it 'allows the user to get the text of an alert' do
303+
it 'allows the user to get the text of an alert', except: {browser: %i[safari safari_preview]} do
303304
driver.navigate.to url_for('alerts.html')
304305
driver.find_element(id: 'alert').click
305306

@@ -311,7 +312,7 @@ module WebDriver
311312
wait_for_no_alert
312313
end
313314

314-
it 'raises when calling #text on a closed alert' do
315+
it 'raises when calling #text on a closed alert', except: {browser: %i[safari safari_preview]} do
315316
driver.navigate.to url_for('alerts.html')
316317
wait_for_element(id: 'alert')
317318

@@ -329,7 +330,8 @@ module WebDriver
329330
end
330331

331332
describe 'unhandled alert error' do
332-
it 'raises an UnexpectedAlertOpenError if an alert has not been dealt with' do
333+
it 'raises an UnexpectedAlertOpenError if an alert has not been dealt with',
334+
except: {browser: %i[safari safari_preview]} do
333335
driver.navigate.to url_for('alerts.html')
334336
driver.find_element(id: 'alert').click
335337
wait_for_alert

0 commit comments

Comments
 (0)