Wrong context set when using within

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

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
javascript, playwright
Lĩnh vực
testing-qa

Hướng nghiên cứu

Bắt đầu bằng cách lần theo hàm _getContext và phần triển khai của within, sau đó chạy ví dụ modal được cung cấp cùng với waitForEnabled. Kiểm tra hành vi liên quan của waitForDisabled, waitNumberOfVisibleElements, waitForValue và waitForText. Hoàn tất khi within('.modal-dialog') sử dụng đúng context của page hoặc frame và các helper này hoạt động bên trong block mà không có lỗi context.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

stale

Description

After updating to CodeceptJS version 3.6.10 (also occurring in 3.7.0), we noticed that the within functionality no longer works correctly when used with a selector like .modal-dialog. Instead of setting the context to a page or frame object, it sets it to a locator object, which causes an error when trying to execute certain functions.

The error encountered:

context.waitForFunction is not a function

This error occurred in the waitForEnabled function, which expects context to be a page object, but instead it is passed as a locator because of the changes introduced with: #4557
Other helper functions that we found that produce the same error: waitForDisabled, waitNumberOfVisibleElements, waitForValue.
We also observed other functions like waitForText not working correctly inside within (e.g. not finding text inside the within context although it was obviously there).
Specifically this line in the _getContext function breaks this use case, since it now returns this.context even if it is a locator object:

  async _getContext() {
    if ((this.context && this.context.constructor.name === 'FrameLocator') || this.context) {
      return this.context
    }
...

Everything worked fine again after reverting the changes that were introduced by this commit.

Steps to Reproduce

  1. Use the within function with a selector such as .modal-dialog.
  2. Attempt to run a command inside the within block, like waitForEnabled.
  3. Observe the error message.
Example test case:
Feature('Modal Test');

Scenario('Test modal within', async ({ I }) => {
  I.amOnPage('https://example.com'); 
  I.click('.open-modal');
  within('.modal-dialog', async () => {
   I.waitForEnabled('.button')
  });
});

Details

  • CodeceptJS version: 3.6.10 and 3.7.0
  • NodeJS Version: 23.7.0
  • playwright-core version: 1.49.1
Ngôn ngữ chính
JavaScript
Star
4.2k
Fork
756
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
16

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.

Issue khác của codeceptjs/CodeceptJS

Tất cả issue của codeceptjs/CodeceptJS

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.