使用codegen录制代码

  1. (venv) PS E:\WorkSpace\Python_WorkSpace\FlaskDemo> python -m playwright codegen --help
  2. Usage: playwright codegen [options] [url]
  3. open page and generate code for user actions
  4. Options:
  5. -o, --output <file name> saves the generated script to a file
  6. --target <language> language to generate, one of javascript, test, python, python-async, csharp (default: "python")
  7. -b, --browser <browserType> browser to use, one of cr, chromium, ff, firefox, wk, webkit (default: "chromium")
  8. --channel <channel> Chromium distribution channel, "chrome", "chrome-beta", "msedge-dev", etc
  9. --color-scheme <scheme> emulate preferred color scheme, "light" or "dark"
  10. --device <deviceName> emulate device, for example "iPhone 11"
  11. --geolocation <coordinates> specify geolocation coordinates, for example "37.819722,-122.478611"
  12. --ignore-https-errors ignore https errors
  13. --load-storage <filename> load context storage state from the file, previously saved with --save-storage
  14. --lang <language> specify language / locale, for example "en-GB"
  15. --proxy-server <proxy> specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"
  16. --proxy-bypass <bypass> comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"
  17. --save-storage <filename> save context storage state at the end, for later use with --load-storage
  18. --save-trace <filename> record a trace for the session and save it to a file
  19. --timezone <time zone> time zone to emulate, for example "Europe/Rome"
  20. --timeout <timeout> timeout for Playwright actions in milliseconds (default: "10000")
  21. --user-agent <ua string> specify user agent string
  22. --viewport-size <size> specify browser viewport size in pixels, for example "1280, 720"
  23. -h, --help display help for command
  24. Examples:
  25. $ codegen
  26. $ codegen --target=python
  27. $ codegen -b webkit https://example.com
-o 将生成的脚本保存到文件
—target 要生成的语言,从javascript、test、python、python-async、csharp中选择一个(默认:”python”)。
-b 使用的浏览器,cr、chromium、ff、firefox、wk、webkit中的一个(默认:”chromium”)。
-h 显示命令帮助

示例

playwright codegen -o test.py -b cr

示例说明使用谷歌浏览器记录执行用例保存为test.py