微軟網頁自動化測試Playwright

Posted in :

直接先講結論, Playwright 沒辦法通過 Cloudflare 的檢查, 服用的程式碼:

from playwright.sync_api import sync_playwright
import time

with sync_playwright() as p:
    for browser_type in [p.chromium, p.firefox, p.webkit]:
        browser = browser_type.launch()
        page = browser.new_page()
        page.goto('https://nowsecure.nl')
        time.sleep(5)
        page.screenshot(path=f'example-{browser_type.name}.png')
        browser.close()

執行畫面: (已被擋下來)


Playwright 介紹

Playwright Test服務提供開發者一個簡易平臺,進行大規模端到端網頁應用程式測試,確保其可靠性以及在各作業系統和瀏覽器的穩定性。

官方網站:
https://playwright.dev/python/

github:
https://github.com/microsoft/playwright-python

Installing Playwright:

Install the Pytest plugin:

pip install pytest-playwright

Install the required browsers:

playwright install

System requirements

  • Python 3.8 or higher.
  • Windows 10+, Windows Server 2016+ or Windows Subsystem for Linux (WSL).
  • MacOS 12 Monterey, MacOS 13 Ventura, or MacOS 14 Sonoma.
  • Debian 11, Debian 12, Ubuntu 20.04 or Ubuntu 22.04.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *