Skip to content

Commit ee7c582

Browse files
committed
Deprecate Alert#authenticate
It's not supported by any drivers anymore and is not spec-compliant. Watch w3c/webdriver#385 for updates.
1 parent 9034099 commit ee7c582

File tree

5 files changed

+18
-50
lines changed

5 files changed

+18
-50
lines changed

lib/selenium/webdriver/common/alert.rb

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def text
4444
end
4545

4646
def authenticate(username, password)
47+
WebDriver.logger.deprecate 'Alert#authenticate'
4748
@bridge.authentication(username: username, password: password)
4849
accept
4950
end

lib/selenium/webdriver/common/logger.rb

+11-4
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,20 @@ def io
101101
end
102102

103103
#
104-
# Marks code as deprecated with replacement.
104+
# Marks code as deprecated with/without replacement.
105105
#
106106
# @param [String] old
107-
# @param [String] new
107+
# @param [String, nil] new
108108
#
109-
def deprecate(old, new)
110-
warn "[DEPRECATION] #{old} is deprecated. Use #{new} instead."
109+
def deprecate(old, new = nil)
110+
message = "[DEPRECATION] #{old} is deprecated"
111+
message << if new
112+
". Use #{new} instead."
113+
else
114+
' and will be removed in the next releases.'
115+
end
116+
117+
warn message
111118
end
112119

113120
private

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

-19
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,10 @@ def call(env)
123123
body = req['upload'][:tempfile].read
124124

125125
[200, {'Content-Type' => 'text/html'}, [body]]
126-
when '/basicAuth'
127-
if authorized?(env)
128-
status = 200
129-
header = {'Content-Type' => 'text/html'}
130-
body = '<h1>authorized</h1>'
131-
else
132-
status = 401
133-
header = {'WWW-Authenticate' => 'Basic realm="basic-auth-test"'}
134-
body = 'Login please'
135-
end
136-
137-
[status, header, [body]]
138126
else
139127
@static.call env
140128
end
141129
end
142-
143-
private
144-
145-
def authorized?(env)
146-
auth = Rack::Auth::Basic::Request.new(env)
147-
auth.provided? && auth.basic? && auth.credentials && auth.credentials == BASIC_AUTH_CREDENTIALS
148-
end
149130
end
150131
end # RackServer
151132
end # SpecSupport

spec/integration/selenium/webdriver/target_locator_spec.rb

-26
Original file line numberDiff line numberDiff line change
@@ -348,32 +348,6 @@ module WebDriver
348348
end
349349
end
350350
end
351-
352-
compliant_on browser: :ie do
353-
# Windows 10 changed the auth alert
354-
not_compliant_on browser: :ie do
355-
describe 'basic auth alerts' do
356-
after { reset_driver! }
357-
358-
it 'allows the user to send valid credentials to an alert' do
359-
driver.navigate.to url_for('basicAuth')
360-
driver.switch_to.alert.authenticate('test', 'test')
361-
362-
expect(driver.find_element(tag_name: 'h1').text).to eq('authorized')
363-
end
364-
365-
it 'does not raise an error when invalid credentials are used' do
366-
driver.navigate.to url_for('basicAuth')
367-
driver.switch_to.alert.authenticate('invalid', 'invalid')
368-
369-
wait = Selenium::WebDriver::Wait.new(timeout: 5, ignore: Selenium::WebDriver::Error::NoSuchAlertError)
370-
wait.until { driver.switch_to.alert }
371-
372-
expect { driver.switch_to.alert.dismiss }.to_not raise_error
373-
end
374-
end
375-
end
376-
end
377351
end
378352
end # WebDriver
379353
end # Selenium

spec/unit/selenium/webdriver/common/logger_spec.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,15 @@ module WebDriver
5858
end
5959
end
6060

61-
it 'allows to deprecate functionality' do
61+
it 'allows to deprecate functionality with replacement' do
6262
message = /WARN Selenium \[DEPRECATION\] #old is deprecated\. Use #new instead\./
6363
expect { WebDriver.logger.deprecate('#old', '#new') }.to output(message).to_stdout
6464
end
65+
66+
it 'allows to deprecate functionality without replacement' do
67+
message = /WARN Selenium \[DEPRECATION\] #old is deprecated and will be removed in the next releases\./
68+
expect { WebDriver.logger.deprecate('#old') }.to output(message).to_stdout
69+
end
6570
end
6671
end # WebDriver
6772
end # Selenium

0 commit comments

Comments
 (0)