2021-10-21 17:44:17 -07:00
# class: PageAssertions
2021-11-24 21:58:35 +01:00
* langs: java, python, js
2021-10-21 17:44:17 -07:00
2021-11-24 21:58:35 +01:00
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` ]:
2021-11-09 12:44:02 -08:00
```java
...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestPage {
...
@Test
void navigatesToLoginPage() {
...
page.click("#login ");
assertThat(page).hasURL(Pattern.compile(".*/login"));
}
}
```
2021-10-21 17:44:17 -07:00
2021-11-18 00:46:30 +01:00
## method: PageAssertions.not
2021-11-24 21:58:35 +01:00
* langs: java, js
2021-11-18 00:46:30 +01:00
- returns: < [PageAssertions]>
Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't contain `"error"` :
```java
assertThat(page).not().hasURL("error");
```
## method: PageAssertions.NotToHaveTitle
* langs: python
The opposite of [`method: PageAssertions.toHaveTitle` ].
### param: PageAssertions.NotToHaveTitle.titleOrRegExp
- `titleOrRegExp` < [string]|[RegExp]>
Expected title or RegExp.
### option: PageAssertions.NotToHaveTitle.timeout = %%-assertions-timeout-%%
## method: PageAssertions.NotToHaveURL
* langs: python
- alias-java: hasURL
The opposite of [`method: PageAssertions.toHaveURL` ].
### param: PageAssertions.NotToHaveURL.urlOrRegExp
- `urlOrRegExp` < [string]|[RegExp]>
Expected substring or RegExp.
### option: PageAssertions.NotToHaveURL.timeout = %%-assertions-timeout-%%
## method: PageAssertions.toHaveTitle
* langs:
- alias-java: hasTitle
2021-10-21 17:44:17 -07:00
2021-10-22 16:56:58 -07:00
Ensures the page has the given title.
2021-10-21 17:44:17 -07:00
2021-11-24 21:58:35 +01:00
```js
await expect(page).toHaveTitle(/.*checkout/);
```
2021-10-21 17:44:17 -07:00
```java
assertThat(page).hasTitle("Playwright");
```
2021-11-18 00:46:30 +01:00
### param: PageAssertions.toHaveTitle.titleOrRegExp
2021-10-21 17:44:17 -07:00
- `titleOrRegExp` < [string]|[RegExp]>
Expected title or RegExp.
2021-11-18 00:46:30 +01:00
### option: PageAssertions.toHaveTitle.timeout = %%-assertions-timeout-%%
2021-10-21 17:44:17 -07:00
2021-11-18 00:46:30 +01:00
## method: PageAssertions.toHaveURL
* langs:
- alias-java: hasURL
2021-10-21 17:44:17 -07:00
Ensures the page is navigated to the given URL.
2021-11-24 21:58:35 +01:00
```js
await expect(page).toHaveURL(/.*checkout/);
```
2021-10-21 17:44:17 -07:00
```java
2021-11-08 11:31:11 -08:00
assertThat(page).hasURL(".com");
2021-10-21 17:44:17 -07:00
```
2021-11-18 00:46:30 +01:00
### param: PageAssertions.toHaveURL.urlOrRegExp
2021-10-21 17:44:17 -07:00
- `urlOrRegExp` < [string]|[RegExp]>
Expected substring or RegExp.
2021-11-18 00:46:30 +01:00
### option: PageAssertions.toHaveURL.timeout = %%-assertions-timeout-%%