// Takes a screenshot, compares
async function screenshotAndCompares (page, target) {
const image = await page.screenshot();
await target.toMatchSnapshot(image);
};
describe('tests', () => {
beforeAll(async () => {
await differencify
.launchBrowser();
});
afterAll(async () => {
await differencify.cleanup();
});
it('test 1', async () => {
const target = differencify.init({ chain: false });
await target.launch();
const page = await target.newPage();
await page.setViewport({ width: 400, height: 600 });
// URL : does not change from one page to another
// we advance from one page to another by clicking on a button
await page.goto('https://Mypage.com')
await page.waitForSelector('#homePage');
await page.waitFor(1000)
// Takes a screenshot, compares
await screenshotAndCompares(page, target);
}, 60 * 1000); // 60 is the timeout in seconds
it('test 2', async () => {
/*
here I must continue the course I must not start from the beginning
example:
test 1 = - go to https://Mypage.com
- take screenshot of the home page of my web page
test 2 = - connect to the application
- take a screenshot of the welcome page of the application
test 3 = - click on start
- Take in screenshot the question page 1
test 4 = - click next
- take in screenshot the question page 2
*/
// connect to the application
//you can log in only once with the same email adresse and at each connection you start from the beginning
await page.waitForSelector('#input_login');
await page.click('#input_login');
await page.type('#input_login', 'Tests@tests.com');
await page.waitForSelector('#button_login');
await page.click('#button_login');
// Takes a screenshot, compares
await screenshotAndCompares(page, target);
}, 60 * 1000); // 60 is the timeout in seconds
it('test 3', async () => {
//click on start : directs you to the question page 1
await page.waitForSelector('#button_start');
await page.click('#button_start');
// Takes a screenshot, compares
await screenshotAndCompares(page, target);
}, 60 * 1000); // 60 is the timeout in seconds
it('test 4', async () => {
//click on next : directs you to the question page 2
await page.waitForSelector('#button_next');
await page.click('#button_next');
// Takes a screenshot, compares
await screenshotAndCompares(page, target);
}, 60 * 1000); // 60 is the timeout in seconds
//close page
});
I want to recover several screenshots in separate tests like this
`const Differencify = require('differencify'); const differencify = new Differencify({ debug: true });
// Takes a screenshot, compares async function screenshotAndCompares (page, target) { const image = await page.screenshot(); await target.toMatchSnapshot(image);
};
`