Last active
July 16, 2019 13:34
-
-
Save Xotabu4/0b592ce051cd8e702f3ad10fdf358596 to your computer and use it in GitHub Desktop.
Protractor Page Object with ShadowDOM example. Uses Protractor By.js - http://www.protractortest.org/#/api?view=webdriver.By.js
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
import { browser, By, element, ElementFinder, ExpectedConditions as EC } from 'protractor'; | |
class LoginModal { | |
private get shadowDOM() { | |
return element(By.js(function () { | |
// returned value must be array | |
return [document.querySelector('CSSselectorForShadowDomContainingElement').shadowRoot]; | |
})); | |
} | |
async login(user: User): Promise<void> { | |
const email: ElementFinder = this.shadowDOM.$('#login_username'); | |
await email.sendKeys(user.email); | |
const password: ElementFinder = this.shadowDOM.$('#login_password'); | |
await password.sendKeys(user.password); | |
const loginButton: ElementFinder = this.shadowDOM.$('button[type="submit"]'); | |
await loginButton.click(); | |
} | |
} | |
export { LoginModal }; |
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
import { browser, By, element, ElementFinder, ExpectedConditions as EC } from 'protractor'; | |
class LoginModal { | |
private email: ElementFinder = this.shadowDOM.$('#login_username'); | |
private password: ElementFinder = this.shadowDOM.$('#login_password'); | |
private loginButton: ElementFinder = this.shadowDOM.$('button[type="submit"]'); | |
private get shadowDOM() { | |
return element(By.js(function () { | |
// returned value must be array | |
return [document.querySelector('CSSselectorForShadowDomContainingElement').shadowRoot]; | |
})); | |
} | |
async login(user: User): Promise<void> { | |
await this.email.sendKeys(user.email); | |
await this.password.sendKeys(user.password); | |
await this.loginButton.click(); | |
} | |
} | |
export { LoginModal }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment