python+playwright 学习-76 playwright 忽略SSL 错误

发布时间 2023-08-27 15:41:48作者: 上海-悠悠

前言

playwright 设置 ignore_https_errors 参数忽略 SSL 错误

context 上下文中设置

browser.new_context() 创建上下文时

from playwright.sync_api import sync_playwright, expect


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


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