Last active
June 8, 2020 14:03
-
-
Save corradin/63c61e3e37ed4f9f39e55be604a74d23 to your computer and use it in GitHub Desktop.
Playwright
This file contains hidden or 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 { 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(); | |
| }); | |
| }); |
This file contains hidden or 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
| 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!' | |
| ); | |
| }); |
This file contains hidden or 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
| browser = await chromium.launch({ headless: false, slowMo: 100 }); |
This file contains hidden or 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
| 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); | |
| }); |
This file contains hidden or 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
| 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(); | |
| }); |
This file contains hidden or 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
| <!-- Strangely styled link --> | |
| <div style="width: 400px; margin-top: 16px"> | |
| <a href="http://www.google.com" id="unclickable_link">OK</a> | |
| </div> |
This file contains hidden or 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
| exports.config = { | |
| allScriptsTimeout: 11000, | |
| specs: [ | |
| './src/**/*playwright.e2e-spec.ts' | |
| ], |
This file contains hidden or 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
| 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