Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from playwright.sync_api import sync_playwright, Error
- def test_insecure_website_headless():
- with sync_playwright() as p:
- browser = p.chromium.launch()
- context = browser.new_context(ignore_https_errors=True)
- page = context.new_page()
- try:
- page.goto("https://expired.badssl.com/", timeout=30000) # Increased timeout
- # Check for specific error messages or elements related to SSL issues.
- # This is more reliable than just checking the status code.
- if "NET::ERR_CERT_DATE_INVALID" in page.content() or \
- "Your connection is not private" in page.content() or \
- page.locator("#error-information-popup-content").is_visible(): # Example - adjust to the error page's content
- print("SSL certificate error detected.")
- page.screenshot(path="expired_ssl_error.png", full_page=True) # full_page is useful
- print("Screenshot saved to expired_ssl_error.png")
- else:
- print("Page loaded (unexpectedly, or different error).")
- page.screenshot(path="unexpected_page.png", full_page=True)
- except Error as e: # Catch Playwright specific errors
- print(f"A Playwright error occurred: {e}")
- page.screenshot(path="playwright_error.png", full_page=True) # Capture even Playwright's errors
- except Exception as e: # Catch broader exceptions
- print(f"A general error occurred: {e}")
- page.screenshot(path="general_error.png", full_page=True)
- finally:
- context.close()
- browser.close()
- test_insecure_website_headless()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement