Title: [225326] trunk/Source/WebDriver
Revision
225326
Author
carlo...@webkit.org
Date
2017-11-30 05:48:46 -0800 (Thu, 30 Nov 2017)

Log Message

WebDriver: locator strategy should be validated before trying to find elements
https://bugs.webkit.org/show_bug.cgi?id=180187

Reviewed by Carlos Alberto Lopez Perez.

We currently rely on the js atom to raise an exception in case the locator strategy is not valid, but in case of
find element from element, if the element doesn't exist we fail with stale element error instead of invalid
argument as expected. So, let's validate the strategies when parsing them, which would also avoid going to the
browser in cae of invalid strategy.

Fixes: imported/w3c/webdriver/tests/retrieval/find_element_from_element.py::test_invalid_using_argument[a]

* WebDriverService.cpp:
(WebDriver::isValidStrategy):
(WebDriver::findStrategyAndSelectorOrCompleteWithError):

Modified Paths

Diff

Modified: trunk/Source/WebDriver/ChangeLog (225325 => 225326)


--- trunk/Source/WebDriver/ChangeLog	2017-11-30 13:47:19 UTC (rev 225325)
+++ trunk/Source/WebDriver/ChangeLog	2017-11-30 13:48:46 UTC (rev 225326)
@@ -1,5 +1,23 @@
 2017-11-30  Carlos Garcia Campos  <cgar...@igalia.com>
 
+        WebDriver: locator strategy should be validated before trying to find elements
+        https://bugs.webkit.org/show_bug.cgi?id=180187
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        We currently rely on the js atom to raise an exception in case the locator strategy is not valid, but in case of
+        find element from element, if the element doesn't exist we fail with stale element error instead of invalid
+        argument as expected. So, let's validate the strategies when parsing them, which would also avoid going to the
+        browser in cae of invalid strategy.
+
+        Fixes: imported/w3c/webdriver/tests/retrieval/find_element_from_element.py::test_invalid_using_argument[a]
+
+        * WebDriverService.cpp:
+        (WebDriver::isValidStrategy):
+        (WebDriver::findStrategyAndSelectorOrCompleteWithError):
+
+2017-11-30  Carlos Garcia Campos  <cgar...@igalia.com>
+
         WebDriver: remove elementSubmit command
         https://bugs.webkit.org/show_bug.cgi?id=180186
 

Modified: trunk/Source/WebDriver/WebDriverService.cpp (225325 => 225326)


--- trunk/Source/WebDriver/WebDriverService.cpp	2017-11-30 13:47:19 UTC (rev 225325)
+++ trunk/Source/WebDriver/WebDriverService.cpp	2017-11-30 13:48:46 UTC (rev 225326)
@@ -984,9 +984,20 @@
     return elementID;
 }
 
+static inline bool isValidStrategy(const String& strategy)
+{
+    // ยง12.1 Locator Strategies.
+    // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-table-of-location-strategies
+    return strategy == "css selector"
+        || strategy == "link text"
+        || strategy == "partial link text"
+        || strategy == "tag name"
+        || strategy == "xpath";
+}
+
 static bool findStrategyAndSelectorOrCompleteWithError(JSON::Object& parameters, Function<void (CommandResult&&)>& completionHandler, String& strategy, String& selector)
 {
-    if (!parameters.getString(ASCIILiteral("using"), strategy)) {
+    if (!parameters.getString(ASCIILiteral("using"), strategy) || !isValidStrategy(strategy)) {
         completionHandler(CommandResult::fail(CommandResult::ErrorCode::InvalidArgument));
         return false;
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to