IndexError masks failures from JavaScript extension keywords with *args

Đang mở Phù hợp với người mới
#5,306 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu với _get_selector_value_from_keyword_call() trong Browser/browser.py và theo dõi cách hàm này khớp các giá trị được truyền với chữ ký keyword. Tái hiện sự cố bằng tiện ích mở rộng JavaScript và bài kiểm thử Robot được cung cấp. Hoàn thành khi lỗi báo lỗi gốc boom: ["a","b"] thay vì phát sinh IndexError.

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

Mô tả

priority: high

Describe the bug
When a JavaScript extension keyword declares a parameter named args and is called with multiple positional arguments, a keyword failure can be replaced by an IndexError during Browser’s failure handling. This hides the original exception and makes the failure difficult to diagnose.

To Reproduce
Steps to reproduce the behavior:
JavaScript extension:

async function boom(args) {
  throw new Error(`boom: ${JSON.stringify(args)}`);
}

exports.Boom = boom;

Robot test:

*** Test Cases ***
Failure Should Preserve Original Error
    Boom    a    b

Expected behavior
The JavaScript keyword receives both values, but the failure handling path raises IndexError: list index out of range while inspecting the keyword arguments, instead of reporting the original boom: ["a","b"] error.

cause
The generated Python signature turns a JavaScript parameter called args into *args. When _get_selector_value_from_keyword_call() tries to match the values passed to the keyword with the keyword signature, it checks the actual values instead of the signature itself. With multiple values, it can end up looking past the end of the signature and throw an IndexError.

suggested fix
Change _get_selector_value_from_keyword_call() method to:

    def _get_selector_value_from_keyword_call(self, name, args, kwargs):
        selector = kwargs.get("selector")
        if not selector and args:
            arguments = self.get_keyword_arguments(name)
            for i, arg in enumerate(args):
                if i >= len(arguments):
                    break
                spec = arguments[i][0] if isinstance(arguments[i], tuple) else arguments[i]
                if spec.startswith("*"):
                    break
                if spec.startswith("selector"):
                    selector = arg
                    break
        return selector

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: chromium
  • Version: 151.0.7922.34
Ngôn ngữ chính
Python
Star
662
Fork
149
Merge trung bình
6 giờ 13 phút
Pull request đã merge (30 ngày)
121

Chuẩn bị môi trường

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 MarketSquare/robotframework-browser

Tất cả issue của MarketSquare/robotframework-browser

Issue tương tự

Thêm issue về Python

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.