microsoft / microsoft/playwright-java

[Feature]: JUnit: Allow the user to control the Browser object's lifecycle

Đang mở
#1,691 8 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

P3-collecting-feedback
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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.