0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

pytest-xdistを用いたPlaywright テストコード並列実行方法 メモ

Last updated at Posted at 2023-01-22
  • ブラウザテスト用ライブラリPlaywrightで作成したコードをテストライブラリpytest-xdistで並列実行する方法についてメモする。

事前準備

  • 並列実行用ライブラリpytest-xdistをインストールする

    pip install pytest-xdist
    

コード

  • テストコードtest.py

    ※Playwright公式サイトにアクセスし、ページタイトルを確認するコード

    from playwright.sync_api import Playwright
    
    def test_parallel(playwright: Playwright):
        browser = playwright.chromium.launch(headless=True)
        page = browser.new_page()
        # ページアクセス
        page.goto('https://playwright.dev/python/')
        # タイトルチェック
        assert page.title() == 'Fast and reliable end-to-end testing for modern web apps | Playwright Python'
        page.close()
    
    

動作確認

  • 以下のコマンドを実行し、並列アクセスを行う

    pytest -n 3 --dist each test.py
    ================================================================================ test session starts =================================================================================
    platform linux -- Python 3.8.10, pytest-7.2.0, pluggy-1.0.0
    rootdir: /home/u5008506/dev/playwright-test
    plugins: html-3.2.0, playwright-0.3.0, metadata-2.0.4, cov-4.0.0, base-url-2.0.0, xdist-3.1.0, parallel-0.1.1, anyio-3.3.4
    gw0 [1] / gw1 [1] / gw2 [1]
    .                                                                                                                                                                              [100%]. [100%]. [100%]
    ================================================================================= 3 passed in 9.37s ==================================================================================
    

    -n :並列実行するノード数を指定する。autoを指定した場合利用可能なCPUのコア数が自動的に設定される。

    ※同時に3ブラウザからアクセスするテストを実行する。

参考情報

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?