跳至主要内容

APIResponseAssertions

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

// ...
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();
}
}

方法

isOK

Added in: v1.18 apiResponseAssertions.isOK

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

用法

assertThat(response).isOK();

返回


属性

not()

Added in: v1.20 apiResponseAssertions.not()

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

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

用法

assertThat(response).not()

返回