docs(expect): APIResponse assertions (#10957)
This commit is contained in:
parent
b606b5b8a0
commit
0eaa19d5e7
94
docs/src/api/class-apiresponseassertions.md
Normal file
94
docs/src/api/class-apiresponseassertions.md
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
# class: APIResponseAssertions
|
||||||
|
* langs: js
|
||||||
|
|
||||||
|
The [APIResponseAssertions] class provides assertion methods that can be used to make assertions about the [APIResponse] in the tests. A new instance of [APIResponseAssertions] is created by calling [`method: PlaywrightAssertions.expectAPIResponse`]:
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
test('navigates to login', async ({ page }) => {
|
||||||
|
// ...
|
||||||
|
const response = await page.request.get('https://playwright.dev');
|
||||||
|
expect(response).toBeOK();
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
...
|
||||||
|
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||||
|
|
||||||
|
public class TestPage {
|
||||||
|
...
|
||||||
|
@Test
|
||||||
|
void navigatesToLoginPage() {
|
||||||
|
...
|
||||||
|
APIResponse response = page.request().get('https://playwright.dev');
|
||||||
|
assertThat(response).isOK();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```python async
|
||||||
|
import re
|
||||||
|
from playwright.async_api import Page, expect
|
||||||
|
|
||||||
|
async def test_navigates_to_login_page(page: Page) -> None:
|
||||||
|
# ..
|
||||||
|
response = await page.request.get('https://playwright.dev')
|
||||||
|
expect(response).to_be_ok()
|
||||||
|
```
|
||||||
|
|
||||||
|
```python sync
|
||||||
|
import re
|
||||||
|
from playwright.sync_api import Page, expect
|
||||||
|
|
||||||
|
def test_navigates_to_login_page(page: Page) -> None:
|
||||||
|
# ..
|
||||||
|
response = page.request.get('https://playwright.dev')
|
||||||
|
expect(response).to_be_ok()
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## method: APIResponseAssertions.not
|
||||||
|
* langs: java, js
|
||||||
|
- returns: <[APIResponseAssertions]>
|
||||||
|
|
||||||
|
Makes the assertion check for the opposite condition. For example, this code tests that the response status is not successfull:
|
||||||
|
|
||||||
|
```js
|
||||||
|
expect(response).not.toBeOK();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
assertThat(response).not().isOK();
|
||||||
|
```
|
||||||
|
|
||||||
|
## method: APIResponseAssertions.toBeOK
|
||||||
|
* langs:
|
||||||
|
- alias-java: isOK
|
||||||
|
|
||||||
|
Ensures the response status code is within [200..299) range.
|
||||||
|
|
||||||
|
```js
|
||||||
|
expect(response).toBeOK();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
assertThat(response).isOK();
|
||||||
|
```
|
||||||
|
|
||||||
|
```python async
|
||||||
|
import re
|
||||||
|
from playwright.async_api import expect
|
||||||
|
|
||||||
|
# ...
|
||||||
|
expect(response).to_be_ok()
|
||||||
|
```
|
||||||
|
|
||||||
|
```python sync
|
||||||
|
import re
|
||||||
|
from playwright.sync_api import expect
|
||||||
|
|
||||||
|
# ...
|
||||||
|
expect(response).to_be_ok()
|
||||||
|
```
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# class: PageAssertions
|
# class: PageAssertions
|
||||||
* langs: java, python, js
|
* langs: java, python, js
|
||||||
|
|
||||||
The [PageAssertions] class provides assertion methods that can be used to make assertions about the [Page] state in the tests. A new instance of [LocatorAssertions] is created by calling [`method: PlaywrightAssertions.expectPage`]:
|
The [PageAssertions] class provides assertion methods that can be used to make assertions about the [Page] state in the tests. A new instance of [PageAssertions] is created by calling [`method: PlaywrightAssertions.expectPage`]:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,24 @@ By default, the timeout for assertions is set to 5 seconds.
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## method: PlaywrightAssertions.expectAPIResponse
|
||||||
|
* langs: js
|
||||||
|
- alias-java: assertThat
|
||||||
|
- alias-python: expect
|
||||||
|
- alias-js: expect
|
||||||
|
- returns: <[APIResponseAssertions]>
|
||||||
|
|
||||||
|
Creates a [APIResponseAssertions] object for the given [APIResponse].
|
||||||
|
|
||||||
|
```java
|
||||||
|
PlaywrightAssertions.assertThat(response).isOK();
|
||||||
|
```
|
||||||
|
|
||||||
|
### param: PlaywrightAssertions.expectAPIResponse.response
|
||||||
|
- `response` <[APIResponse]>
|
||||||
|
|
||||||
|
[APIResponse] object to use for assertions.
|
||||||
|
|
||||||
## method: PlaywrightAssertions.expectLocator
|
## method: PlaywrightAssertions.expectLocator
|
||||||
* langs: java, python, js
|
* langs: java, python, js
|
||||||
- alias-java: assertThat
|
- alias-java: assertThat
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ const path = require('path');
|
||||||
|
|
||||||
/** @typedef {import('../../markdown').MarkdownNode} MarkdownNode */
|
/** @typedef {import('../../markdown').MarkdownNode} MarkdownNode */
|
||||||
|
|
||||||
const IGNORE_CLASSES = ['PlaywrightAssertions', 'LocatorAssertions', 'PageAssertions'];
|
const IGNORE_CLASSES = ['PlaywrightAssertions', 'LocatorAssertions', 'PageAssertions', 'APIResponseAssertions'];
|
||||||
|
|
||||||
module.exports = function lint(documentation, jsSources, apiFileName) {
|
module.exports = function lint(documentation, jsSources, apiFileName) {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ class TypesGenerator {
|
||||||
return (!docsOnlyClassMapping && docClass) ? this.classBody(docClass) : '';
|
return (!docsOnlyClassMapping && docClass) ? this.classBody(docClass) : '';
|
||||||
});
|
});
|
||||||
|
|
||||||
const IGNORED_CLASSES = ['PlaywrightAssertions', 'LocatorAssertions', 'PageAssertions'];
|
const IGNORED_CLASSES = ['PlaywrightAssertions', 'LocatorAssertions', 'PageAssertions', 'APIResponseAssertions'];
|
||||||
const classes = this.documentation.classesArray.filter(cls => !IGNORED_CLASSES.includes(cls.name)).filter(cls => !handledClasses.has(cls.name));
|
const classes = this.documentation.classesArray.filter(cls => !IGNORED_CLASSES.includes(cls.name)).filter(cls => !handledClasses.has(cls.name));
|
||||||
{
|
{
|
||||||
const playwright = this.documentation.classesArray.find(c => c.name === 'Playwright');
|
const playwright = this.documentation.classesArray.find(c => c.name === 'Playwright');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue