Last active
July 11, 2019 10:27
-
-
Save HyunSeob/3204ff30b57fc423baef951fe6513220 to your computer and use it in GitHub Desktop.
Puppeteer & Jest: Describe "google.com"
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 myAccount = require('../google-account.js'); | |
jest.setTimeout(30000); | |
let browser = null; | |
let signContext = null; | |
beforeAll(async () => { | |
browser = await puppeteer.launch({ headless: false }); | |
signContext = await browser.createIncognitoBrowserContext(); | |
}); | |
describe('google.com', () => { | |
let page = null; | |
beforeEach(async () => { | |
page = await signContext.newPage(); | |
await page.setViewport({ | |
width: 1200, | |
height: 800, | |
}); | |
// Google 접속 | |
await page.goto('https://google.com'); | |
}); | |
afterEach(async () => { | |
await page.close(); | |
}); | |
test('로그인', async () => { | |
// 로그인 페이지로 이동 | |
await page.click('#gb_70'); | |
await page.waitForNavigation(); | |
// 이메일 타이핑 및 다음 | |
await page.type('#identifierId', myAccount.email); | |
await page.click('#identifierNext'); | |
await page.waitForNavigation(); | |
// 패스워드 타이핑 및 다음 | |
await page.waitForSelector('input[type="password"]', { | |
visible: true, | |
}); | |
await page.type('input[type="password"]', myAccount.password); | |
await page.click('#passwordNext'); | |
await page.waitForNavigation(); | |
await page.waitForSelector('a[title^="Google 계정"]', { | |
visible: true, | |
}); | |
// 로그인 체크 | |
const buttonTitle = await page.$eval('a[title^="Google 계정"]', button => button.title); | |
expect(buttonTitle).toContain(myAccount.email); | |
}); | |
test('로그아웃', async () => { | |
const nextPage = await page.$eval('a[title^="Google 계정"]', button => button.href); | |
await page.goto(nextPage); | |
await page.click('#signout'); | |
await page.waitForNavigation(); | |
const buttonText = await page.$eval('#gb_70', button => button.textContent); | |
expect(buttonText).toBe('로그인'); | |
}); | |
}); | |
afterAll(() => { | |
browser.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment