Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 11, 2021. It is now read-only.

Commit cd2975b

Browse files
authored
docs(readme): skip with annotations (#173)
1 parent b51a775 commit cd2975b

File tree

1 file changed

+51
-31
lines changed

1 file changed

+51
-31
lines changed

README.md

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Playwright test runner is **available in preview** and minor breaking changes co
1515
- [Visual comparisons](#visual-comparisons)
1616
- [Configuration](#configuration)
1717
- [Modify context options](#modify-context-options)
18-
- [JUnit reporter](#junit-reporter)
18+
- [Skip tests with annotations](#skip-tests-with-annotations)
19+
- [Export JUnit report](#export-junit-report)
1920

2021
## Get started
2122

@@ -30,12 +31,12 @@ npm i -D @playwright/test
3031
Create `foo.spec.ts` to define your test. The test function uses the [`page`](https://playwright.dev/#path=docs%2Fapi.md&q=class-page) argument for browser automation.
3132

3233
```js
33-
import { it, expect } from '@playwright/test';
34+
import { it, expect } from "@playwright/test";
3435

35-
it('is a basic test with the page', async ({ page }) => {
36-
await page.goto('https://playwright.dev/');
37-
const name = await page.innerText('.home-navigation');
38-
expect(name).toBe('🎭 Playwright');
36+
it("is a basic test with the page", async ({ page }) => {
37+
await page.goto("https://playwright.dev/");
38+
const name = await page.innerText(".home-navigation");
39+
expect(name).toBe("🎭 Playwright");
3940
});
4041
```
4142

@@ -55,10 +56,10 @@ The test runner provides browser primitives as arguments to your test functions.
5556
- For assertions, use the [`expect` API](https://jestjs.io/docs/en/expect).
5657

5758
```js
58-
const { it, describe } = require('@playwright/test');
59+
const { it, describe } = require("@playwright/test");
5960

60-
describe('feature foo', () => {
61-
it('is working correctly', async ({ page }) => {
61+
describe("feature foo", () => {
62+
it("is working correctly", async ({ page }) => {
6263
// Test function
6364
});
6465
});
@@ -78,12 +79,18 @@ npx folio --param browserName=chromium
7879
# Run all tests in headful mode
7980
npx folio --param headful
8081

82+
# Run tests with slowMo (slows down Playwright operations by n milliseconds)
83+
npx folio --param slowMo=100
84+
8185
# Save screenshots on failure in test-results directory
8286
npx folio --param screenshotOnFailure
8387

8488
# Record videos
8589
npx folio --param video
8690

91+
# Retry test failures
92+
npx folio --retries 3
93+
8794
# See all options
8895
npx folio --help
8996
```
@@ -111,9 +118,9 @@ Save the run command as an NPM script.
111118
The default `context` argument is a [BrowserContext][browser-context]. Browser contexts are isolated execution environments that can host multiple pages. See [multi-page scenarios][multi-page] for more examples.
112119

113120
```js
114-
import { it } from '@playwright/test';
121+
import { it } from "@playwright/test";
115122

116-
it('tests on multiple web pages', async ({ context }) => {
123+
it("tests on multiple web pages", async ({ context }) => {
117124
const pageFoo = await context.newPage();
118125
const pageBar = await context.newPage();
119126
// Test function
@@ -125,19 +132,19 @@ it('tests on multiple web pages', async ({ context }) => {
125132
The `contextOptions` fixture defines default options used for context creation. This fixture can be overriden to configure mobile emulation in the default `context`.
126133

127134
```js
128-
import { folio } from '@playwright/test';
129-
import { devices } from 'playwright';
135+
import { folio } from "@playwright/test";
136+
import { devices } from "playwright";
130137

131138
const fixtures = folio.extend();
132139
fixtures.contextOptions.override(async ({ contextOptions }, runTest) => {
133140
await runTest({
134141
...contextOptions,
135-
...devices['iPhone 11']
142+
...devices["iPhone 11"]
136143
});
137144
});
138145
const { it, describe, extend } = fixtures.build();
139146

140-
it('uses mobile emulation', async ({ context }) => {
147+
it("uses mobile emulation", async ({ context }) => {
141148
// Test function
142149
});
143150
```
@@ -148,8 +155,8 @@ Define a custom argument that mocks networks call for a browser context.
148155

149156
```js
150157
// In fixtures.ts
151-
import { folio as base } from '@playwright/test';
152-
import { BrowserContext } from 'playwright';
158+
import { folio as base } from "@playwright/test";
159+
import { BrowserContext } from "playwright";
153160

154161
// Extend base fixtures with a new test-level fixture
155162
const fixtures = base.extend<{ mockedContext: BrowserContext }>();
@@ -166,12 +173,12 @@ export folio = fixtures.build();
166173

167174
```js
168175
// In foo.spec.ts
169-
import { folio } from './fixtures';
176+
import { folio } from "./fixtures";
170177
const { it, expect } = folio;
171178

172-
it('loads pages without css requests', async ({ mockedContext }) => {
179+
it("loads pages without css requests", async ({ mockedContext }) => {
173180
const page = await mockedContext.newPage();
174-
await page.goto('https://stackoverflow.com');
181+
await page.goto("https://stackoverflow.com");
175182
// Test function code
176183
});
177184
```
@@ -181,10 +188,10 @@ it('loads pages without css requests', async ({ mockedContext }) => {
181188
The `expect` API supports visual comparisons with `toMatchSnapshot`. This uses the [pixelmatch](https://github.com/mapbox/pixelmatch) library, and you can pass `threshold` as an option.
182189

183190
```js
184-
import { it, expect } from '@playwright/test';
191+
import { it, expect } from "@playwright/test";
185192

186-
it('compares page screenshot', async ({ page, browserName }) => {
187-
await page.goto('https://stackoverflow.com');
193+
it("compares page screenshot", async ({ page, browserName }) => {
194+
await page.goto("https://stackoverflow.com");
188195
const screenshot = await page.screenshot();
189196
expect(screenshot).toMatchSnapshot(`test-${browserName}.png`, { threshold: 0.2 });
190197
});
@@ -209,7 +216,7 @@ You can modify the built-in fixtures. This example modifies the default `context
209216

210217
```ts
211218
// test/fixtures.ts
212-
import { folio as baseFolio } from '@playwright/test';
219+
import { folio as baseFolio } from "@playwright/test";
213220

214221
const builder = baseFolio.extend();
215222

@@ -222,8 +229,8 @@ const folio = builder.build();
222229

223230
```diff
224231
// test/fixtures.ts
225-
import { folio as baseFolio } from '@playwright/test';
226-
+ import { BrowserContextOptions } from 'playwright';
232+
import { folio as baseFolio } from "@playwright/test";
233+
+ import { BrowserContextOptions } from "playwright";
227234

228235
const builder = baseFolio.extend();
229236

@@ -243,8 +250,8 @@ const folio = builder.build();
243250

244251
```diff
245252
// test/fixtures.ts
246-
import { folio as baseFolio } from '@playwright/test';
247-
import { BrowserContextOptions } from 'playwright';
253+
import { folio as baseFolio } from "@playwright/test";
254+
import { BrowserContextOptions } from "playwright";
248255

249256
const builder = baseFolio.extend();
250257

@@ -267,12 +274,24 @@ const folio = builder.build();
267274
import { it, expect } from "./fixtures";
268275

269276
// Test functions go here
270-
it('should have modified viewport', async ({ context }) => {
277+
it("should have modified viewport", async ({ context }) => {
271278
// ...
272279
});
273280
```
274281

275-
### JUnit reporter
282+
### Skip tests with annotations
283+
284+
The Playwright test runner can annotate tests to skip under certain parameters. This is enabled by [Folio annotations][folio-annotations].
285+
286+
```js
287+
it("should be skipped on firefox", (test, { browserName }) => {
288+
test.skip(browserName === "firefox", "optional description for the skip")
289+
}, async ({ page, browserName }) => {
290+
// Test function
291+
});
292+
```
293+
294+
### Export JUnit report
276295

277296
The Playwright test runner supports various reporters, including exporting as a JUnit compatible XML file.
278297

@@ -293,4 +312,5 @@ npx folio --help
293312
[browser-opts]: https://playwright.dev/#path=docs%2Fapi.md&q=browsertypelaunchoptions
294313
[context-opts]: https://playwright.dev/#path=docs%2Fapi.md&q=browsernewcontextoptions
295314
[multi-page]: https://playwright.dev/#path=docs%2Fmulti-pages.md&q=
296-
[browser-context]: https://playwright.dev/#path=docs%2Fapi.md&q=class-browsercontext
315+
[browser-context]: https://playwright.dev/#path=docs%2Fapi.md&q=class-browsercontext
316+
[folio-annotations]: https://github.com/microsoft/folio#annotations

0 commit comments

Comments
 (0)