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

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

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

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

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

@ -212,7 +212,7 @@ void ExecuteSessionCommandOnSessionThread(
cmd_task_runner->PostTask(
FROM_HERE,
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));
return;
}
@ -317,7 +317,7 @@ void ExecuteSessionCommand(
const CommandCallback& callback) {
SessionThreadMap::iterator iter = session_thread_map->find(session_id);
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);
} else {
iter->second->task_runner()->PostTask(

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

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

@ -160,22 +160,22 @@ Status CheckSessionCreated(Session* session) {
WebView* web_view = NULL;
Status status = session->GetTargetWindow(&web_view);
if (status.IsError())
return Status(kSessionNotCreatedException, status);
return Status(kSessionNotCreated, status);
status = web_view->ConnectIfNecessary();
if (status.IsError())
return Status(kSessionNotCreatedException, status);
return Status(kSessionNotCreated, status);
base::ListValue args;
std::unique_ptr<base::Value> result(new base::Value(0));
status = web_view->CallFunction(session->GetCurrentFrameId(),
"function(s) { return 1; }", args, &result);
if (status.IsError())
return Status(kSessionNotCreatedException, status);
return Status(kSessionNotCreated, status);
int response;
if (!result->GetAsInteger(&response) || response != 1) {
return Status(kSessionNotCreatedException,
return Status(kSessionNotCreated,
"unexpected response from browser");
}
@ -214,7 +214,7 @@ Status InitSessionHelper(const InitSessionParams& bound_params,
continue;
}
if (!MergeCapabilities(desired_caps, first_match, &merged_caps)) {
return Status(kSessionNotCreatedException, "Invalid capabilities");
return Status(kSessionNotCreated, "Invalid capabilities");
}
if (MatchCapabilities(&merged_caps)) {
// 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.
session->w3c_compliant = true;
} else if (!params.GetDictionary("desiredCapabilities", &desired_caps)) {
return Status(kSessionNotCreatedException,
return Status(kSessionNotCreated,
"Missing or invalid capabilities");
}

@ -1115,7 +1115,7 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=547
self.assertRaises(chromedriver.UnknownError,
self._driver.Load, 'chrome://crash')
self.assertRaises(chromedriver.NoSuchSession,
self.assertRaises(chromedriver.InvalidSessionId,
self._driver.GetCurrentUrl)
def testDoesntHangOnDebugger(self):
@ -2515,7 +2515,7 @@ class MobileEmulationCapabilityTest(ChromeDriverBaseTest):
def testW3cCompliantResponses(self):
# 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)
# 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).
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
| --- | --- | --- | --- | --- |
| 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)