0

[ChromeDriver] Update error codes according W3C standard

Updated several error codes returned by ChromeDriver, for compliance
to W3C standard.

Bug: chromedriver:2552
Change-Id: Ie05b784beee8f6e9a79e4c0356e9d3c2dbce3874
Reviewed-on: https://chromium-review.googlesource.com/1187193
Commit-Queue: Tatiana Buldina <buldina@chromium.org>
Reviewed-by: John Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585854}
This commit is contained in:
Tatiana Buldina
2018-08-24 15:45:58 +00:00
committed by Commit Bot
parent 73a943026f
commit 97fe5556de
11 changed files with 36 additions and 39 deletions

@@ -14,8 +14,8 @@ const char* DefaultMessageForStatusCode(StatusCode code) {
switch (code) { switch (code) {
case kOk: case kOk:
return "ok"; return "ok";
case kNoSuchSession: case kInvalidSessionId:
return "no such session"; return "invalid session id";
case kNoSuchElement: case kNoSuchElement:
return "no such element"; return "no such element";
case kNoSuchFrame: case kNoSuchFrame:
@@ -25,7 +25,7 @@ const char* DefaultMessageForStatusCode(StatusCode code) {
case kStaleElementReference: case kStaleElementReference:
return "stale element reference"; return "stale element reference";
case kElementNotVisible: case kElementNotVisible:
return "element not visible"; return "element not interactable";
case kInvalidElementState: case kInvalidElementState:
return "invalid element state"; return "invalid element state";
case kUnknownError: case kUnknownError:
@@ -41,7 +41,7 @@ const char* DefaultMessageForStatusCode(StatusCode code) {
case kJavaScriptError: case kJavaScriptError:
return "javascript error"; return "javascript error";
case kXPathLookupError: case kXPathLookupError:
return "xpath lookup error"; return "invalid selector";
case kTimeout: case kTimeout:
return "timeout"; return "timeout";
case kNoSuchWindow: case kNoSuchWindow:
@@ -53,11 +53,11 @@ const char* DefaultMessageForStatusCode(StatusCode code) {
case kNoSuchAlert: case kNoSuchAlert:
return "no such alert"; return "no such alert";
case kScriptTimeout: case kScriptTimeout:
return "asynchronous script timeout"; return "script timeout";
case kInvalidSelector: case kInvalidSelector:
return "invalid selector"; return "invalid selector";
case kSessionNotCreatedException: case kSessionNotCreated:
return "session not created exception"; return "session not created";
case kNoSuchExecutionContext: case kNoSuchExecutionContext:
return "no such execution context"; return "no such execution context";
case kChromeNotReachable: case kChromeNotReachable:

@@ -10,7 +10,7 @@
// WebDriver standard status codes. // WebDriver standard status codes.
enum StatusCode { enum StatusCode {
kOk = 0, kOk = 0,
kNoSuchSession = 6, kInvalidSessionId = 6,
kNoSuchElement = 7, kNoSuchElement = 7,
kNoSuchFrame = 8, kNoSuchFrame = 8,
kUnknownCommand = 9, kUnknownCommand = 9,
@@ -32,7 +32,7 @@ enum StatusCode {
kNoSuchAlert = 27, kNoSuchAlert = 27,
kScriptTimeout = 28, kScriptTimeout = 28,
kInvalidSelector = 32, kInvalidSelector = 32,
kSessionNotCreatedException = 33, kSessionNotCreated = 33,
// Chrome-specific status codes. // Chrome-specific status codes.
kChromeNotReachable = 100, kChromeNotReachable = 100,
kNoSuchExecutionContext, kNoSuchExecutionContext,

@@ -34,14 +34,14 @@ TEST(StatusTest, ErrorWithCause) {
kUnknownCommand, "quit", kUnknownCommand, "quit",
Status( Status(
kUnknownError, "something happened", kUnknownError, "something happened",
Status(kSessionNotCreatedException))); Status(kSessionNotCreated)));
ASSERT_FALSE(error.IsOk()); ASSERT_FALSE(error.IsOk());
ASSERT_TRUE(error.IsError()); ASSERT_TRUE(error.IsError());
ASSERT_EQ(kUnknownCommand, error.code()); ASSERT_EQ(kUnknownCommand, error.code());
ASSERT_STREQ( ASSERT_STREQ(
"unknown command: quit\n" "unknown command: quit\n"
"from unknown error: something happened\n" "from unknown error: something happened\n"
"from session not created exception", "from session not created",
error.message().c_str()); error.message().c_str());
} }

@@ -225,7 +225,7 @@ Status WaitForDevToolsAndCheckVersion(
if (browser_info->is_android && if (browser_info->is_android &&
browser_info->android_package != capabilities->android_package) { browser_info->android_package != capabilities->android_package) {
return Status( return Status(
kSessionNotCreatedException, kSessionNotCreated,
base::StringPrintf("please close '%s' and try again", base::StringPrintf("please close '%s' and try again",
browser_info->android_package.c_str())); browser_info->android_package.c_str()));
} }
@@ -237,7 +237,7 @@ Status WaitForDevToolsAndCheckVersion(
"cannot be reproduced with this switch removed."; "cannot be reproduced with this switch removed.";
} else if (browser_info->build_no < kMinimumSupportedChromeBuildNo) { } else if (browser_info->build_no < kMinimumSupportedChromeBuildNo) {
return Status( return Status(
kSessionNotCreatedException, kSessionNotCreated,
"Chrome version must be >= " + GetMinimumSupportedChromeVersion()); "Chrome version must be >= " + GetMinimumSupportedChromeVersion());
} }

@@ -43,9 +43,9 @@ class ScriptTimeout(ChromeDriverException):
pass pass
class InvalidSelector(ChromeDriverException): class InvalidSelector(ChromeDriverException):
pass pass
class SessionNotCreatedException(ChromeDriverException): class SessionNotCreated(ChromeDriverException):
pass pass
class NoSuchSession(ChromeDriverException): class InvalidSessionId(ChromeDriverException):
pass pass
class UnexpectedAlertOpen(ChromeDriverException): class UnexpectedAlertOpen(ChromeDriverException):
pass pass
@@ -62,7 +62,7 @@ class UnsupportedOperation(ChromeDriverException):
def _ExceptionForLegacyResponse(response): def _ExceptionForLegacyResponse(response):
exception_class_map = { exception_class_map = {
6: NoSuchSession, 6: InvalidSessionId,
7: NoSuchElement, 7: NoSuchElement,
8: NoSuchFrame, 8: NoSuchFrame,
9: UnknownCommand, 9: UnknownCommand,
@@ -82,7 +82,7 @@ def _ExceptionForLegacyResponse(response):
27: NoSuchAlert, 27: NoSuchAlert,
28: ScriptTimeout, 28: ScriptTimeout,
32: InvalidSelector, 32: InvalidSelector,
33: SessionNotCreatedException, 33: SessionNotCreated,
105: NoSuchCookie 105: NoSuchCookie
} }
status = response['status'] status = response['status']
@@ -91,24 +91,24 @@ def _ExceptionForLegacyResponse(response):
def _ExceptionForStandardResponse(response): def _ExceptionForStandardResponse(response):
exception_map = { exception_map = {
'no such session' : NoSuchSession, 'invalid session id' : InvalidSessionId,
'no such element': NoSuchElement, 'no such element': NoSuchElement,
'no such frame': NoSuchFrame, 'no such frame': NoSuchFrame,
'unknown command': UnknownCommand, 'unknown command': UnknownCommand,
'stale element reference': StaleElementReference, 'stale element reference': StaleElementReference,
'element not visible': ElementNotVisible, 'element not interactable': ElementNotVisible,
'invalid element state': InvalidElementState, 'invalid element state': InvalidElementState,
'unknown error': UnknownError, 'unknown error': UnknownError,
'javascript error': JavaScriptError, 'javascript error': JavaScriptError,
'xpath lookup error': XPathLookupError, 'invalid selector': XPathLookupError,
'timeout': Timeout, 'timeout': Timeout,
'no such window': NoSuchWindow, 'no such window': NoSuchWindow,
'invalid cookie domain': InvalidCookieDomain, 'invalid cookie domain': InvalidCookieDomain,
'unexpected alert open': UnexpectedAlertOpen, 'unexpected alert open': UnexpectedAlertOpen,
'no such alert': NoSuchAlert, 'no such alert': NoSuchAlert,
'asynchronous script timeout': ScriptTimeout, 'script timeout': ScriptTimeout,
'invalid selector': InvalidSelector, 'invalid selector': InvalidSelector,
'session not created exception': SessionNotCreatedException, 'session not created': SessionNotCreated,
'no such cookie': NoSuchCookie, 'no such cookie': NoSuchCookie,
'invalid argument': InvalidArgument, 'invalid argument': InvalidArgument,
'element not interactable': ElementNotInteractable, 'element not interactable': ElementNotInteractable,

@@ -212,7 +212,7 @@ void ExecuteSessionCommandOnSessionThread(
cmd_task_runner->PostTask( cmd_task_runner->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(callback_on_cmd, base::BindOnce(callback_on_cmd,
Status(return_ok_without_session ? kOk : kNoSuchSession), Status(return_ok_without_session ? kOk : kInvalidSessionId),
std::unique_ptr<base::Value>(), std::string(), false)); std::unique_ptr<base::Value>(), std::string(), false));
return; return;
} }
@@ -317,7 +317,7 @@ void ExecuteSessionCommand(
const CommandCallback& callback) { const CommandCallback& callback) {
SessionThreadMap::iterator iter = session_thread_map->find(session_id); SessionThreadMap::iterator iter = session_thread_map->find(session_id);
if (iter == session_thread_map->end()) { if (iter == session_thread_map->end()) {
Status status(return_ok_without_session ? kOk : kNoSuchSession); Status status(return_ok_without_session ? kOk : kInvalidSessionId);
callback.Run(status, std::unique_ptr<base::Value>(), session_id, false); callback.Run(status, std::unique_ptr<base::Value>(), session_id, false);
} else { } else {
iter->second->task_runner()->PostTask( iter->second->task_runner()->PostTask(

@@ -265,7 +265,7 @@ void OnNoSuchSession(const Status& status,
std::unique_ptr<base::Value> value, std::unique_ptr<base::Value> value,
const std::string& session_id, const std::string& session_id,
bool w3c_compliant) { bool w3c_compliant) {
EXPECT_EQ(kNoSuchSession, status.code()); EXPECT_EQ(kInvalidSessionId, status.code());
EXPECT_FALSE(value.get()); EXPECT_FALSE(value.get());
} }
@@ -311,7 +311,7 @@ void OnNoSuchSessionAndQuit(base::RunLoop* run_loop,
const std::string& session_id, const std::string& session_id,
bool w3c_compliant) { bool w3c_compliant) {
run_loop->Quit(); run_loop->Quit();
EXPECT_EQ(kNoSuchSession, status.code()); EXPECT_EQ(kInvalidSessionId, status.code());
EXPECT_FALSE(value.get()); EXPECT_FALSE(value.get());
} }

@@ -792,7 +792,7 @@ HttpHandler::PrepareStandardResponse(
response.reset( response.reset(
new net::HttpServerResponseInfo(net::HTTP_REQUEST_TIMEOUT)); new net::HttpServerResponseInfo(net::HTTP_REQUEST_TIMEOUT));
break; break;
case kSessionNotCreatedException: case kSessionNotCreated:
response.reset( response.reset(
new net::HttpServerResponseInfo(net::HTTP_INTERNAL_SERVER_ERROR)); new net::HttpServerResponseInfo(net::HTTP_INTERNAL_SERVER_ERROR));
break; break;
@@ -832,7 +832,7 @@ HttpHandler::PrepareStandardResponse(
case kNoSuchExecutionContext: case kNoSuchExecutionContext:
response.reset(new net::HttpServerResponseInfo(net::HTTP_BAD_REQUEST)); response.reset(new net::HttpServerResponseInfo(net::HTTP_BAD_REQUEST));
break; break;
case kNoSuchSession: case kInvalidSessionId:
case kChromeNotReachable: case kChromeNotReachable:
case kDisconnected: case kDisconnected:
case kForbidden: case kForbidden:

@@ -160,22 +160,22 @@ Status CheckSessionCreated(Session* session) {
WebView* web_view = NULL; WebView* web_view = NULL;
Status status = session->GetTargetWindow(&web_view); Status status = session->GetTargetWindow(&web_view);
if (status.IsError()) if (status.IsError())
return Status(kSessionNotCreatedException, status); return Status(kSessionNotCreated, status);
status = web_view->ConnectIfNecessary(); status = web_view->ConnectIfNecessary();
if (status.IsError()) if (status.IsError())
return Status(kSessionNotCreatedException, status); return Status(kSessionNotCreated, status);
base::ListValue args; base::ListValue args;
std::unique_ptr<base::Value> result(new base::Value(0)); std::unique_ptr<base::Value> result(new base::Value(0));
status = web_view->CallFunction(session->GetCurrentFrameId(), status = web_view->CallFunction(session->GetCurrentFrameId(),
"function(s) { return 1; }", args, &result); "function(s) { return 1; }", args, &result);
if (status.IsError()) if (status.IsError())
return Status(kSessionNotCreatedException, status); return Status(kSessionNotCreated, status);
int response; int response;
if (!result->GetAsInteger(&response) || response != 1) { if (!result->GetAsInteger(&response) || response != 1) {
return Status(kSessionNotCreatedException, return Status(kSessionNotCreated,
"unexpected response from browser"); "unexpected response from browser");
} }
@@ -214,7 +214,7 @@ Status InitSessionHelper(const InitSessionParams& bound_params,
continue; continue;
} }
if (!MergeCapabilities(desired_caps, first_match, &merged_caps)) { if (!MergeCapabilities(desired_caps, first_match, &merged_caps)) {
return Status(kSessionNotCreatedException, "Invalid capabilities"); return Status(kSessionNotCreated, "Invalid capabilities");
} }
if (MatchCapabilities(&merged_caps)) { if (MatchCapabilities(&merged_caps)) {
// If a match is found, we want to use these matched setcapabilities. // If a match is found, we want to use these matched setcapabilities.
@@ -231,7 +231,7 @@ Status InitSessionHelper(const InitSessionParams& bound_params,
// TODO(johnchen): Remove when clients stop using this. // TODO(johnchen): Remove when clients stop using this.
session->w3c_compliant = true; session->w3c_compliant = true;
} else if (!params.GetDictionary("desiredCapabilities", &desired_caps)) { } else if (!params.GetDictionary("desiredCapabilities", &desired_caps)) {
return Status(kSessionNotCreatedException, return Status(kSessionNotCreated,
"Missing or invalid capabilities"); "Missing or invalid capabilities");
} }

@@ -1115,7 +1115,7 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=547 # https://bugs.chromium.org/p/chromedriver/issues/detail?id=547
self.assertRaises(chromedriver.UnknownError, self.assertRaises(chromedriver.UnknownError,
self._driver.Load, 'chrome://crash') self._driver.Load, 'chrome://crash')
self.assertRaises(chromedriver.NoSuchSession, self.assertRaises(chromedriver.InvalidSessionId,
self._driver.GetCurrentUrl) self._driver.GetCurrentUrl)
def testDoesntHangOnDebugger(self): def testDoesntHangOnDebugger(self):
@@ -2515,7 +2515,7 @@ class MobileEmulationCapabilityTest(ChromeDriverBaseTest):
def testW3cCompliantResponses(self): def testW3cCompliantResponses(self):
# It's an error to send W3C format request without W3C capability flag. # It's an error to send W3C format request without W3C capability flag.
with self.assertRaises(chromedriver.SessionNotCreatedException): with self.assertRaises(chromedriver.SessionNotCreated):
self.CreateDriver(send_w3c_request=True) self.CreateDriver(send_w3c_request=True)
# W3C capability flag is ignored in a legacy format request. # W3C capability flag is ignored in a legacy format request.

@@ -2,9 +2,6 @@
Below is a list of all WebDriver commands and their current support in ChromeDriver based on what is in the [WebDriver Specification](https://w3c.github.io/webdriver/webdriver-spec.html). Below is a list of all WebDriver commands and their current support in ChromeDriver based on what is in the [WebDriver Specification](https://w3c.github.io/webdriver/webdriver-spec.html).
Notes:
- Currently some error strings returned by ChromeDriver are incorrect. This is tracked by bug [2552](https://bugs.chromium.org/p/chromedriver/issues/detail?id=2552).
| Method | URL | Command | Status | Bug | Method | URL | Command | Status | Bug
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| POST | /session | New Session | Partially Complete | [1997](https://bugs.chromium.org/p/chromedriver/issues/detail?id=1997) [2537](https://bugs.chromium.org/p/chromedriver/issues/detail?id=2537) | POST | /session | New Session | Partially Complete | [1997](https://bugs.chromium.org/p/chromedriver/issues/detail?id=1997) [2537](https://bugs.chromium.org/p/chromedriver/issues/detail?id=2537)