microsoft / microsoft/playwright-java
[Feature]: JUnit: Allow the user to control the Browser object's lifecycle
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Java
- Star
- 1.6k
- Fork
- 298
- Merge trung bình
- 3 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 14
Mô tả
🚀 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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách theo dõi Options của tiện ích mở rộng JUnit, các phương thức TestWatcher hiện có, BrowserExtension.closeBrowser() và fixture tạo lại Browser. Xác nhận cách tùy chọn được đọc và cách việc tái sử dụng trình duyệt hiện đang hoạt động. Hoàn thành khi một cài đặt opt-in đóng Browser sau mỗi bài kiểm thử và bài kiểm thử tiếp theo tạo một phiên mới với các tùy chọn hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- testing
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100