playwright启动后报错net::ERR_CERT_COMMON_NAME_INVALID 解决方法

运行playwright测试用例报错:

1、如果是在跑测试的时候报错,在创建上下文时设置ignore_https_errors=True就可以了,如:

from idlelib import browser
from playwright.sync_api import Playwright

def getPage(playwright: Playwright):
    chromium = playwright.chromium  
    browser = chromium.launch(headless=False)
    page = browser.new_page(ignore_https_errors=True)     # 解决报错问题
    return page

def test_has_title(playwright: Playwright):
    page = getPage(playwright)
    page.goto("https://www.test.com")
    expect(page).to_have_title(re.compile("XXXX"))
    # other actions...
    browser.close()

2、如果是在录制脚本的时候报错,那就是在playwright codegen命令后添加–ignore-https-errors参数即可,如:

 playwright codegen --ignore-https-errors https://www.test.com/

 

posted @ 2024-08-13 16:21  远洪  阅读(241)  评论(0编辑  收藏  举报