Last active
July 30, 2018 03:05
-
-
Save bennewton999/e00dca728345183190a204ad2341bd97 to your computer and use it in GitHub Desktop.
Remove iPerceptions Modal in Puppeteer e2e and visual regression tests
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
// Checks for survey modal and clicks "NO" if it is on page during testing. | |
const checkForSurvey = async page => { | |
const SELECTOR = | |
'img[src="https://ips-invite.iperceptions.com/images/templates/Layer/theme1/no_1.png"]'; | |
if ((await page.$(SELECTOR)) !== null) { | |
await page.click(SELECTOR); | |
} | |
}; | |
export default checkForSurvey; |
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 puppeteer from 'puppeteer'; | |
import { toMatchImageSnapshot } from 'jest-image-snapshot'; | |
import config from './config'; | |
import checkForSurvey from './checkForSurvey'; | |
expect.extend({ toMatchImageSnapshot }); | |
let page; | |
let browser; | |
beforeAll(async () => { | |
browser = await puppeteer.launch({ | |
args: ['--no-sandbox', '--enable-features=NetworkService', '--ignore-certificate-errors', '--disable-web-security'], | |
headless: !config.showBrowser, | |
// slowMo: 80, | |
ignoreHTTPSErrors: true, | |
devtools: config.showDevtools | |
}); | |
page = await browser.newPage(); | |
}); | |
afterAll(async () => { | |
await browser.close(); | |
}); | |
describe('Visual Regression Test Home Page', () => { | |
test('Home page screenshot should match', async () => { | |
await page.setViewport({ width: 1280, height: 800 }); | |
await page.goto(config.homePageUrl); | |
// Check for iPerseption Survey Modal and close if it exists. | |
await checkForSurvey(page); | |
const screenshot = await page.screenshot(); | |
expect(screenshot).toMatchImageSnapshot(); | |
}); | |
test('Page 2 Page should match screenshot', async () => { | |
await page.click('.linkToPage2'); | |
await page.waitForNavigation(); | |
// Check for iPerseption Survey Modal and close if it exists. | |
await checkForSurvey(page); | |
const screenshot = await page.screenshot(); | |
expect(screenshot).toMatchImageSnapshot(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment