Skip to main content

APIResponseAssertions

The APIResponseAssertions class provides assertion methods that can be used to make assertions about the APIResponse in the tests.

using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;

namespace PlaywrightTests;

[TestClass]
public class ExampleTests : PageTest
{
[TestMethod]
public async Task NavigatesToLoginPage()
{
var response = await Page.APIRequest.GetAsync("https://playwright.dev");
await Expect(response).ToBeOKAsync();
}
}

Methods

ToBeOKAsync

Added in: v1.18 apiResponseAssertions.ToBeOKAsync

Ensures the response status code is within 200..299 range.

Usage

await Expect(response).ToBeOKAsync();

Returns


Properties

Not

Added in: v1.20 apiResponseAssertions.Not

Makes the assertion check for the opposite condition.

Usage

For example, this code tests that the response status is not successful:

await Expect(response).Not.ToBeOKAsync();

Type