Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/fedcm/fedcm_test.js
3220 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
'use strict'
19
20
const assert = require('node:assert')
21
const { Browser } = require('selenium-webdriver')
22
const { ignore, Pages, suite } = require('../../lib/test')
23
const { By } = require('selenium-webdriver/index')
24
25
suite(
26
function (env) {
27
let driver
28
29
beforeEach(async function () {
30
driver = await env.builder().build()
31
})
32
33
afterEach(async function () {
34
await driver.quit()
35
})
36
37
// Failing due to - https://issues.chromium.org/u/0/issues/425801332, enable when Chrome 140 is released
38
ignore(env.browsers(Browser.CHROME, Browser.EDGE)).describe('Federated Credential Management Test', function () {
39
it('credential management dialog should appear', async function () {
40
await driver.get(Pages.fedcm)
41
42
let triggerButton = await driver.findElement(By.id('triggerButton'))
43
await triggerButton.click()
44
45
let dialog
46
47
await driver.wait(
48
async () => {
49
try {
50
dialog = await driver.getFederalCredentialManagementDialog()
51
return (await dialog.type()) === 'AccountChooser'
52
} catch (error) {
53
return false
54
}
55
},
56
10000,
57
'Expected dialog type to be "AccountChooser"',
58
2000,
59
)
60
61
assert.equal(await dialog.type(), 'AccountChooser')
62
let title = await dialog.title()
63
assert.equal(title.includes('Sign in to'), true)
64
})
65
66
it('can dismiss dialog', async function () {
67
await driver.get(Pages.fedcm)
68
69
let triggerButton = await driver.findElement(By.id('triggerButton'))
70
await triggerButton.click()
71
72
let dialog = await driver.getFederalCredentialManagementDialog()
73
74
await driver.wait(
75
async () => {
76
try {
77
return (await dialog.type()) === 'AccountChooser'
78
} catch (error) {
79
return false
80
}
81
},
82
10000,
83
'Expected dialog type to be "AccountChooser"',
84
2000,
85
)
86
87
assert.equal(await dialog.type(), 'AccountChooser')
88
let title = await dialog.title()
89
assert.equal(title.includes('Sign in to'), true)
90
91
await dialog.dismiss()
92
93
try {
94
await dialog.type()
95
assert.fail('Above command should throw error')
96
} catch (error) {
97
assert.equal(error.message.includes('no such alert'), true)
98
}
99
})
100
101
it('can select account', async function () {
102
await driver.get(Pages.fedcm)
103
104
let triggerButton = await driver.findElement(By.id('triggerButton'))
105
await triggerButton.click()
106
107
let dialog = await driver.getFederalCredentialManagementDialog()
108
109
await driver.wait(
110
async () => {
111
try {
112
return (await dialog.type()) === 'AccountChooser'
113
} catch (error) {
114
return false
115
}
116
},
117
10000,
118
'Expected dialog type to be "AccountChooser"',
119
2000,
120
)
121
122
assert.equal(await dialog.type(), 'AccountChooser')
123
let title = await dialog.title()
124
assert.equal(title.includes('Sign in to'), true)
125
126
await dialog.selectAccount(1)
127
})
128
129
it('can get account list', async function () {
130
await driver.get(Pages.fedcm)
131
132
let triggerButton = await driver.findElement(By.id('triggerButton'))
133
await triggerButton.click()
134
135
let dialog = await driver.getFederalCredentialManagementDialog()
136
137
await driver.wait(
138
async () => {
139
try {
140
return (await dialog.type()) === 'AccountChooser'
141
} catch (error) {
142
return false
143
}
144
},
145
10000,
146
'Expected dialog type to be "AccountChooser"',
147
2000,
148
)
149
150
assert.equal(await dialog.type(), 'AccountChooser')
151
let title = await dialog.title()
152
assert.equal(title.includes('Sign in to'), true)
153
154
const accounts = await dialog.accounts()
155
156
assert.equal(accounts.length, 2)
157
158
const account1 = accounts[0]
159
const account2 = accounts[1]
160
161
assert.strictEqual(account1.name, 'John Doe')
162
assert.strictEqual(account1.email, '[email protected]')
163
assert.strictEqual(account1.accountId, '1234')
164
assert.strictEqual(account1.givenName, 'John')
165
assert(account1.idpConfigUrl.includes('/fedcm/config.json'), true)
166
assert.strictEqual(account1.pictureUrl, 'https://idp.example/profile/123')
167
assert.strictEqual(account1.loginState, 'SignUp')
168
assert.strictEqual(account1.termsOfServiceUrl, 'https://rp.example/terms_of_service.html')
169
assert.strictEqual(account1.privacyPolicyUrl, 'https://rp.example/privacy_policy.html')
170
171
assert.strictEqual(account2.name, 'Aisha Ahmad')
172
assert.strictEqual(account2.email, '[email protected]')
173
assert.strictEqual(account2.accountId, '5678')
174
assert.strictEqual(account2.givenName, 'Aisha')
175
assert(account2.idpConfigUrl.includes('/fedcm/config.json'), true)
176
assert.strictEqual(account2.pictureUrl, 'https://idp.example/profile/567')
177
assert.strictEqual(account2.loginState, 'SignUp')
178
assert.strictEqual(account2.termsOfServiceUrl, 'https://rp.example/terms_of_service.html')
179
assert.strictEqual(account2.privacyPolicyUrl, 'https://rp.example/privacy_policy.html')
180
})
181
})
182
},
183
{ browsers: [Browser.CHROME, Browser.EDGE] },
184
)
185
186