跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

APIResponseAssertions ​

Added in: v1.18

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

csharp
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 ​

ApiResponseAssertions.ToBeOKAsync() ​

Added in: v1.18

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

Usage

csharp
await Expect(response).ToBeOKAsync();

Properties ​

ApiResponseAssertions.Not ​

Added in: v1.20

Makes the assertion check for the opposite condition.

Usage

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

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

Type

  • APIResponseAssertions

基于 Apache 2.0 许可证发布。