New Session

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Lệnh New Session của API WebDriver tạo một phiên WebDriver mới với trình duyệt. Định danh phiên được trả về trong phản hồi là bắt buộc cho mọi lệnh tiếp theo.

Cú pháp

Method URI template
POST /session

Dữ liệu gửi lên

capabilities

Dùng để xác định các tính năng mà driver phải đáp ứng khi tạo phiên mới. Xem Capabilities để biết các tùy chọn có sẵn.

Phản hồi

Phần dữ liệu phản hồi là một đối tượng JSON với:

sessionId

Định danh duy nhất của phiên.

capabilities

Các capability đã được thương lượng của phiên.

Lỗi

Session not created

Không thể tạo phiên mới.

Ví dụ

Khởi tạo một phiên mới

Với một WebDriver server đang chạy trên localhost:4444, lệnh sau sẽ khởi động một phiên WebDriver mới yêu cầu Firefox làm trình duyệt:

bash
curl -i -H "Content-Type: application/json" -d '{"capabilities": {"alwaysMatch": {"browserName": "firefox"}}}' http://localhost:4444/session

Kết quả sẽ trông tương tự như sau, trong đó 27c8437e-5e42-43f9-a26f-2db0fd509ec1 là định danh duy nhất của phiên này:

http
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{"value":{"sessionId":"27c8437e-5e42-43f9-a26f-2db0fd509ec1","capabilities":{"acceptInsecureCerts":false,"browserName":"firefox","browserVersion":"147.0.4","pageLoadStrategy":"normal","platformName":"mac","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000}}}}

Đặc tả

Thông số kỹ thuật
WebDriver
# new-session

Tương thích trình duyệt

Xem thêm