Skip to content

Commit

Permalink
Fix webdriver links. (youtube#371)
Browse files Browse the repository at this point in the history
This updates webdriver links to their new locations, with versioning.

b/200993308
  • Loading branch information
jellefoks authored May 15, 2023
1 parent a16f613 commit 6316eb6
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cobalt/webdriver/algorithms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ std::string GetElementText(dom::Element* element) {
}

// There is a spec for "displayedness" available:
// https://w3c.github.io/webdriver/webdriver-spec.html#element-displayedness
// https://www.w3.org/TR/2015/WD-webdriver-20150808/#element-displayedness
// However, the algorithm described in the spec does not match existing
// implementations of WebDriver.
// IsDisplayed will match the existing implementations, using the implementation
Expand Down
4 changes: 2 additions & 2 deletions cobalt/webdriver/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ namespace webdriver {
namespace algorithms {

// Implementation of getElementText algorithm.
// https://w3c.github.io/webdriver/webdriver-spec.html#getelementtext
// https://www.w3.org/TR/2015/WD-webdriver-20150808/#getelementtext
// The spec is not totally clear and, according to comments on the spec, does
// not exactly match the behavior of existing WebDriver implementations. This
// implementation will follow the de-facto standards where they differ.
std::string GetElementText(dom::Element* element);

// https://w3c.github.io/webdriver/webdriver-spec.html#element-displayedness
// https://www.w3.org/TR/2015/WD-webdriver-20150808/#element-displayedness
// The spec does not exactly match the behavior of existing WebDriver
// implementations. Consistency with existing implementations will be preferred
// over strict conformance to the draft spec.
Expand Down
6 changes: 3 additions & 3 deletions cobalt/webdriver/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class WebDriverDispatcher {
};
// Send the result of the execution of a registered WebDriver command to be
// sent as a response as described in the spec:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Responses
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Failed-Commands
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#responses
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#failed-commands
virtual void SendResult(
const base::Optional<protocol::SessionId>& session_id,
protocol::Response::StatusCode status_code,
Expand All @@ -95,7 +95,7 @@ class WebDriverDispatcher {
// Some forms of Invalid Requests are detected in the CommandCallback by
// checking the path variables and command parameters. Invalid requests are
// described here:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Invalid-Requests
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#invalid-requests
//
// TODO: Invalid requests should be handled before calling the
// CommandCallback.
Expand Down
6 changes: 3 additions & 3 deletions cobalt/webdriver/element_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ util::CommandResult<void> ElementDriver::SendClickInternal(
return CommandResult(protocol::Response::kElementNotVisible);
}
// Click on an element.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidelementidclick
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidelementidclick
// The Element Click clicks the in-view center point of the element
// https://w3c.github.io/webdriver/webdriver-spec.html#dfn-element-click
// https://www.w3.org/TR/2015/WD-webdriver-20150808/#click

// An element's in-view center point is the origin position of the rectangle
// that is the intersection between the element's first DOM client rectangle
// and the initial viewport.
// https://w3c.github.io/webdriver/webdriver-spec.html#dfn-in-view-center-point
// https://www.w3.org/TR/2017/WD-webdriver-20170125/#dfn-in-view-center-point
scoped_refptr<dom::DOMRectList> dom_rects = element_->GetClientRects();
if (dom_rects->length() == 0) {
return CommandResult(protocol::Response::kElementNotVisible);
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/element_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class WindowDriver;

// ElementDriver could be considered a WebElement as described in the WebDriver
// spec.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#webelement
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#webelement
// Commands that interact with a WebElement, such as:
// /session/:sessionId/element/:id/some_command
// will map to a method on this class.
Expand Down
6 changes: 3 additions & 3 deletions cobalt/webdriver/protocol/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace protocol {

// Represents the JSON parameters passed to the click, buttondown, and buttonup
// WebDriver commands.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidelementidclick
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidbuttondown
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidbuttonup
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidelementidclick
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidbuttondown
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidbuttonup
class Button {
public:
static std::unique_ptr<base::Value> ToValue(const Button& button);
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/protocol/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Capabilities {
private:
Capabilities() {}
// The capabilities listed here:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Capabilities-JSON-Object
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#capabilities-json-object

base::Optional<std::string> browser_name_;
base::Optional<std::string> version_;
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/protocol/cookie.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace cobalt {
namespace webdriver {
namespace protocol {

// https://w3c.github.io/webdriver/webdriver-spec.html#cookies
// https://www.w3.org/TR/2015/WD-webdriver-20150808/#cookies
class Cookie {
public:
static std::unique_ptr<base::Value> ToValue(const Cookie& cookie);
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/protocol/element_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ElementId {
static const char kElementKey[];

// Convert the ElementId to a WebElement JSON object:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#WebElement-JSON-Object
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#webelement-json-object
static std::unique_ptr<base::Value> ToValue(const ElementId& element_id);
static base::Optional<ElementId> FromValue(const base::Value* value);

Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/protocol/frame_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace cobalt {
namespace webdriver {
namespace protocol {

// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidframe
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidframe
// Since Cobalt doesn't support multiple frames, the only valid value for this
// command is to request switching to the top-level browsing context, which
// is always active.
Expand Down
6 changes: 3 additions & 3 deletions cobalt/webdriver/protocol/log_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <memory>

#include "cobalt/webdriver/protocol/log_entry.h"

#include <memory>

#include "base/logging.h"

namespace cobalt {
Expand Down Expand Up @@ -48,7 +48,7 @@ std::unique_ptr<base::Value> LogEntry::ToValue(const LogEntry& log_entry) {
std::unique_ptr<base::DictionaryValue> log_entry_value(
new base::DictionaryValue());
// Format of the Log Entry object can be found here:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Log-Entry-JSON-Object
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#log-entry-json-object
// timestamp is in milliseconds since the Unix Epoch.
log_entry_value->SetInteger("timestamp",
log_entry.timestamp_.InMilliseconds());
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/protocol/log_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace webdriver {
namespace protocol {

// Log entry object:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Log-Entry-JSON-Object
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#log-entry-json-object
class LogEntry {
public:
enum LogLevel {
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/protocol/moveto.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace webdriver {
namespace protocol {

// Represents the JSON parameters passed to the moveto WebDriver command.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidmoveto
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidmoveto
class Moveto {
public:
static std::unique_ptr<base::Value> ToValue(const Moveto& moveto);
Expand Down
6 changes: 3 additions & 3 deletions cobalt/webdriver/protocol/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace protocol {
class Response {
public:
// WebDriver Response Status Codes:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Response-Status-Codes
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#response-status-codes
enum StatusCode {
// The command executed successfully.
kSuccess = 0,
Expand Down Expand Up @@ -79,13 +79,13 @@ class Response {

// Create a JSON object that will be used as the response body for a failed
// command:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Failed-Commands
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#failed-commands
// TODO: Add support for screenshot, stack trace, etc.
static std::unique_ptr<base::Value> CreateErrorResponse(
const std::string& message);

// Create a JSON object that will be used as the response body for a command:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Responses
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#responses
static std::unique_ptr<base::Value> CreateResponse(
const base::Optional<protocol::SessionId>& session_id,
StatusCode status_code,
Expand Down
4 changes: 2 additions & 2 deletions cobalt/webdriver/protocol/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace protocol {

// Represents the JSON parameters passed to the execute and execute_async
// WebDriver commands.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidexecute
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidexecute-async
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidexecute
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidexecute_async
class Script {
public:
static base::Optional<Script> FromValue(const base::Value* script);
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/protocol/server_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace protocol {

// Represents the JSON object that describes the WebDriver server's current
// status in response to the /status command:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#status
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#status
class ServerStatus {
public:
ServerStatus();
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/protocol/session_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace webdriver {
namespace protocol {

// sessionId is mentioned in the spec describing WebDriver responses:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Responses
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#responses
//
class SessionId {
public:
Expand Down
6 changes: 3 additions & 3 deletions cobalt/webdriver/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ResponseHandlerImpl : public WebDriverServer::ResponseHandler {
server_(server),
connection_id_(connection_id) {}

// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Responses
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#responses
void Success(std::unique_ptr<base::Value> value) override {
DCHECK(value);
std::string data;
Expand All @@ -96,7 +96,7 @@ class ResponseHandlerImpl : public WebDriverServer::ResponseHandler {
// Failed commands map to a valid WebDriver command and contain the expected
// parameters, but otherwise failed to execute for some reason. This should
// send a 500 Internal Server Error.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Error-Handling
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#error-handling
void FailedCommand(std::unique_ptr<base::Value> value) override {
DCHECK(value);
std::string data;
Expand All @@ -105,7 +105,7 @@ class ResponseHandlerImpl : public WebDriverServer::ResponseHandler {
}

// A number of cases for invalid requests are explained here:
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Invalid-Requests
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#invalid-requests
// The response type should be text/plain and the message body is an error
// message

Expand Down
6 changes: 3 additions & 3 deletions cobalt/webdriver/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ class WebDriverServer : public net::HttpServer::Delegate {
class ResponseHandler {
public:
// Called after a successful WebDriver command.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Responses
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#responses
virtual void Success(std::unique_ptr<base::Value>) = 0;
// |content_type| specifies the type of the data using HTTP mime types.
virtual void SuccessData(const std::string& content_type, const char* data,
int len) = 0;

// Called after a failed WebDriver command
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Failed-Commands
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#failed-commands
virtual void FailedCommand(std::unique_ptr<base::Value>) = 0;

// Called after an invalid request.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Invalid-Requests
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#invalid-requests
virtual void UnknownCommand(const std::string& path) = 0;
virtual void UnimplementedCommand(const std::string& path) = 0;
virtual void VariableResourceNotFound(const std::string& variable_name) = 0;
Expand Down
13 changes: 8 additions & 5 deletions cobalt/webdriver/testdata/simple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import requests

# This is a simple script for Webdriver Wire Protocol communication.
# https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
# https://www.selenium.dev/documentation/legacy/json_wire_protocol

WEBDRIVER_HOST = 'http://localhost:4444'

Expand All @@ -30,7 +30,7 @@
DELETE = 'DELETE'

# WebDriver Response Status Codes:
# https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#Response-Status-Codes
# https://www.selenium.dev/documentation/legacy/json_wire_protocol/#response-status-codes

RESPONSE_STATUS_CODES = {
0: 'Success',
Expand Down Expand Up @@ -75,11 +75,14 @@ def Request(request_type, path='', parameters=None):
url = f'{WEBDRIVER_HOST}/{path}'
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
if request_type == GET:
request = requests.get(url, data=json.dumps(parameters), headers=headers)
request = requests.get(
url, data=json.dumps(parameters), headers=headers, timeout=10)
if request_type == POST:
request = requests.post(url, data=json.dumps(parameters), headers=headers)
request = requests.post(
url, data=json.dumps(parameters), headers=headers, timeout=10)
if request_type == DELETE:
request = requests.delete(url, data=json.dumps(parameters), headers=headers)
request = requests.delete(
url, data=json.dumps(parameters), headers=headers, timeout=10)
result = request.text if request.headers[
'content-type'] == 'text/plain' else request.json()
if request.status_code == 200:
Expand Down
10 changes: 5 additions & 5 deletions cobalt/webdriver/web_driver_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ SessionDriver* WebDriverModule::GetSessionDriver(
return NULL;
}

// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#status
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#status
void WebDriverModule::GetServerStatus(
const base::Value* parameters,
const WebDriverDispatcher::PathVariableMap* path_variables,
Expand All @@ -531,7 +531,7 @@ void WebDriverModule::GetServerStatus(
protocol::ServerStatus::ToValue(status_));
}

// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessions
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessions
void WebDriverModule::GetActiveSessions(
const base::Value* parameters,
const WebDriverDispatcher::PathVariableMap* path_variables,
Expand All @@ -545,7 +545,7 @@ void WebDriverModule::GetActiveSessions(
util::internal::ToValue(sessions));
}

// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#get-sessionsessionid
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionid
void WebDriverModule::CreateSession(
const base::Value* parameters,
const WebDriverDispatcher::PathVariableMap* path_variables,
Expand All @@ -571,7 +571,7 @@ void WebDriverModule::CreateSession(
result_handler.get());
}

// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#delete-sessionsessionid
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessions
void WebDriverModule::DeleteSession(
const base::Value* parameters,
const WebDriverDispatcher::PathVariableMap* path_variables,
Expand Down Expand Up @@ -634,7 +634,7 @@ void WebDriverModule::StopScreencast(
}
}

// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidscreenshot
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidscreenshot
void WebDriverModule::RequestScreenshot(
const base::Value* parameters,
const WebDriverDispatcher::PathVariableMap* path_variables,
Expand Down
2 changes: 1 addition & 1 deletion cobalt/webdriver/window_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ util::CommandResult<void> WindowDriver::MouseMoveToInternal(
// specified, the move is relative to the current mouse cursor. If an element
// is provided but no offset, the mouse will be moved to the center of the
// element.
// https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidmoveto
// https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidmoveto
float x = 0;
float y = 0;
scoped_refptr<dom::Element> element;
Expand Down

0 comments on commit 6316eb6

Please sign in to comment.