playwright文档说明

playwright官方文档翻译


运行测试

<h1>运行测试</h1> <p>可以运行单个测试、一组测试或所有测试。测试可以在一个浏览器或多个浏览器上运行。默认情况下,测试以无头方式运行,这意味着在运行测试时不会打开浏览器窗口,结果将在终端中看到。如果您愿意,可以使用 theflag 在有头模式下运行测试。<code>--headed</code></p> <ul> <li> <p>在chrome上运行测试</p> <pre><code>pytest</code></pre> </li> <li> <p>运行单个测试文件</p> <pre><code>pytest test_login.py</code></pre> </li> <li> <p>运行一组测试文件</p> <pre><code>pytest tests/todo-page/ tests/landing-page/</code></pre> </li> <li> <p>使用函数名称运行测试</p> <pre><code>pytest -k "test_add_a_todo_item"</code></pre> </li> <li> <p>在定向模式下运行测试</p> <pre><code>pytest --headed test_login.py</code></pre> </li> <li> <p>在特定浏览器上运行测试</p> <pre><code>pytest test_login.py --browser webkit</code></pre> </li> <li> <p>在多个浏览器上运行测试</p> <pre><code>pytest test_login.py --browser webkit --browser firefox</code></pre> </li> <li> <p>并行运行测试</p> <pre><code>pytest --numprocesses auto</code></pre> <p>(此假设已安装。有关更多信息,请参阅<a href="https://playwright.dev/python/docs/test-runners#parallelism-running-multiple-tests-at-once">此处</a>。<code>pytest-xdist</code></p> </li> </ul> <p>有关更多信息,请参阅<a href="https://playwright.dev/python/docs/test-runners">Playwright</a>Pytest 用法或 Pytest 文档了解<a href="https://docs.pytest.org/en/stable/usage.html">常规 CLI 用法</a>。</p> <h2>运行测试<a href="https://playwright.dev/python/docs/running-tests#running-tests" title="Direct link to heading"></a></h2> <p>由于Playwright在Python中运行,因此您可以使用您选择的调试器对其进行调试,例如Visual Studio Code中的<a href="https://code.visualstudio.com/docs/python/python-tutorial">Python扩展</a>。Playwright 附带 Playwright Inspector,可让您逐步完成 Playwright API 调用、查看其调试日志并探索<a href="https://playwright.dev/python/docs/selectors">选择器</a>。</p> <ul> <li>砰砰��</li> <li>PowerShell</li> <li>批</li> </ul> <pre><code class="language-python"> PWDEBUG=1 pytest -s`</code></pre> <p><img src="https://user-images.githubusercontent.com/883973/108614092-8c478a80-73ac-11eb-9597-67dfce110e00.png" alt="Playwright Inspector" /></p>

页面列表

ITEM_HTML