I would like playwright to fail early, and stop as soon as one http request is not 200
or 302
.
def test_it(live_server):
os.environ['DEBUG']='pw:api'
with sync_playwright() as playwright:
run_test_id(live_server, playwright)
def run_test_id(live_server, playwright):
browser = playwright.webkit.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto(live_server.url)
page.click("text=Create Test Data")
Unfortunately page.click()
returns None, so I have no clue how I can check for the http status of the click.
How could I implement "Fail on unusual http status" in Playwright?
An option is to use page.on()
:
def handle_response(response):
print(f"{response.status}")
if response.status == 500:
exit(1)
page.on("response", handle_response)
This, however, doesn't check for only a status code after the click, but for any response for a request, so for example if your page.goto()
returns 500, it will stop here as well.
(I'm more used to Playwright with JS, so my example might be a tiny bit off.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With