Path: blob/trunk/javascript/selenium-webdriver/test/fedcm/fedcm_test.js
2885 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'1819const assert = require('node:assert')20const { Browser } = require('selenium-webdriver')21const { Pages, suite } = require('../../lib/test')22const { By } = require('selenium-webdriver/index')2324suite(25function (env) {26let driver2728beforeEach(async function () {29driver = await env.builder().build()30})3132afterEach(async function () {33await driver.quit()34})3536describe('Federated Credential Management Test', function () {37it('credential management dialog should appear', async function () {38await driver.get(Pages.fedcm)3940let triggerButton = await driver.findElement(By.id('triggerButton'))41await triggerButton.click()4243let dialog4445await driver.wait(46async () => {47try {48dialog = await driver.getFederalCredentialManagementDialog()49return (await dialog.type()) === 'AccountChooser'50} catch (error) {51return false52}53},5410000,55'Expected dialog type to be "AccountChooser"',562000,57)5859assert.equal(await dialog.type(), 'AccountChooser')60let title = await dialog.title()61assert.equal(title.includes('Sign in to'), true)62})6364it('can dismiss dialog', async function () {65await driver.get(Pages.fedcm)6667let triggerButton = await driver.findElement(By.id('triggerButton'))68await triggerButton.click()6970let dialog = await driver.getFederalCredentialManagementDialog()7172await driver.wait(73async () => {74try {75return (await dialog.type()) === 'AccountChooser'76} catch (error) {77return false78}79},8010000,81'Expected dialog type to be "AccountChooser"',822000,83)8485assert.equal(await dialog.type(), 'AccountChooser')86let title = await dialog.title()87assert.equal(title.includes('Sign in to'), true)8889await dialog.dismiss()9091try {92await dialog.type()93assert.fail('Above command should throw error')94} catch (error) {95assert.equal(error.message.includes('no such alert'), true)96}97})9899it('can select account', async function () {100await driver.get(Pages.fedcm)101102let triggerButton = await driver.findElement(By.id('triggerButton'))103await triggerButton.click()104105let dialog = await driver.getFederalCredentialManagementDialog()106107await driver.wait(108async () => {109try {110return (await dialog.type()) === 'AccountChooser'111} catch (error) {112return false113}114},11510000,116'Expected dialog type to be "AccountChooser"',1172000,118)119120assert.equal(await dialog.type(), 'AccountChooser')121let title = await dialog.title()122assert.equal(title.includes('Sign in to'), true)123124await dialog.selectAccount(1)125})126127it('can get account list', async function () {128await driver.get(Pages.fedcm)129130let triggerButton = await driver.findElement(By.id('triggerButton'))131await triggerButton.click()132133let dialog = await driver.getFederalCredentialManagementDialog()134135await driver.wait(136async () => {137try {138return (await dialog.type()) === 'AccountChooser'139} catch (error) {140return false141}142},14310000,144'Expected dialog type to be "AccountChooser"',1452000,146)147148assert.equal(await dialog.type(), 'AccountChooser')149let title = await dialog.title()150assert.equal(title.includes('Sign in to'), true)151152const accounts = await dialog.accounts()153154assert.equal(accounts.length, 2)155156const account1 = accounts[0]157const account2 = accounts[1]158159assert.strictEqual(account1.name, 'John Doe')160assert.strictEqual(account1.email, '[email protected]')161assert.strictEqual(account1.accountId, '1234')162assert.strictEqual(account1.givenName, 'John')163assert(account1.idpConfigUrl.includes('/fedcm/config.json'), true)164assert.strictEqual(account1.pictureUrl, 'https://idp.example/profile/123')165assert.strictEqual(account1.loginState, 'SignUp')166assert.strictEqual(account1.termsOfServiceUrl, 'https://rp.example/terms_of_service.html')167assert.strictEqual(account1.privacyPolicyUrl, 'https://rp.example/privacy_policy.html')168169assert.strictEqual(account2.name, 'Aisha Ahmad')170assert.strictEqual(account2.email, '[email protected]')171assert.strictEqual(account2.accountId, '5678')172assert.strictEqual(account2.givenName, 'Aisha')173assert(account2.idpConfigUrl.includes('/fedcm/config.json'), true)174assert.strictEqual(account2.pictureUrl, 'https://idp.example/profile/567')175assert.strictEqual(account2.loginState, 'SignUp')176assert.strictEqual(account2.termsOfServiceUrl, 'https://rp.example/terms_of_service.html')177assert.strictEqual(account2.privacyPolicyUrl, 'https://rp.example/privacy_policy.html')178})179})180},181{ browsers: [Browser.CHROME, Browser.EDGE] },182)183184185