From ca479d8878a6025187ed2b60311402bfc9c8e0f4 Mon Sep 17 00:00:00 2001 From: "microsoft-playwright-automation[bot]" <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com> Date: Tue, 15 Apr 2025 10:09:20 +0000 Subject: [PATCH] feat(roll): roll to ToT Playwright (15-04-25) --- dotnet/docs/auth.mdx | 5 ++ java/docs/auth.mdx | 5 ++ nodejs/docs/api/class-testcase.mdx | 8 +-- nodejs/docs/api/class-testresult.mdx | 7 ++- nodejs/docs/auth.mdx | 5 ++ nodejs/docs/pom.mdx | 84 ++-------------------------- nodejs/docs/test-assertions.mdx | 9 ++- python/docs/auth.mdx | 5 ++ 8 files changed, 38 insertions(+), 90 deletions(-) diff --git a/dotnet/docs/auth.mdx b/dotnet/docs/auth.mdx index 767764d1b70..b852bb26e1c 100644 --- a/dotnet/docs/auth.mdx +++ b/dotnet/docs/auth.mdx @@ -16,6 +16,11 @@ Regardless of the authentication strategy you choose, you are likely to store au We recommend to create `playwright/.auth` directory and add it to your `.gitignore`. Your authentication routine will produce authenticated browser state and save it to a file in this `playwright/.auth` directory. Later on, tests will reuse this state and start already authenticated. +:::danger + +The browser state file may contain sensitive cookies and headers that could be used to impersonate you or your test account. We strongly discourage checking them into private or public repositories. +::: + Added in: v1.10testCase.annotations -The list of annotations applicable to the current test. Includes: -* annotations defined on the test or suite via [test()](/api/class-test.mdx#test-call) and [test.describe()](/api/class-test.mdx#test-describe); -* annotations implicitly added by methods [test.skip()](/api/class-test.mdx#test-skip), [test.fixme()](/api/class-test.mdx#test-fixme) and [test.fail()](/api/class-test.mdx#test-fail) prior to test execution. - -Annotations are available during test execution through [testInfo.annotations](/api/class-testinfo.mdx#test-info-annotations). - -Learn more about [test annotations](../test-annotations.mdx). +[testResult.annotations](/api/class-testresult.mdx#test-result-annotations) of the last test run. **Usage** diff --git a/nodejs/docs/api/class-testresult.mdx b/nodejs/docs/api/class-testresult.mdx index dc4c782bfec..aa31a771e8b 100644 --- a/nodejs/docs/api/class-testresult.mdx +++ b/nodejs/docs/api/class-testresult.mdx @@ -18,9 +18,10 @@ A result of a single [TestCase] run. Added in: v1.52testResult.annotations -The list of annotations appended during test execution. Includes: -* annotations implicitly added by methods [test.skip()](/api/class-test.mdx#test-skip), [test.fixme()](/api/class-test.mdx#test-fixme) and [test.fail()](/api/class-test.mdx#test-fail) during test execution; -* annotations appended to [testInfo.annotations](/api/class-testinfo.mdx#test-info-annotations). +The list of annotations applicable to the current test. Includes: +* annotations defined on the test or suite via [test()](/api/class-test.mdx#test-call) and [test.describe()](/api/class-test.mdx#test-describe); +* annotations implicitly added by methods [test.skip()](/api/class-test.mdx#test-skip), [test.fixme()](/api/class-test.mdx#test-fixme) and [test.fail()](/api/class-test.mdx#test-fail); +* annotations appended to [testInfo.annotations](/api/class-testinfo.mdx#test-info-annotations) during the test execution. Annotations are available during test execution through [testInfo.annotations](/api/class-testinfo.mdx#test-info-annotations). diff --git a/nodejs/docs/auth.mdx b/nodejs/docs/auth.mdx index 9a8cebcbe99..b5810db4e34 100644 --- a/nodejs/docs/auth.mdx +++ b/nodejs/docs/auth.mdx @@ -16,6 +16,11 @@ Regardless of the authentication strategy you choose, you are likely to store au We recommend to create `playwright/.auth` directory and add it to your `.gitignore`. Your authentication routine will produce authenticated browser state and save it to a file in this `playwright/.auth` directory. Later on, tests will reuse this state and start already authenticated. +:::danger + +The browser state file may contain sensitive cookies and headers that could be used to impersonate you or your test account. We strongly discourage checking them into private or public repositories. +::: + - + ```js title="playwright-dev-page.ts" import { expect, type Locator, type Page } from '@playwright/test'; @@ -67,45 +66,6 @@ export class PlaywrightDevPage { } ``` - - - -```js title="playwright-dev-page.js" -const { expect } = require('@playwright/test'); - -exports.PlaywrightDevPage = class PlaywrightDevPage { - - /** - * @param {import('@playwright/test').Page} page - */ - constructor(page) { - this.page = page; - this.getStartedLink = page.locator('a', { hasText: 'Get started' }); - this.gettingStartedHeader = page.locator('h1', { hasText: 'Installation' }); - this.pomLink = page.locator('li', { - hasText: 'Guides', - }).locator('a', { - hasText: 'Page Object Model', - }); - this.tocList = page.locator('article div.markdown ul > li > a'); - } - - async goto() { - await this.page.goto('https://playwright.dev'); - } - - async getStarted() { - await this.getStartedLink.first().click(); - await expect(this.gettingStartedHeader).toBeVisible(); - } - - async pageObjectModel() { - await this.getStarted(); - await this.pomLink.click(); - } -}; -``` - @@ -145,14 +105,13 @@ Now we can use the `PlaywrightDevPage` class in our tests. - + ```js title="example.spec.ts" import { test, expect } from '@playwright/test'; @@ -182,37 +141,6 @@ test('should show Page Object Model article', async ({ page }) => { }); ``` - - - -```js title="example.spec.js" -const { test, expect } = require('@playwright/test'); -const { PlaywrightDevPage } = require('./playwright-dev-page'); - -test('getting started should contain table of contents', async ({ page }) => { - const playwrightDev = new PlaywrightDevPage(page); - await playwrightDev.goto(); - await playwrightDev.getStarted(); - await expect(playwrightDev.tocList).toHaveText([ - `How to install Playwright`, - `What's Installed`, - `How to run the example test`, - `How to open the HTML test report`, - `Write tests using web first assertions, page fixtures and locators`, - `Run single test, multiple tests, headed mode`, - `Generate tests with Codegen`, - `See a trace of your tests` - ]); -}); - -test('should show Page Object Model article', async ({ page }) => { - const playwrightDev = new PlaywrightDevPage(page); - await playwrightDev.goto(); - await playwrightDev.pageObjectModel(); - await expect(page.locator('article')).toContainText('Page Object Model is a common pattern'); -}); -``` - diff --git a/nodejs/docs/test-assertions.mdx b/nodejs/docs/test-assertions.mdx index 4c48b698c89..a1cc7caee53 100644 --- a/nodejs/docs/test-assertions.mdx +++ b/nodejs/docs/test-assertions.mdx @@ -254,7 +254,7 @@ In this example we add a custom `toHaveAmount` function. Custom matcher should r ```js title="fixtures.ts" import { expect as baseExpect } from '@playwright/test'; -import type { Page, Locator } from '@playwright/test'; +import type { Locator } from '@playwright/test'; export { test } from '@playwright/test'; @@ -264,13 +264,18 @@ export const expect = baseExpect.extend({ let pass: boolean; let matcherResult: any; try { - await baseExpect(locator).toHaveAttribute('data-amount', String(expected), options); + const expectation = this.isNot ? baseExpect(locator).not : baseExpect(locator); + await expectation.toHaveAttribute('data-amount', String(expected), options); pass = true; } catch (e: any) { matcherResult = e.matcherResult; pass = false; } + if (this.isNot) { + pass =!pass; + } + const message = pass ? () => this.utils.matcherHint(assertionName, undefined, undefined, { isNot: this.isNot }) + '\n\n' + diff --git a/python/docs/auth.mdx b/python/docs/auth.mdx index 28a282019ae..8e07a25a9ba 100644 --- a/python/docs/auth.mdx +++ b/python/docs/auth.mdx @@ -16,6 +16,11 @@ Regardless of the authentication strategy you choose, you are likely to store au We recommend to create `playwright/.auth` directory and add it to your `.gitignore`. Your authentication routine will produce authenticated browser state and save it to a file in this `playwright/.auth` directory. Later on, tests will reuse this state and start already authenticated. +:::danger + +The browser state file may contain sensitive cookies and headers that could be used to impersonate you or your test account. We strongly discourage checking them into private or public repositories. +::: +