APIResponseAssertions
The APIResponseAssertions 類別提供了斷言方法,可以用於對測試中的 APIResponse 進行斷言。
// ...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestPage {
// ...
@Test
void navigatesToLoginPage() {
// ...
APIResponse response = page.request().get("https://playwright.dev.org.tw");
assertThat(response).isOK();
}
}
方法
isOK
新增於:v1.18確保回應狀態碼在 200..299
範圍內。
用法
assertThat(response).isOK();
回傳
屬性
not()
新增於:v1.20使斷言檢查相反的條件。例如,此程式碼測試回應狀態是否不成功
assertThat(response).not().isOK();
用法
assertThat(response).not()
回傳