2019-01-30 15:47:03 +00:00
|
|
|
import Speakeasy from "speakeasy";
|
|
|
|
import SeleniumWebdriver, { WebDriver } from 'selenium-webdriver';
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
export default async function(driver: WebDriver, secret: string, timeout: number = 5000) {
|
2019-01-30 15:47:03 +00:00
|
|
|
const token = Speakeasy.totp({
|
|
|
|
secret: secret,
|
|
|
|
encoding: "base32"
|
|
|
|
});
|
|
|
|
|
|
|
|
await driver.wait(SeleniumWebdriver.until.elementLocated(
|
2019-03-03 22:51:52 +00:00
|
|
|
SeleniumWebdriver.By.id("totp-token")), timeout)
|
2019-01-30 15:47:03 +00:00
|
|
|
await driver.findElement(SeleniumWebdriver.By.id("totp-token")).sendKeys(token);
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
const el = await driver.wait(SeleniumWebdriver.until.elementLocated(SeleniumWebdriver.By.id('totp-button')), timeout);
|
2019-01-30 15:47:03 +00:00
|
|
|
el.click();
|
|
|
|
}
|