Javascript actions for JUnit

I’m having problems using Javascript in JUnit tests to execute a tap action in an iOS app. Can anyone help me out here?

Here’s an excerpt of the JUnit code which is breaking:

    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, Double> tapObject = new HashMap<String, Double>();
    tapObject.put("x", 134.0); // in pixels from left
    tapObject.put("y", 526.0); // in pixels from top
    tapObject.put("touchCount", 1.0);
    tapObject.put("tapCount", 1.0);
    tapObject.put("duration", 0.5);
    js.executeScript("mobile: tap", tapObject);

And here is the error:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 110.846 sec <<< FAILURE!
testViewCart(com.saucelabs.appium.SimpleTest)  Time elapsed: 110.784 sec  <<< ERROR!
org.openqa.selenium.WebDriverException: An error occurred while executing user supplied JavaScript. 
(WARNING: The server did not provide any stacktrace information)

The full stack trace is here.

Thanks for any help.

1 Like

Nevermind. I can use AppiumDriver.tap() instead.

1 Like