Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/bidi/credentials_spec.rb
1865 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require File.expand_path('../spec_helper', __dir__)
21
require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/credentials', __dir__)
22
23
module Selenium
24
module WebDriver
25
class BiDi
26
describe Credentials do
27
describe '#initialize' do
28
it 'initializes with nil username/password by default' do
29
creds = described_class.new
30
expect(creds.username).to be_nil
31
expect(creds.password).to be_nil
32
end
33
34
it 'allows initialization with username and password' do
35
creds = described_class.new(username: 'alice', password: 'secret')
36
expect(creds.username).to eq('alice')
37
expect(creds.password).to eq('secret')
38
end
39
end
40
41
describe '#username / #password' do
42
it 'allows setting and retrieving username' do
43
creds = described_class.new
44
creds.username = 'bob'
45
expect(creds.username).to eq('bob')
46
end
47
48
it 'allows setting and retrieving password' do
49
creds = described_class.new
50
creds.password = 'my_password'
51
expect(creds.password).to eq('my_password')
52
end
53
end
54
55
describe '#as_json' do
56
it 'returns nil if username is missing' do
57
creds = described_class.new(password: 'secret')
58
expect(creds.as_json).to be_nil
59
end
60
61
it 'returns nil if password is missing' do
62
creds = described_class.new(username: 'alice')
63
expect(creds.as_json).to be_nil
64
end
65
66
it 'returns a hash of the credentials when both username and password are present' do
67
creds = described_class.new(username: 'alice', password: 'secret')
68
formatted_creds = creds.as_json
69
70
expect(formatted_creds).to eq(
71
type: 'password',
72
username: 'alice',
73
password: 'secret'
74
)
75
end
76
end
77
end
78
end
79
end
80
end
81
82