|
27 | 27 | */ |
28 | 28 | public class XPathEvaluatorTest extends WebDriverTestCase { |
29 | 29 |
|
| 30 | + /** |
| 31 | + * @throws Exception if the test fails |
| 32 | + */ |
| 33 | + @Test |
| 34 | + @Alerts({"function", "[object XPathEvaluator]", "[object HTMLHtmlElement]", "first", "second", ""}) |
| 35 | + public void ctor() throws Exception { |
| 36 | + final String html = DOCTYPE_HTML |
| 37 | + + "<html><body>\n" |
| 38 | + + "<span id='first'>hello</span>\n" |
| 39 | + + "<div><span id='second'>world</span></div>\n" |
| 40 | + + "<script>\n" |
| 41 | + + LOG_TITLE_FUNCTION |
| 42 | + + "var res = '';\n" |
| 43 | + + "try {\n" |
| 44 | + + " res += typeof window.XPathEvaluator + '§';\n" |
| 45 | + + " var xpe = new XPathEvaluator();\n" |
| 46 | + + " res += xpe + '§';\n" |
| 47 | + + " var nsResolver = xpe.createNSResolver(document.documentElement);\n" |
| 48 | + + " res += nsResolver + '§';\n" |
| 49 | + + " var result = xpe.evaluate('//span', document.body, nsResolver, 0, null);\n" |
| 50 | + + " var found = [];\n" |
| 51 | + + " var next;\n" |
| 52 | + + " while (next = result.iterateNext()) {\n" |
| 53 | + + " res += next.id + '§';\n" |
| 54 | + + " }\n" |
| 55 | + + "} catch(e) { res += 'exception' + '§'; }\n" |
| 56 | + + "log(res);\n" |
| 57 | + + "</script></body></html>"; |
| 58 | + |
| 59 | + loadPageVerifyTitle2(html); |
| 60 | + } |
| 61 | + |
30 | 62 | /** |
31 | 63 | * @throws Exception if the test fails |
32 | 64 | */ |
@@ -236,6 +268,27 @@ public void namespacesWithCustomNSResolver() throws Exception { |
236 | 268 | loadPageVerifyTitle2(html); |
237 | 269 | } |
238 | 270 |
|
| 271 | + /** |
| 272 | + * @throws Exception if the test fails |
| 273 | + */ |
| 274 | + @Test |
| 275 | + @Alerts("[object XPathExpression]") |
| 276 | + public void createExpression() throws Exception { |
| 277 | + final String html = DOCTYPE_HTML |
| 278 | + + "<html><body>\n" |
| 279 | + + "<script>\n" |
| 280 | + + LOG_TITLE_FUNCTION |
| 281 | + + "var res = '';\n" |
| 282 | + + "try {\n" |
| 283 | + + " var expression = new XPathEvaluator().createExpression('//span');\n" |
| 284 | + + " res += expression;\n" |
| 285 | + + "} catch(e) { res += e.name; }\n" |
| 286 | + + "log(res);\n" |
| 287 | + + "</script></body></html>"; |
| 288 | + |
| 289 | + loadPageVerifyTitle2(html); |
| 290 | + } |
| 291 | + |
239 | 292 | /** |
240 | 293 | * @throws Exception if the test fails |
241 | 294 | */ |
|
0 commit comments