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