diff --git a/docs/src/library-js.md b/docs/src/library-js.md index 95e5e67869..4e978ed468 100644 --- a/docs/src/library-js.md +++ b/docs/src/library-js.md @@ -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 diff --git a/docs/src/puppeteer-js.md b/docs/src/puppeteer-js.md index 9ec95b063d..a0634b0e9a 100644 --- a/docs/src/puppeteer-js.md +++ b/docs/src/puppeteer-js.md @@ -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. diff --git a/docs/src/test-runners-js.md b/docs/src/test-runners-js.md deleted file mode 100644 index a8f1e36263..0000000000 --- a/docs/src/test-runners-js.md +++ /dev/null @@ -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. - - - -## 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. -