Skip to content

Instantly share code, notes, and snippets.

@jcdalton2201
Created October 7, 2019 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcdalton2201/84b1d15d8dac46ad0635ede777bd50bb to your computer and use it in GitHub Desktop.
Save jcdalton2201/84b1d15d8dac46ad0635ede777bd50bb to your computer and use it in GitHub Desktop.
Jasmine test for button
describe('Visual regression Test for Simple Button', () => {
let browser = null;
let page = null;
afterEach(async () => {
await page.evaluate(element => {
element.innerHTML = '';
}, bodyhandle);
await page.close();
await browser.close();
});
it('Test hover on button will turn it green', async () => {
const Differencify = require('differencify');
const differencify = new Differencify({});
browser = differencify.init({
testName: 'Test hover on button will turn it green',
chain: false,
headless: true,
});
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
await browser.launch();
page = await browser.newPage();
await page.setBypassCSP(true);
await page.setViewport({ width: 1600, height: 1200 });
await page.addScriptTag({ path: 'SimpleButton.js' });
const bodyhandle = await page.$('body');
await page.evaluate(element => {
element.innerHTML = `<simple-button >Test Button</simple-button>`;
}, bodyhandle);
const result1 = await browser.toMatchSnapshot(image);
expect(result1).toBeTruthy();
const button = await page.evaluateHandle(() => {
const btn = document
.querySelector('simple-button')
.shadowRoot.querySelector('button');
return btn;
});
await button.hover();
await page.waitFor(2000);
const image = await page.screenshot({ path: 'hover.png' });
const result2 = await browser.toMatchSnapshot(image);
expect(result2).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment