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

2023-09-11 19:35:18 浏览数 (2)

前言

playwright 设置 ignore_https_errors 参数忽略 SSL 错误

context 上下文中设置

browser.new_context() 创建上下文时

代码语言:javascript复制
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

代码语言:javascript复制
playwright codegen --ignore-https-errors https://example.com

结合 pytest-playwright 用例插件

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

代码语言:javascript复制
import pytest@pytest.fixture(scope="session")def browser_context_args(browser_context_args):
    return {
        **browser_context_args,                "ignore_https_errors": True
    }

0 人点赞