APIResponseAssertions
Added in: v1.18The APIResponseAssertions class provides assertion methods that can be used to make assertions about the APIResponse in the tests.
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();
}
}Methods
apiResponseAssertions.isOK()
Added in: v1.18Ensures the response status code is within 200..299 range.
Usage
java
assertThat(response).isOK();Properties
apiResponseAssertions.not()
Added in: v1.20Makes the assertion check for the opposite condition.
Usage
For example, this code tests that the response status is not successful:
java
assertThat(response).not().isOK();Type
APIResponseAssertions