microsoft / microsoft/playwright-java
[Feature]: JUnit: Allow the user to control the Browser object's lifecycle
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 1.6k
- フォーク
- 298
- 平均マージ
- 3日 2時間
- マージ済み PR(30日)
- 14
説明
🚀 Feature Request
Add an option that will reset the Browser object after each test so cloud services that use BrowserType.connect can work properly. Example: https://www.browserstack.com/docs/automate/playwright/playwright-capabilities#Java
Example
public class Options {
// existing options
public Boolean closeBrowserAfterEachTest;
public Options setCloseBrowserAfterEachTest(Boolean closeBrowser) {
this.closeBrowserAfterEachTest = closeBrowser;
return this;
}
}
Inside of the existing TestWatcher methods, we can check if the user wants to close the browser after each test and do so. Once the next test starts, the Browser will be re-created by the fixture using the existing options. This will allow a new test session to start in BrowserStack.
@Override
public void testSuccessful(ExtensionContext extensionContext) {
saveTraceWhenOn(extensionContext);
closeBrowserContext();
Options options = OptionsExtension.getOptions(extensionContext);
if(options.closeBrowserAfterEachTest) {
BrowserExtension.closeBrowser();
}
}
Motivation
Cloud testing services like BrowserStack launch new sessions using BrowserType.connect. Each call to connect starts a new test session.
This doesn't work properly with current JUnit fixtures because the Browser object is re-used per thread and so all tests that run on the same thread use the same test session in BrowserStack. This becomes one giant test according to BrowserStack.
My suggestion would allow the user to decide when to re-use the browser, which works great locally, but not so well when using cloud testing services.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、JUnit 拡張の Options、既存の TestWatcher メソッド、BrowserExtension.closeBrowser()、および Browser を再作成する fixture を追跡します。オプションがどのように読み取られるか、また現在ブラウザーの再利用がどのように機能しているかを確認します。opt-in 設定によって各テストの後に Browser が閉じられ、次のテストで既存のオプションを使って新しいセッションが作成されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- testing
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100