[Bug]: tracing.stop(path=...) and record_har_path ignore os.chdir() for relative paths

Đang mở Phù hợp với người mới
#3,361 0 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
74/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

Người báo cáo chỉ vào Artifact.save_as, thứ đã tuyệt đối hóa đường dẫn của nó trước khi gửi đến driver; hãy bắt đầu ở đó và xem nó làm như thế nào. Sau đó tìm hai chỗ serialize tracing.stop(path=...) và tùy chọn context record_har_path đến driver và áp dụng cách xử lý tương tự. Script repro trong issue là bước kiểm tra: sau os.chdir(target), trace.zip và rel.har sẽ nằm trong cwd mới giống như shot.png, ở cả API sync và async.

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

Mô tả

Version

1.65.2 (same on 1.64.0)

Steps to reproduce

Relative paths for traces and HARs are resolved against the directory the driver was started in, not the current one. Screenshots use the current one, so in one script the files end up in two places:

import os, tempfile
from playwright.sync_api import sync_playwright

start = os.getcwd()
with sync_playwright() as p:
    target = tempfile.mkdtemp()
    os.chdir(target)
    ctx = p.chromium.launch().new_context(record_har_path="rel.har")
    ctx.tracing.start()
    page = ctx.new_page()
    page.goto("data:text/html,x")
    ctx.tracing.stop(path="trace.zip")
    page.screenshot(path="shot.png")
    ctx.close()
    for f in ("trace.zip", "rel.har", "shot.png"):
        print(f, os.path.exists(os.path.join(target, f)), os.path.exists(os.path.join(start, f)))
Expected behavior

All three files in target.

Actual behavior
trace.zip False True
rel.har False True
shot.png True False

Hits anyone using monkeypatch.chdir() with a session-scoped playwright. Artifact.save_as already makes the path absolute before sending it; tracing and HAR don't.

Additional context

No response

Environment
- Operating System: macOS 27.2
- CPU: arm64
- Browser: Chromium
- Python Version: 3.14
- Other info:
Ngôn ngữ chính
Python
Star
15.1k
Fork
1.3k
Merge trung bình
6 giờ 16 phút
Pull request đã merge (30 ngày)
53

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 microsoft/playwright-python

Tất cả issue của microsoft/playwright-python

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.