-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some redirect webdriver tests (#4589)
* Add some redirect webdriver tests * Formatting * Fix linter issue * PR feedback
- Loading branch information
Showing
7 changed files
with
194 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages-exp/auth-exp/test/integration/webdriver/redirect.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { OperationType, UserCredential } from '@firebase/auth-exp'; | ||
import { expect } from 'chai'; | ||
import { TestFunction } from './util/auth_driver'; | ||
import { IdPPage } from './util/idp_page'; | ||
import { browserDescribe } from './util/test_runner'; | ||
|
||
browserDescribe('WebDriver redirect IdP test', driver => { | ||
it('allows users to sign in', async () => { | ||
await driver.pause(200); // Race condition on auth init | ||
await driver.callNoWait(TestFunction.IDP_REDIRECT); | ||
const widget = new IdPPage(driver.webDriver); | ||
|
||
// We're now on the widget page; wait for load | ||
await widget.pageLoad(); | ||
await widget.clickAddAccount(); | ||
await widget.fillEmail('bob@bob.test'); | ||
await widget.fillDisplayName('Bob Test'); | ||
await widget.fillScreenName('bob.test'); | ||
await widget.fillProfilePhoto('http://bob.test/bob.png'); | ||
await widget.clickSignIn(); | ||
|
||
await driver.reinitOnRedirect(); | ||
|
||
const currentUser = await driver.getUserSnapshot(); | ||
expect(currentUser.email).to.eq('bob@bob.test'); | ||
expect(currentUser.displayName).to.eq('Bob Test'); | ||
expect(currentUser.photoURL).to.eq('http://bob.test/bob.png'); | ||
|
||
const redirectResult: UserCredential = await driver.call( | ||
TestFunction.REDIRECT_RESULT | ||
); | ||
expect(redirectResult.operationType).to.eq(OperationType.SIGN_IN); | ||
expect(redirectResult.user).to.eql(currentUser); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages-exp/auth-exp/test/integration/webdriver/util/idp_page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { By, until, WebDriver } from 'selenium-webdriver'; | ||
import { JsLoadCondition } from './js_load_condition'; | ||
|
||
const ADD_ACCOUNT_BUTTON = By.css('.js-new-account'); | ||
const SIGN_IN_BUTTON = By.id('sign-in'); | ||
const EMAIL_INPUT = By.id('email-input'); | ||
const DISPLAY_NAME_INPUT = By.id('display-name-input'); | ||
const SCREEN_NAME_INPUT = By.id('screen-name-input'); | ||
const PROFILE_PHOTO_INPUT = By.id('profile-photo-input'); | ||
|
||
export class IdPPage { | ||
static PAGE_TITLE = 'Auth Emulator IDP Login Widget'; | ||
|
||
constructor(private readonly driver: WebDriver) {} | ||
|
||
async pageLoad(): Promise<void> { | ||
await this.driver.wait(until.titleContains('Auth Emulator')); | ||
await this.driver.wait(new JsLoadCondition('toggleForm')); | ||
} | ||
|
||
async clickAddAccount(): Promise<void> { | ||
await this.driver.wait(until.elementLocated(ADD_ACCOUNT_BUTTON)); | ||
await this.driver.findElement(ADD_ACCOUNT_BUTTON).click(); | ||
} | ||
|
||
async clickSignIn(): Promise<void> { | ||
await this.driver.wait(until.elementLocated(SIGN_IN_BUTTON)); | ||
const button = await this.driver.findElement(SIGN_IN_BUTTON); | ||
await this.driver.wait(until.elementIsEnabled(button)); | ||
await button.click(); | ||
} | ||
|
||
fillEmail(email: string): Promise<void> { | ||
return this.fillInput(EMAIL_INPUT, email); | ||
} | ||
|
||
fillDisplayName(displayName: string): Promise<void> { | ||
return this.fillInput(DISPLAY_NAME_INPUT, displayName); | ||
} | ||
|
||
fillScreenName(screenName: string): Promise<void> { | ||
return this.fillInput(SCREEN_NAME_INPUT, screenName); | ||
} | ||
|
||
fillProfilePhoto(prophilePhoto: string): Promise<void> { | ||
return this.fillInput(PROFILE_PHOTO_INPUT, prophilePhoto); | ||
} | ||
|
||
private async fillInput(input: By, text: string): Promise<void> { | ||
await this.driver.wait(until.elementLocated(input)); | ||
const el = await this.driver.findElement(input); | ||
await el.click(); | ||
await el.sendKeys(text); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages-exp/auth-exp/test/integration/webdriver/util/js_load_condition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Condition } from 'selenium-webdriver'; | ||
|
||
/** | ||
* A condition that looks for the presence of a specified function. This is | ||
* used with WebDriver .wait() as a proxy for determining when the JS has | ||
* finished loading in a page. | ||
*/ | ||
export class JsLoadCondition extends Condition<boolean> { | ||
constructor(globalValue: string) { | ||
super(`Waiting for global value ${globalValue}`, driver => { | ||
return driver.executeScript( | ||
`return typeof ${globalValue} !== 'undefined';` | ||
); | ||
}); | ||
} | ||
} |