3030@ RunWith (BrowserRunner .class )
3131public class HtmlUnitXPath2Test extends WebDriverTestCase {
3232
33+ /**
34+ * {@inheritDoc}
35+ */
36+ @ Override
37+ protected boolean isWebClientCached () {
38+ return true ;
39+ }
40+
3341 /**
3442 * @throws Exception if the test fails
3543 */
@@ -254,6 +262,51 @@ public void number() throws Exception {
254262 compare ("//p[@y=number(\" 13\t \" )]" );
255263 }
256264
265+ /**
266+ * @throws Exception if the test fails
267+ */
268+ @ Test
269+ @ Alerts ("false" )
270+ public void startsWith () throws Exception {
271+ compareBooleanValue ("starts-with(\" haystack\" , \" needle\" )" );
272+ }
273+
274+ /**
275+ * @throws Exception if the test fails
276+ */
277+ @ Test
278+ @ Alerts ("true" )
279+ public void startsWithFound () throws Exception {
280+ compareBooleanValue ("starts-with(\" haystack\" , \" hay\" )" );
281+ }
282+
283+ /**
284+ * @throws Exception if the test fails
285+ */
286+ @ Test
287+ @ Alerts ("true" )
288+ public void startsWithWhole () throws Exception {
289+ compareBooleanValue ("starts-with(\" haystack\" , \" haystack\" )" );
290+ }
291+
292+ /**
293+ * @throws Exception if the test fails
294+ */
295+ @ Test
296+ @ Alerts ("true" )
297+ public void startsWithEmpty () throws Exception {
298+ compareBooleanValue ("starts-with(\" haystack\" , \" \" )" );
299+ }
300+
301+ /**
302+ * @throws Exception if the test fails
303+ */
304+ @ Test
305+ @ Alerts ("true" )
306+ public void startsWithEmptyEmpty () throws Exception {
307+ compareBooleanValue ("starts-with(\" \" , \" \" )" );
308+ }
309+
257310 /**
258311 * @throws Exception if the test fails
259312 */
@@ -319,9 +372,27 @@ public void attrib() throws Exception {
319372 * @throws Exception if the test fails
320373 */
321374 @ Test
322- @ Alerts ("error " )
375+ @ Alerts ("SyntaxError " )
323376 public void lowerCaseNotSupported () throws Exception {
324- compare ("//*[lower-case(@id) = \" a\" ]" );
377+ compareError ("//*[lower-case(@id) = \" a\" ]" );
378+ }
379+
380+ /**
381+ * @throws Exception if the test fails
382+ */
383+ @ Test
384+ @ Alerts ("SyntaxError" )
385+ public void upperCaseNotSupported () throws Exception {
386+ compareError ("//*[upper-case(@id) = \" A\" ]" );
387+ }
388+
389+ /**
390+ * @throws Exception if the test fails
391+ */
392+ @ Test
393+ @ Alerts ("SyntaxError" )
394+ public void endsWithNotSupported () throws Exception {
395+ compareError ("ends-with(\" haystack\" , \" haystack\" )" );
325396 }
326397
327398 private void compare (final String xpath ) throws Exception {
@@ -338,7 +409,7 @@ private void compare(final String xpath) throws Exception {
338409 + " res += node.id;\n "
339410 + " }\n "
340411 + " log(res);\n "
341- + " } catch (e) {log('error' )}\n "
412+ + " } catch (e) {log(e.name )}\n "
342413 + "}\n "
343414 + "</script></head>\n "
344415 + "<body onload='test()'>\n "
@@ -399,6 +470,25 @@ private void compareBooleanValue(final String xpath) throws Exception {
399470 loadPageVerifyTitle2 (content );
400471 }
401472
473+ private void compareError (final String xpath ) throws Exception {
474+ final String content = "<html>\n "
475+ + "<head>\n "
476+ + "<script>\n "
477+ + LOG_TITLE_FUNCTION
478+ + "function test() {\n "
479+ + " try {\n "
480+ + " var expr = '" + xpath + "';\n "
481+ + " var result = document.evaluate(expr, document.documentElement, null, XPathResult.ANY_TYPE, null);\n "
482+ + " log('error expected');\n "
483+ + " } catch (e) {log(e.name)}\n "
484+ + "}\n "
485+ + "</script></head>\n "
486+ + "<body onload='test()'>\n "
487+ + "</body></html>" ;
488+
489+ loadPageVerifyTitle2 (content );
490+ }
491+
402492 /**
403493 * @throws Exception if the test fails
404494 */
0 commit comments