Skip to content

Commit fe9bb9d

Browse files
committed
WebDriver: handle invalid selector errors
https://bugs.webkit.org/show_bug.cgi?id=174619 Reviewed by Brian Burg. Source/WebDriver: Add InvalidSelector error and handle it in case of protocol server error. * CommandResult.cpp: (WebDriver::CommandResult::CommandResult): (WebDriver::CommandResult::httpStatusCode): (WebDriver::CommandResult::errorString): * CommandResult.h: Source/WebKit: We are currently handling only XPathException and only when it's an invalid expression. In the xpath case, the spec also says "If any item in result is not an element return an error with error code invalid selector.", so we should also handle TYPE_ERR (The expression could not be converted to return the specified type.). However, since the spec says "or other error", I think we can simplify this and simply throw InvalidSelector inside the catch, without checking any specific error. This is causing 14 failures in selenium tests. §12. Element Retrieval. Step 6: If a DOMException, SyntaxError, XPathException, or other error occurs during the execution of the element location strategy, return error invalid selector. https://www.w3.org/TR/webdriver/#dfn-find * UIProcess/Automation/Automation.json: Add InvalidSelector error. * UIProcess/Automation/atoms/FindNodes.js: (tryToFindNode): Raise InvalidSelector in case of error. * WebProcess/Automation/WebAutomationSessionProxy.cpp: (WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction): Handle InvalidSelector exceptions. Canonical link: https://commits.webkit.org/191463@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219652 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent bc5cfb7 commit fe9bb9d

7 files changed

Lines changed: 52 additions & 6 deletions

File tree

Source/WebDriver/ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2017-07-18 Carlos Garcia Campos <[email protected]>
2+
3+
WebDriver: handle invalid selector errors
4+
https://bugs.webkit.org/show_bug.cgi?id=174619
5+
6+
Reviewed by Brian Burg.
7+
8+
Add InvalidSelector error and handle it in case of protocol server error.
9+
10+
* CommandResult.cpp:
11+
(WebDriver::CommandResult::CommandResult):
12+
(WebDriver::CommandResult::httpStatusCode):
13+
(WebDriver::CommandResult::errorString):
14+
* CommandResult.h:
15+
116
2017-07-18 Carlos Alberto Lopez Perez <[email protected]>
217

318
[GTK] Fix build with Clang after r219605.

Source/WebDriver/CommandResult.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ CommandResult::CommandResult(RefPtr<InspectorValue>&& result, std::optional<Erro
9898
m_errorCode = ErrorCode::InvalidArgument;
9999
else if (errorName == "InvalidElementState")
100100
m_errorCode = ErrorCode::InvalidElementState;
101+
else if (errorName == "InvalidSelector")
102+
m_errorCode = ErrorCode::InvalidSelector;
101103

102104
break;
103105
}
@@ -120,6 +122,7 @@ unsigned CommandResult::httpStatusCode() const
120122
switch (m_errorCode.value()) {
121123
case ErrorCode::InvalidArgument:
122124
case ErrorCode::InvalidElementState:
125+
case ErrorCode::InvalidSelector:
123126
case ErrorCode::NoSuchElement:
124127
case ErrorCode::NoSuchFrame:
125128
case ErrorCode::NoSuchWindow:
@@ -150,6 +153,8 @@ String CommandResult::errorString() const
150153
return ASCIILiteral("invalid argument");
151154
case ErrorCode::InvalidElementState:
152155
return ASCIILiteral("invalid element state");
156+
case ErrorCode::InvalidSelector:
157+
return ASCIILiteral("invalid selector");
153158
case ErrorCode::InvalidSessionID:
154159
return ASCIILiteral("invalid session id");
155160
case ErrorCode::JavascriptError:

Source/WebDriver/CommandResult.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class CommandResult {
4141
enum class ErrorCode {
4242
InvalidArgument,
4343
InvalidElementState,
44+
InvalidSelector,
4445
InvalidSessionID,
4546
JavascriptError,
4647
NoSuchElement,

Source/WebKit/ChangeLog

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2017-07-18 Carlos Garcia Campos <[email protected]>
2+
3+
WebDriver: handle invalid selector errors
4+
https://bugs.webkit.org/show_bug.cgi?id=174619
5+
6+
Reviewed by Brian Burg.
7+
8+
We are currently handling only XPathException and only when it's an invalid expression. In the xpath case, the
9+
spec also says "If any item in result is not an element return an error with error code invalid selector.", so
10+
we should also handle TYPE_ERR (The expression could not be converted to return the specified type.). However,
11+
since the spec says "or other error", I think we can simplify this and simply throw InvalidSelector inside the
12+
catch, without checking any specific error. This is causing 14 failures in selenium tests.
13+
14+
§12. Element Retrieval. Step 6: If a DOMException, SyntaxError, XPathException, or other error occurs during the
15+
execution of the element location strategy, return error invalid selector.
16+
https://www.w3.org/TR/webdriver/#dfn-find
17+
18+
* UIProcess/Automation/Automation.json: Add InvalidSelector error.
19+
* UIProcess/Automation/atoms/FindNodes.js:
20+
(tryToFindNode): Raise InvalidSelector in case of error.
21+
* WebProcess/Automation/WebAutomationSessionProxy.cpp:
22+
(WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction): Handle InvalidSelector exceptions.
23+
124
2017-07-18 Carlos Garcia Campos <[email protected]>
225

326
Web Automation: error details not passed to DidEvaluateJavaScriptFunction message when callback was not called before page unload

Source/WebKit/UIProcess/Automation/Automation.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"NoJavaScriptDialog",
5858
"NotImplemented",
5959
"MissingParameter",
60-
"InvalidParameter"
60+
"InvalidParameter",
61+
"InvalidSelector"
6162
]
6263
},
6364
{

Source/WebKit/UIProcess/Automation/atoms/FindNodes.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ function(strategy, ancestorElement, query, firstResultOnly, timeoutDuration, cal
100100
return arrayResult;
101101
}
102102
} catch (error) {
103-
if (error instanceof XPathException && error.code === XPathException.INVALID_EXPRESSION_ERR)
104-
return "InvalidXPathExpression";
105-
// FIXME: Bad CSS can throw an error that we should report back to the endpoint. There is no
106-
// special error code for that though, so we just return an empty match.
107-
return firstResultOnly ? null : [];
103+
// §12. Element Retrieval. Step 6: If a DOMException, SyntaxError, XPathException, or other error occurs during
104+
// the execution of the element location strategy, return error invalid selector.
105+
// https://www.w3.org/TR/webdriver/#dfn-find
106+
throw { name: "InvalidSelector", message: error.message };
108107
}
109108
}
110109

Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ void WebAutomationSessionProxy::evaluateJavaScriptFunction(uint64_t pageID, uint
281281
errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidElementState);
282282
else if (exceptionName->string() == "InvalidParameter")
283283
errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidParameter);
284+
else if (exceptionName->string() == "InvalidSelector")
285+
errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidSelector);
284286

285287
JSValueRef messageValue = JSObjectGetProperty(context, const_cast<JSObjectRef>(exception), toJSString(ASCIILiteral("message")).get(), nullptr);
286288
exceptionMessage.adopt(JSValueToStringCopy(context, messageValue, nullptr));

0 commit comments

Comments
 (0)