|
18 | 18 | 'use strict' |
19 | 19 |
|
20 | 20 | const assert = require('node:assert') |
21 | | -const { Browser } = require('selenium-webdriver') |
22 | | -const { Pages, suite } = require('../../lib/test') |
23 | | -const until = require('selenium-webdriver/lib/until') |
| 21 | +const {Browser} = require('selenium-webdriver') |
| 22 | +const {Pages, suite} = require('../../lib/test') |
| 23 | +const {By} = require("../../index"); |
24 | 24 |
|
25 | 25 | suite( |
26 | | - function (env) { |
27 | | - let driver |
| 26 | + function (env) { |
| 27 | + let driver |
28 | 28 |
|
29 | | - beforeEach(async function () { |
30 | | - driver = await env.builder().build() |
31 | | - }) |
| 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 mangement 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() |
32 | 154 |
|
33 | | - afterEach(async function () { |
34 | | - await driver.quit() |
35 | | - }) |
| 155 | + assert.equal(accounts.length, 2) |
36 | 156 |
|
37 | | - describe('Federated Credential Management Tess', function () { |
38 | | - it('dailog test', async function () { |
| 157 | + const account1 = accounts[0] |
| 158 | + const account2 = accounts[1] |
39 | 159 |
|
40 | | - await driver.get(Pages.fedcm) |
| 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"); |
41 | 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 | + }) |
42 | 180 | }) |
43 | | - }) |
44 | | - }, |
45 | | - { browsers: [Browser.CHROME] }, |
| 181 | + }, |
| 182 | + {browsers: [Browser.CHROME]}, |
46 | 183 | ) |
0 commit comments