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
2885 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 { 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
describe('Federated Credential Management Test', function () {
38
it('credential management dialog should appear', async function () {
39
await driver.get(Pages.fedcm)
40
41
let triggerButton = await driver.findElement(By.id('triggerButton'))
42
await triggerButton.click()
43
44
let dialog
45
46
await driver.wait(
47
async () => {
48
try {
49
dialog = await driver.getFederalCredentialManagementDialog()
50
return (await dialog.type()) === 'AccountChooser'
51
} catch (error) {
52
return false
53
}
54
},
55
10000,
56
'Expected dialog type to be "AccountChooser"',
57
2000,
58
)
59
60
assert.equal(await dialog.type(), 'AccountChooser')
61
let title = await dialog.title()
62
assert.equal(title.includes('Sign in to'), true)
63
})
64
65
it('can dismiss dialog', async function () {
66
await driver.get(Pages.fedcm)
67
68
let triggerButton = await driver.findElement(By.id('triggerButton'))
69
await triggerButton.click()
70
71
let dialog = await driver.getFederalCredentialManagementDialog()
72
73
await driver.wait(
74
async () => {
75
try {
76
return (await dialog.type()) === 'AccountChooser'
77
} catch (error) {
78
return false
79
}
80
},
81
10000,
82
'Expected dialog type to be "AccountChooser"',
83
2000,
84
)
85
86
assert.equal(await dialog.type(), 'AccountChooser')
87
let title = await dialog.title()
88
assert.equal(title.includes('Sign in to'), true)
89
90
await dialog.dismiss()
91
92
try {
93
await dialog.type()
94
assert.fail('Above command should throw error')
95
} catch (error) {
96
assert.equal(error.message.includes('no such alert'), true)
97
}
98
})
99
100
it('can select account', async function () {
101
await driver.get(Pages.fedcm)
102
103
let triggerButton = await driver.findElement(By.id('triggerButton'))
104
await triggerButton.click()
105
106
let dialog = await driver.getFederalCredentialManagementDialog()
107
108
await driver.wait(
109
async () => {
110
try {
111
return (await dialog.type()) === 'AccountChooser'
112
} catch (error) {
113
return false
114
}
115
},
116
10000,
117
'Expected dialog type to be "AccountChooser"',
118
2000,
119
)
120
121
assert.equal(await dialog.type(), 'AccountChooser')
122
let title = await dialog.title()
123
assert.equal(title.includes('Sign in to'), true)
124
125
await dialog.selectAccount(1)
126
})
127
128
it('can get account list', async function () {
129
await driver.get(Pages.fedcm)
130
131
let triggerButton = await driver.findElement(By.id('triggerButton'))
132
await triggerButton.click()
133
134
let dialog = await driver.getFederalCredentialManagementDialog()
135
136
await driver.wait(
137
async () => {
138
try {
139
return (await dialog.type()) === 'AccountChooser'
140
} catch (error) {
141
return false
142
}
143
},
144
10000,
145
'Expected dialog type to be "AccountChooser"',
146
2000,
147
)
148
149
assert.equal(await dialog.type(), 'AccountChooser')
150
let title = await dialog.title()
151
assert.equal(title.includes('Sign in to'), true)
152
153
const accounts = await dialog.accounts()
154
155
assert.equal(accounts.length, 2)
156
157
const account1 = accounts[0]
158
const account2 = accounts[1]
159
160
assert.strictEqual(account1.name, 'John Doe')
161
assert.strictEqual(account1.email, '[email protected]')
162
assert.strictEqual(account1.accountId, '1234')
163
assert.strictEqual(account1.givenName, 'John')
164
assert(account1.idpConfigUrl.includes('/fedcm/config.json'), true)
165
assert.strictEqual(account1.pictureUrl, 'https://idp.example/profile/123')
166
assert.strictEqual(account1.loginState, 'SignUp')
167
assert.strictEqual(account1.termsOfServiceUrl, 'https://rp.example/terms_of_service.html')
168
assert.strictEqual(account1.privacyPolicyUrl, 'https://rp.example/privacy_policy.html')
169
170
assert.strictEqual(account2.name, 'Aisha Ahmad')
171
assert.strictEqual(account2.email, '[email protected]')
172
assert.strictEqual(account2.accountId, '5678')
173
assert.strictEqual(account2.givenName, 'Aisha')
174
assert(account2.idpConfigUrl.includes('/fedcm/config.json'), true)
175
assert.strictEqual(account2.pictureUrl, 'https://idp.example/profile/567')
176
assert.strictEqual(account2.loginState, 'SignUp')
177
assert.strictEqual(account2.termsOfServiceUrl, 'https://rp.example/terms_of_service.html')
178
assert.strictEqual(account2.privacyPolicyUrl, 'https://rp.example/privacy_policy.html')
179
})
180
})
181
},
182
{ browsers: [Browser.CHROME, Browser.EDGE] },
183
)
184
185