appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.2k stars 755 forks source link

Appium 2.0 - [W3C] Matched W3C error code 'invalid argument' to InvalidArgumentError #1954

Open dipakkumar1225 opened 1 year ago

dipakkumar1225 commented 1 year ago

Description

Getting error while perform tap Action using W3C

Environment

Code To Reproduce Issue [ Good To Have ]

Below is the sample tap action code

public void tapCenterUsingW3C()
{
           log.info("CLICKING AT CENTER OF SCREEN");
           Dimension dimension = getAppiumDriver().manage().window().getSize();
           System.out.println("dimension dimension " + dimension);
           Point point = new Point((int) (dimension.width * 0.5), (int) (dimension.height * 0.5));
           System.out.println("dimension dimension  point.getX() " + point.getX());
           System.out.println("dimension dimension  point.getY() " + point.getY());
           PointerInput FINGER = new PointerInput(TOUCH, "finger");
           Sequence tap = new Sequence(FINGER, 100)
                .addAction(FINGER.createPointerMove(ofMillis(10), viewport(), point.getX(), point.getY()))
                .addAction(FINGER.createPointerDown(LEFT.asArg()))
                .addAction(new Pause(FINGER, ofMillis(milliseconds)))
                .addAction(FINGER.createPointerUp(LEFT.asArg()));
           getAppiumDriver().perform(List.of(tap));
           log.info("CLICKED AT CENTER OF SCREEN");
  }

Link To Appium Logs

[debug] [AndroidUiautomator2Driver@3aba (07890412)] Matched '/actions' to command name 'performActions' [debug] [AndroidUiautomator2Driver@3aba (07890412)] Proxying [POST /actions] to [POST http://127.0.0.1:10001/session/042567b1-6a57-4895-816a-60f11f23ba74/actions] with body: {"actions":[{"id":"finger","type":"pointer","parameters":{"pointerType":"touch"},"actions":[{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"}... [AndroidUiautomator2Driver@3aba (07890412)] Got response with status 400: {"sessionId":"042567b1-6a57-4895-816a-60f11f23ba74","value":{"error":"invalid argument","message":"Exception while reading JSON","stacktrace":"io.appium.uiautomator2.common.exceptions.InvalidArgumentException: Exception while reading JSON\n\tat io.appium.uiautomator2.handler.W3CActions.safeHandle(W3CActions.java:92)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:277)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:271)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.n... [debug] [W3C] Matched W3C error code 'invalid argument' to InvalidArgumentError [debug] [AndroidUiautomator2Driver@3aba (07890412)] Encountered internal error running command: io.appium.uiautomator2.common.exceptions.InvalidArgumentException: Exception while reading JSON

Detailed Appium Log:

https://gist.github.com/dipakkumar1225/76f6e226e8fb1e1a5110deb30a0aad62

mykola-mokhnach commented 1 year ago

Unfortunately the server log gist is not accessible. Also, the generated actions JSON above does not look right to me. Are you sure there are no loops anywhere? All these actions-related classes are defined in the Selenium client, so it probably makes sense to report your issue there.

dipakkumar1225 commented 1 year ago

Unfortunately the server log gist is not accessible. Also, the generated actions JSON above does not look right to me. Are you sure there are no loops anywhere? All these actions-related classes are defined in the Selenium client, so it probably makes sense to report your issue there.

Please find the new glist link https://gist.github.com/dipakkumar1225/72d4b72353ac926ae60e8290e8ab1ad2

The same code was working proper with Appium1.x. Today I updated Appium 2.0 and java client version to 8.5.1 and after this I am getting error

mykola-mokhnach commented 1 year ago

@titusfortner @diemol Do you have any idea why the selenium java client generates so many redundant

{
  "duration": 0,
  "type": "pause"
}

actions there?

diemol commented 1 year ago

I am not sure, I'd wait for @titusfortner, he knows much more about that.

mykola-mokhnach commented 1 year ago

@dipakkumar1225 You can set the duration of move action to zero as a workaround

dipakkumar1225 commented 1 year ago

@dipakkumar1225 You can set the duration of move action to zero as a workaround

@mykola-mokhnach Thanks for the workaround, now I am able to perform tap action. But still in log there are redundant performActions

{
  "duration": 0,
  "type": "pause"
}
mykola-mokhnach commented 1 year ago

These extra entries are added by the Selenium lib dependency. Nothing we can do there.

titusfortner commented 1 year ago

Actions are grouped by ticks

Actions for each device in a given tick are executed simultaneously If you want a keyboard to press a key after the mouse presses a button, the device lists will look like:

keyboard: [pause, downKey] mouse: [downButton, pause]

So, that JSON is truncated, but it only represents one of presumably multiple devices, and it's possible that the particular "touch device" referenced isn't being used until later in the action chain.