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
添加于:v1.18确保响应状态码在 200..299
范围内。
用法
assertThat(response).isOK();
返回值
属性
not()
添加于:v1.20使断言检查相反的条件。例如,此代码测试响应状态不成功:
assertThat(response).not().isOK();
用法
assertThat(response).not()
返回值