Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tap by element coordinates #355

Merged
merged 4 commits into from Apr 19, 2020

Conversation

mykola-mokhnach
Copy link
Contributor

@imurchie
Copy link
Contributor

I'm confused. Why is the ability to set an element and the offset being removed?

@mykola-mokhnach
Copy link
Contributor Author

Because such feature is not supported by the bootstrap server itself:

  @Override
  public AndroidCommandResult execute(final AndroidCommand command)
      throws JSONException {
    if (command.isElementCommand()) {
      try {
        final AndroidElement el = command.getElement();
        el.click();
        return getSuccessResult(true);
      } catch (final UiObjectNotFoundException e) {
        return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
            e.getMessage());
      } catch (final Exception e) { // handle NullPointerException
        return getErrorResult("Unknown error");
      }
    } else {
      final Hashtable<String, Object> params = command.params();
      Point coords = new Point(Double.parseDouble(params.get("x").toString()),
          Double.parseDouble(params.get("y").toString()) );

      try {
        coords = PositionHelper.getDeviceAbsPos(coords);
      } catch (final UiObjectNotFoundException e) {
        return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
            e.getMessage());
      } catch (final InvalidCoordinatesException e) {
        return new AndroidCommandResult(WDStatus.INVALID_ELEMENT_COORDINATES,
            e.getMessage());
      }

      final boolean res = UiDevice.getInstance().click(coords.x.intValue(), coords.y.intValue());
      return getSuccessResult(res);
    }
  }

As you can see here it can only perform click on element or click by absolute coordinates.

@imurchie
Copy link
Contributor

Ok. That makes sense, then.

@imurchie
Copy link
Contributor

It's still possible to do what we purport to do (element with offset) by converting to absolute coordinates (i.e., finding the coordinates of the element and then adding the offset). Since this is what is purported to be done.

@mykola-mokhnach
Copy link
Contributor Author

mykola-mokhnach commented Apr 24, 2018

Yes, it is possible. However, in order to achieve this one has to rewrite the logic for touch actions parser, for the bootstrap lib and for this tap command. It could be more error-prone, since many components will be affected (including UIA2 driver) and will take much more time.

@imurchie
Copy link
Contributor

Really? We take the correct arguments now. We could just go, in the driver,

if (elementId && areCoordinatesDefined) {
  const loc = await this.getLocation(elementId);
  const newX = loc.x + x;
  const newY = loc.y + y;
  await this.bootstrap.sendAction("click", {x: newX, y: newY});
} else ...

And, of course, this could be done on the bootstrap side more efficiently.

@mykola-mokhnach
Copy link
Contributor Author

The coordinates passed to tap are already absolute. Although, I don't mind if you can implement a better fix

@mykola-mokhnach
Copy link
Contributor Author

@imurchie I think we could merge this solution for now, since it is not ideal, but fixes the original problem, so clients could properly run their tests with Appium@beta. In the meantime one could refactor the code and present something better. Same for appium/appium-uiautomator2-driver#163

@mykola-mokhnach
Copy link
Contributor Author

@imurchie the code above is already applied in

helpers.parseTouch = async function (gestures, multi) {
method.

@jsf-clabot
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ mykola-mokhnach
❌ Mykola Mokhnach


Mykola Mokhnach seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.

@mykola-mokhnach mykola-mokhnach merged commit a74c51d into appium:master Apr 19, 2020
@mykola-mokhnach mykola-mokhnach deleted the fix_tap branch April 19, 2020 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants