前言

playwright 设置 ignore_https_errors 参数忽略 SSL 错误

context 上下文中设置

browser.new_context() 创建上下文时

from playwright.sync_api import sync_playwright, expect
# 上海悠悠 wx:283340479
# blog:https://www.cnblogs.com/yoyoketang/


with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    context = browser.new_context(ignore_https_errors=True)
    page = context.new_page()

codegen 录制用例

录制用例时,启动命令添加--ignore-https-errors

playwright codegen --ignore-https-errors https://example.com

结合 pytest-playwright 用例插件

pytest-playwright 插件写自动化用例时,在conftest.py 中加入context 上下文启动参数

import pytest
# 上海悠悠 wx:283340479
# blog:https://www.cnblogs.com/yoyoketang/


@pytest.fixture(scope="session")
def browser_context_args(browser_context_args):
    return {
        **browser_context_args,
        "ignore_https_errors": True
    }

文章转自:https://www.cnblogs.com/yoyoketang/p/17660359.html