欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python中Playwright模塊進行自動化測試的實現(xiàn)

 更新時間:2023年12月10日 09:59:18   作者:?cacho_37967865  
playwright是由微軟開發(fā)的Web UI自動化測試工具,本文主要介紹了Python中Playwright模塊進行自動化測試的實現(xiàn),具有一定的參考價值,感興趣的可以了解一下

playwright是由微軟開發(fā)的Web UI自動化測試工具,支持Node.js、Python、C# 和 Java語言,本文將介紹Python版本的Playwright使用方法。

微軟開源了一個非常強大的自動化項目叫playwright-python,項目地址:https://github.com/microsoft/playwright-python 

它支持主流的瀏覽器,包含:Chrome、Firefox、Safari、Microsoft Edge 等,同時支持以無頭模式、有頭模式運行,并提供了同步、異步的 API,可以結合 Pytest 測試框架使用,并且支持瀏覽器端的自動化腳本錄制。

Playwright提供的自動化技術是綠色的、功能強大、可靠且快速,支持Linux、Mac以及Windows操作系統(tǒng)。

官網(wǎng):https://playwright.dev/ 

從官網(wǎng)的解釋,官方給Playwright定位是一款真正意義上的Web端到端測試工具。

安裝步驟

第 1 步,安裝 playwright-python 依賴庫 (需要注意的是,playwright庫需要依賴Python3.7+以上)

pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade Playwright

第 2 步,安裝主流的瀏覽器驅動

playwright install

如果想查看Playwright支持的功能, 可以直接在命令行輸入:playwright -h

使用Playwright可以無需寫代碼,只需手動操作瀏覽器,它會錄制我們的操作,然后自動生成代碼腳本。

錄制腳本

1. 查看錄制命令說明 playwright codegen -h

Usage: playwright codegen [options] [url]

open page and generate code for user actions

Options:
  -o, --output <file name>             saves the generated script to a file
  --target <language>                  language to generate, one of javascript, playwright-test, python, python-async,
                                       python-pytest, csharp, csharp-mstest, csharp-nunit, java (default: "python")
  --save-trace <filename>              record a trace for the session and save it to a file
  --test-id-attribute <attributeName>  use the specified attribute to generate data test ID selectors
  -b, --browser <browserType>          browser to use, one of cr, chromium, ff, firefox, wk, webkit (default:
                                       "chromium")
  --block-service-workers              block service workers
  --channel <channel>                  Chromium distribution channel, "chrome", "chrome-beta", "msedge-dev", etc
  --color-scheme <scheme>              emulate preferred color scheme, "light" or "dark"
  --device <deviceName>                emulate device, for example  "iPhone 11"
  --geolocation <coordinates>          specify geolocation coordinates, for example "37.819722,-122.478611"
  --ignore-https-errors                ignore https errors
  --load-storage <filename>            load context storage state from the file, previously saved with --save-storage
  --lang <language>                    specify language / locale, for example "en-GB"
  --proxy-server <proxy>               specify proxy server, for example "http://myproxy:3128" or
                                       "socks5://myproxy:8080"
  --proxy-bypass <bypass>              comma-separated domains to bypass proxy, for example
                                       ".com,chromium.org,.domain.com"
  --save-har <filename>                save HAR file with all network activity at the end
  --save-har-glob <glob pattern>       filter entries in the HAR by matching url against this glob pattern
  --save-storage <filename>            save context storage state at the end, for later use with --load-storage
  --timezone <time zone>               time zone to emulate, for example "Europe/Rome"
  --timeout <timeout>                  timeout for Playwright actions in milliseconds, no timeout by default
  --user-agent <ua string>             specify user agent string
  --viewport-size <size>               specify browser viewport size in pixels, for example "1280, 720"
  -h, --help                           display help for command

Examples:

  $ codegen
  $ codegen --target=python
  $ codegen -b webkit https://example.com

比如,我要在baidu.com搜索,用chromium驅動,將結果保存為test.py的python文件。文檔默認保存到 C:\Users\user\下面

playwright codegen --target python -o 'test.py' -b chromium https://www.baidu.com

到此這篇關于Python中Playwright模塊進行自動化測試的實現(xiàn)的文章就介紹到這了,更多相關Python Playwright自動化測試內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • python代碼區(qū)分大小寫嗎

    python代碼區(qū)分大小寫嗎

    在本篇文章里小編給大家整理了一篇關于python是否區(qū)分大小寫的相關內容,對此有疑惑的新手們來學習下吧。
    2020-06-06
  • Python錯誤和異??偨Y詳細

    Python錯誤和異常總結詳細

    本文詳細且清晰地講解了Python中錯誤和異常的概念及其處理方式,通過具體案例展示try...except、try...finally、with...等句式的具體用法,期望能幫助到對此感到迷惑的初學者
    2021-10-10
  • ChatGLM-6B+LangChain環(huán)境部署與使用實戰(zhàn)

    ChatGLM-6B+LangChain環(huán)境部署與使用實戰(zhàn)

    這篇文章主要介紹了ChatGLM-6B+LangChain環(huán)境部署與使用方法,結合實例形式詳細分析了ChatGLM-6B+LangChain環(huán)境部署相關步驟、實現(xiàn)方法與相關注意事項,需要的朋友可以參考下
    2023-07-07
  • pandas DataFrame mul的具體實現(xiàn)

    pandas DataFrame mul的具體實現(xiàn)

    pandas.DataFrame.mul()?方法用于執(zhí)行逐元素的乘法操作,本文主要介紹了pandas DataFrame mul的具體實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2025-04-04
  • pycharm永久激活超詳細教程

    pycharm永久激活超詳細教程

    這篇文章主要介紹了pycharm永久激活超詳細教程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10
  • python中matplotlib調整圖例位置的方法實例

    python中matplotlib調整圖例位置的方法實例

    在matplotlib中,一般圖例默認是在圖表內部的,如果要放置到圖例外面,需要對坐標進行指定,下面這篇文章主要給大家介紹了關于python中matplotlib調整圖例位置的相關資料,需要的朋友可以參考下
    2022-06-06
  • Pycharm直接使用遠程服務器代碼并調試的解決方法

    Pycharm直接使用遠程服務器代碼并調試的解決方法

    這篇文章主要介紹了Pycharm直接使用遠程服務器代碼并調試的解決方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-02-02
  • 利用Pandas讀取表格行數(shù)據(jù)判斷是否相同的方法

    利用Pandas讀取表格行數(shù)據(jù)判斷是否相同的方法

    這篇文章主要給大家介紹了關于利用Pandas讀取表格行數(shù)據(jù)判斷是否相同的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • Jupyter notebook遠程訪問服務器的方法

    Jupyter notebook遠程訪問服務器的方法

    今天小編就為大家分享一篇Jupyter notebook遠程訪問服務器的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • python更新數(shù)據(jù)庫中某個字段的數(shù)據(jù)(方法詳解)

    python更新數(shù)據(jù)庫中某個字段的數(shù)據(jù)(方法詳解)

    這篇文章主要介紹了python更新數(shù)據(jù)庫中某個字段的數(shù)據(jù)方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-11-11

最新評論