docs: split assertions list into langs (#19039)

This commit is contained in:
Pavel Feldman 2022-11-24 08:25:24 -08:00 committed by GitHub
parent 8ec3de7f41
commit be2139f0ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 23 deletions

View file

@ -695,7 +695,7 @@ await Expect(locator).ToBeFocusedAsync();
* langs:
- alias-java: isHidden
Ensures that [Locator] either does not resolve to any DOM node, or resolves to a [non-visible](./actionability.md#visible) one.
Ensures that [Locator] either does not resolve to any DOM node, or resolves to a [non-visible](../actionability.md#visible) one.
**Usage**
@ -738,7 +738,7 @@ await Expect(locator).ToBeHiddenAsync();
* langs:
- alias-java: isVisible
Ensures that [Locator] points to an [attached](./actionability.md#attached) and [visible](./actionability.md#visible) DOM node.
Ensures that [Locator] points to an [attached](../actionability.md#attached) and [visible](../actionability.md#visible) DOM node.
**Usage**

View file

@ -33,7 +33,7 @@ expect(await page.screenshot()).toMatchSnapshot(['landing', 'step2.png']);
expect(await page.screenshot()).toMatchSnapshot(['landing', 'step3.png']);
```
Learn more about [visual comparisons](./test-snapshots.md).
Learn more about [visual comparisons](../test-snapshots.md).
### param: ScreenshotAssertions.toMatchSnapshot#1.name
* since: v1.22
@ -73,7 +73,7 @@ expect(await page.screenshot()).toMatchSnapshot({
});
```
Learn more about [visual comparisons](./test-snapshots.md).
Learn more about [visual comparisons](../test-snapshots.md).
### option: ScreenshotAssertions.toMatchSnapshot#2.maxDiffPixels = %%-assertions-max-diff-pixels-%%
* since: v1.22

View file

@ -0,0 +1,30 @@
---
id: test-assertions
title: "Assertions"
---
## List of assertions
| Assertion | Description |
| :- | :- |
| [`method: LocatorAssertions.toBeChecked`] | Checkbox is checked |
| [`method: LocatorAssertions.toBeDisabled`] | Element is disabled |
| [`method: LocatorAssertions.toBeEditable`] | Element is enabled |
| [`method: LocatorAssertions.toBeEmpty`] | Container is empty |
| [`method: LocatorAssertions.toBeEnabled`] | Element is enabled |
| [`method: LocatorAssertions.toBeFocused`] | Element is focused |
| [`method: LocatorAssertions.toBeHidden`] | Element is not visible |
| [`method: LocatorAssertions.toBeVisible`] | Element is visible |
| [`method: LocatorAssertions.toContainText`] | Element contains text |
| [`method: LocatorAssertions.toHaveAttribute`] | Element has a DOM attribute |
| [`method: LocatorAssertions.toHaveClass`] | Element has a class property |
| [`method: LocatorAssertions.toHaveCount`] | List has exact number of children |
| [`method: LocatorAssertions.toHaveCSS`] | Element has CSS property |
| [`method: LocatorAssertions.toHaveId`] | Element has an ID |
| [`method: LocatorAssertions.toHaveJSProperty`] | Element has a JavaScript property |
| [`method: LocatorAssertions.toHaveText`] | Element matches text |
| [`method: LocatorAssertions.toHaveValue`] | Input has a value |
| [`method: LocatorAssertions.toHaveValues`] | Select has options selected |
| [`method: PageAssertions.toHaveTitle`] | Page has a title |
| [`method: PageAssertions.toHaveURL`] | Page has a URL |
| [`method: APIResponseAssertions.toBeOK`] | Response has an OK status |

View file

@ -20,6 +20,34 @@ Playwright Test will be re-testing the node with the selector `.status` until fe
By default, the timeout for assertions is set to 5 seconds. Learn more about [various timeouts](./test-timeouts.md).
## List of assertions
| Assertion | Description |
| :- | :- |
| [`method: LocatorAssertions.toBeChecked`] | Checkbox is checked |
| [`method: LocatorAssertions.toBeDisabled`] | Element is disabled |
| [`method: LocatorAssertions.toBeEditable`] | Element is enabled |
| [`method: LocatorAssertions.toBeEmpty`] | Container is empty |
| [`method: LocatorAssertions.toBeEnabled`] | Element is enabled |
| [`method: LocatorAssertions.toBeFocused`] | Element is focused |
| [`method: LocatorAssertions.toBeHidden`] | Element is not visible |
| [`method: LocatorAssertions.toBeVisible`] | Element is visible |
| [`method: LocatorAssertions.toContainText`] | Element contains text |
| [`method: LocatorAssertions.toHaveAttribute`] | Element has a DOM attribute |
| [`method: LocatorAssertions.toHaveClass`] | Element has a class property |
| [`method: LocatorAssertions.toHaveCount`] | List has exact number of children |
| [`method: LocatorAssertions.toHaveCSS`] | Element has CSS property |
| [`method: LocatorAssertions.toHaveId`] | Element has an ID |
| [`method: LocatorAssertions.toHaveJSProperty`] | Element has a JavaScript property |
| [`method: LocatorAssertions.toHaveScreenshot#1`] | Element has a screenshot |
| [`method: LocatorAssertions.toHaveText`] | Element matches text |
| [`method: LocatorAssertions.toHaveValue`] | Input has a value |
| [`method: LocatorAssertions.toHaveValues`] | Select has options selected |
| [`method: PageAssertions.toHaveScreenshot#1`] | Page has a screenshot |
| [`method: PageAssertions.toHaveTitle`] | Page has a title |
| [`method: PageAssertions.toHaveURL`] | Page has a URL |
| [`method: APIResponseAssertions.toBeOK`] | Response has an OK status |
## Negating Matchers
In general, we can expect the opposite to be true by adding a `.not` to the front

View file

@ -134,7 +134,6 @@ Here is the list of the most popular async assertions. Note that there are [many
| Assertion | Description |
| :- | :- |
| [`method: LocatorAssertions.toBeChecked`] | Checkbox is checked |
| [`method: LocatorAssertions.toBeChecked`] | Checkbox is checked |
| [`method: LocatorAssertions.toBeEnabled`] | Control is enabled |
| [`method: LocatorAssertions.toBeVisible`] | Element is visible |
| [`method: LocatorAssertions.toContainText`] | Element contains text |

View file

@ -3567,7 +3567,7 @@ interface LocatorAssertions {
/**
* Ensures that [Locator] either does not resolve to any DOM node, or resolves to a
* [non-visible](https://playwright.dev/docs/api/actionability#visible) one.
* [non-visible](https://playwright.dev/docs/actionability#visible) one.
*
* **Usage**
*
@ -3586,8 +3586,8 @@ interface LocatorAssertions {
}): Promise<void>;
/**
* Ensures that [Locator] points to an [attached](https://playwright.dev/docs/api/actionability#attached) and
* [visible](https://playwright.dev/docs/api/actionability#visible) DOM node.
* Ensures that [Locator] points to an [attached](https://playwright.dev/docs/actionability#attached) and
* [visible](https://playwright.dev/docs/actionability#visible) DOM node.
*
* **Usage**
*
@ -4392,7 +4392,7 @@ interface ScreenshotAssertions {
* expect(await page.screenshot()).toMatchSnapshot(['landing', 'step3.png']);
* ```
*
* Learn more about [visual comparisons](https://playwright.dev/docs/api/test-snapshots).
* Learn more about [visual comparisons](https://playwright.dev/docs/test-snapshots).
* @param name Snapshot name.
* @param options
*/
@ -4439,7 +4439,7 @@ interface ScreenshotAssertions {
* });
* ```
*
* Learn more about [visual comparisons](https://playwright.dev/docs/api/test-snapshots).
* Learn more about [visual comparisons](https://playwright.dev/docs/test-snapshots).
* @param options
*/
toMatchSnapshot(options?: {

View file

@ -206,24 +206,11 @@ async function run() {
if (mdLink.startsWith('#'))
continue;
// The assertion classes are "virtual files" which get merged into test-assertions.md inside our docs generator
let markdownBasePath = path.dirname(filePath);
if ([
'class-screenshotassertions.md',
'class-locatorassertions.md',
'class-pageassertions.md'
].includes(path.basename(filePath))) {
markdownBasePath = documentationRoot;
}
let linkWithoutHash = path.join(markdownBasePath, mdLink.split('#')[0]);
if (path.extname(linkWithoutHash) !== '.md')
linkWithoutHash += '.md';
// We generate it inside the generator (playwright.dev)
if (path.basename(linkWithoutHash) === 'test-assertions.md')
return;
if (!relevantMarkdownFiles.has(linkWithoutHash))
throw new Error(`${path.relative(PROJECT_DIR, filePath)} references to '${linkWithoutHash}' as '${mdLinkName}' which does not exist.`);
}