Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove iPerceptions Modal in Puppeteer e2e and visual regression tests
// 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;
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