Skip to main content

APIResponseAssertions

APIResponseAssertions 类提供了断言方法,可用于在测试中对 APIResponse 进行断言。

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

// ...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

public class TestPage {
// ...
@Test
void navigatesToLoginPage() {
// ...
APIResponse response = page.request().get("https://playwright.nodejs.cn");
assertThat(response).isOK();
}
}

方法

¥Methods

isOK

Added in: v1.18 apiResponseAssertions.isOK

确保响应状态代码在 200..299 范围内。

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

用法

¥Usage

assertThat(response).isOK();

返回

¥Returns


属性

¥Properties

not()

Added in: v1.20 apiResponseAssertions.not()

使断言检查相反的条件。例如,此代码测试响应状态是否不成功:

¥Makes the assertion check for the opposite condition. For example, this code tests that the response status is not successful:

assertThat(response).not().isOK();

用法

¥Usage

assertThat(response).not()

返回

¥Returns