docs: remove third party js runners doc (#20405)

Fixes: https://github.com/microsoft/playwright/issues/20390

We are doing such a bad job documenting these third party approaches
that they bring more harm than benefit. We should let respective
integration owners own the documentation and link to it. I'll remove it
altogether for now.
This commit is contained in:
Pavel Feldman 2023-01-26 10:05:11 -08:00 committed by GitHub
parent ccb53c2c1b
commit 841ac6ecb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 144 deletions

View File

@ -7,11 +7,6 @@ Playwright Library provides unified APIs for launching and interacting with brow
Under most circumstances, for end-to-end testing, you'll want to use `@playwright/test` (Playwright Test), and not `playwright` (Playwright Library) directly. To get started with Playwright Test, follow the [Getting Started Guide](./intro.md).
## When Should Playwright Library Be Used Directly?
- Creating an integration for a third party test runner. For example, third-party runner plugins listed [here](./test-runners.md) are built on top of the Playwright Library.
- Automation and scraping.
## Differences when using library
### Library Example

View File

@ -143,8 +143,6 @@ Playwright Test creates an isolated [Page] object for each test. However, if you
## Testing
With a few lines of code, you can hook up Playwright to your existing JavaScript [test runner](./test-runners).
To improve testing, it is advised to use [Locators](./api/class-locator) and web-first [Assertions](./test-assertions). See [Writing Tests](./writing-tests)
It is common with Puppeteer to use `page.evaluate()` or `page.$eval()` to inspect an [ElementHandle] and extract the value of text content, attribute, class... Web-first [Assertions](./test-assertions) offers several matchers for this purpose, it is more reliable and readable.

View File

@ -1,137 +0,0 @@
---
id: test-runners
title: "Third party runners"
---
With a few lines of code, you can hook up Playwright to your existing JavaScript test runner.
<!-- TOC -->
## Playwright Test
[Playwright Test](./intro.md) is our first-party recommended test runner to be used with Playwright. Learn more about it [here](./intro.md).
## Jest / Jasmine
For Jest, [jest-playwright](https://github.com/playwright-community/jest-playwright) can be used. However for a light-weight solution, requiring playwright directly works fine. Jest shares it's syntax with Jasmine, so this applies to Jasmine as well.
```js
const {chromium} = require('playwright');
const expect = require('expect');
let browser;
let page;
beforeAll(async () => {
browser = await chromium.launch();
});
afterAll(async () => {
await browser.close();
});
beforeEach(async () => {
page = await browser.newPage();
});
afterEach(async () => {
await page.close();
});
it('should work', async () => {
await page.goto('https://www.example.com/');
expect(await page.title()).toBe('Example Domain');
});
```
## AVA
Tests run concurrently in AVA, so a single page variable cannot be shared between tests. Instead, create new pages with a macro function.
```js
const {chromium} = require('playwright');
const test = require('ava').default;
const browserPromise = chromium.launch();
async function pageMacro(t, callback) {
const browser = await browserPromise;
const page = await browser.newPage();
try {
await callback(t, page);
} finally {
await page.close();
}
}
test('should work', pageMacro, async (t, page) => {
await page.goto('https://www.example.com/');
t.is(await page.title(), 'Example Domain');
});
```
## Mocha
Mocha looks very similar to the Jest/Jasmine setup, and functions in the same way.
```js
const {chromium} = require('playwright');
const assert = require('assert');
let browser;
before(async() => {
browser = await chromium.launch();
});
after(async () => {
await browser.close();
});
let page;
beforeEach(async() => {
page = await browser.newPage();
});
afterEach(async () => {
await page.close();
});
it('should work', async () => {
await page.goto('https://www.example.com/');
assert.equal(await page.title(), 'Example Domain');
});
```
## Vitest
Vitest looks very similar to the Jest/Jasmine setup, and functions in the same way.
```js
import { chromium } from 'playwright';
import { afterAll, afterEach, beforeAll, beforeEach, expect, test } from 'vitest';
let browser;
let page;
beforeAll(async () => {
browser = await chromium.launch();
});
afterAll(async () => {
await browser.close();
});
beforeEach(async () => {
page = await browser.newPage();
});
afterEach(async () => {
await page.close();
});
test('should work', async () => {
await page.goto('https://www.example.com/');
expect(await page.title()).toBe('Example Domain');
});
```
## Multiple Browsers
These simple examples can be extended to support multiple browsers using an environment variable.
```js
const {chromium, webkit, firefox} = require('playwright');
const browserName = process.env.BROWSER || 'webkit';
let browser;
beforeAll(async() => {
browser = await {chromium, webkit, firefox}[browserName].launch();
});
```
Then set `BROWSER=firefox` to run your tests with firefox, or any other browser.