Skip to content

Instantly share code, notes, and snippets.

@corradin
Last active June 8, 2020 14:03
Show Gist options
  • Save corradin/63c61e3e37ed4f9f39e55be604a74d23 to your computer and use it in GitHub Desktop.
Save corradin/63c61e3e37ed4f9f39e55be604a74d23 to your computer and use it in GitHub Desktop.
Playwright
import { chromium, Browser, Page } from 'playwright';
describe('Angular app homepage', () => {
let browser: Browser;
let page: Page;
beforeAll(async () => {
browser = await chromium.launch({ headless: false });
page = await browser.newPage();
});
it('Should display the correct page title', async () => {
await page.goto('http://localhost:4200');
expect(await page.title()).toBe('MyAngular9AppPlaywright');
});
afterAll(async () => {
await browser.close();
});
});
it('should display welcome message', async () => {
await page.goto('http://localhost:4200');
const titleBannerContents = await page.$eval(
'app-root .content span',
(el: HTMLElement) => el.innerText
);
expect(titleBannerContents).toBe(
'my-angular9-app-playwright app is running!'
);
});
browser = await chromium.launch({ headless: false, slowMo: 100 });
it('should display the full link on mobile', async () => {
await page.goto('http://localhost:4200');
const checked = await page.click('#unclickable_link');
console.log(checked);
});
beforeAll(async () => {
browser = await chromium.launch({ headless: false });
//With Galaxy S5 The third test will fail
const galaxyS5 = devices['Galaxy S5'];
const context = await browser.newContext({
...galaxyS5,
});
page = await context.newPage();
});
<!-- Strangely styled link -->
<div style="width: 400px; margin-top: 16px">
<a href="http://www.google.com" id="unclickable_link">OK</a>
</div>
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*playwright.e2e-spec.ts'
],
capabilities: {
chromeOptions: {
args: [ "--headless" ] //So we only display Playwright screens
},
browserName: 'chrome'
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment