Created
October 21, 2020 15:06
-
-
Save martinratinaud/4c7862c197311ff3726f739ac8e2411e to your computer and use it in GitHub Desktop.
puppeteer - login in with Google
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
const puppeteer = require('puppeteer'); | |
const assert = require('assert'); | |
const BASEURL="https://www.something.com" | |
(async () => { | |
const browser = await puppeteer.launch({ | |
headless: process.env.CI === 'true', | |
slowMo: 20, | |
devtools: process.env.CI !== 'true', | |
args: [ | |
'--no-sandbox', | |
'--disable-setuid-sandbox', | |
'--disable-gpu', | |
'--disable-dev-shm-usage', | |
'--disable-web-security', | |
], | |
}); | |
const page = await browser.newPage(); | |
await page.setViewport({ width: 1280, height: 800 }); | |
await page.goto(BASEURL); | |
console.log(`Url ${BASEURL} loaded`); | |
const popupPromise = new Promise((x) => page.once('popup', x)); | |
await page.waitForSelector('button:not(:disabled)'); | |
await page.click('button'); | |
const popupPage = await popupPromise; | |
await popupPage.waitForSelector('input[type="email"]'); | |
console.log(`Popup loaded`); | |
const isHookedLoginPage = (await popupPage.content()).includes('hooked.media'); | |
const loginInput = isHookedLoginPage ? process.env.TEST_LOGIN_USER : `${process.env.TEST_LOGIN_USER}@hooked.co`; | |
const loginButtonSelector = isHookedLoginPage ? '#identifierNext' : '#next'; | |
const submitButtonSelector = isHookedLoginPage ? '#passwordNext' : '#submit'; | |
await popupPage.waitForSelector(loginButtonSelector); | |
await popupPage.type(`input[type="email"]`, loginInput); | |
await popupPage.click(loginButtonSelector); | |
await popupPage.waitForSelector('input[type="password"]', { visible: true }); | |
await popupPage.waitForSelector(submitButtonSelector, { visible: true }); | |
await popupPage.type('input[type="password"]', process.env.TEST_LOGIN_PWD); | |
await popupPage.click(submitButtonSelector); | |
await page.waitForSelector('main.main'); | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment