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

multiTouchPerform is broken #711

Closed
tonn opened this issue Oct 17, 2021 · 2 comments
Closed

multiTouchPerform is broken #711

tonn opened this issue Oct 17, 2021 · 2 comments

Comments

@tonn
Copy link

tonn commented Oct 17, 2021

Hi! I've encountered with such error:

Sun, 17 Oct 2021 18:03:07 GMT [debug] [WD Proxy] Matched '/wd/hub/session/7c1249a8-335f-406f-b896-4de763450808/elements' to command name 'findElements'
Sun, 17 Oct 2021 18:03:08 GMT [debug] [WD Proxy] Proxying [POST /wd/hub/session/7c1249a8-335f-406f-b896-4de763450808/elements] to [POST http://127.0.0.1:8000/wd/hub/session/11e8cf5c008df135834898f574187b26/elements] with body: {"using":"xpath","value":"//ion-toolbar/following::*[text() = 'Settings']"}
Sun, 17 Oct 2021 18:03:08 GMT [debug] [WD Proxy] Got response with status 200: {"value":[{"element-6066-11e4-a52e-4f735466cecf":"73f5694e-4214-4b04-b644-d6e1f355ec40"}]}
Sun, 17 Oct 2021 18:03:08 GMT [HTTP] <-- POST /wd/hub/session/7c1249a8-335f-406f-b896-4de763450808/elements 200 56 ms - 139
[HTTP] 
[HTTP] --> POST /wd/hub/session/7c1249a8-335f-406f-b896-4de763450808/touch/multi/perform
[HTTP] {"actions":[{"action":"press","options":{"element":{"sessionId":"7c1249a8-335f-406f-b896-4de763450808","elementId":"73f5694e-4214-4b04-b644-d6e1f355ec40","element-6066-11e4-a52e-4f735466cecf":"73f5694e-4214-4b04-b644-d6e1f355ec40","selector":"//ion-toolbar/following::*[text() = 'Settings']","parent":{"sessionId":"7c1249a8-335f-406f-b896-4de763450808","capabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","deviceName":"Android Emulator","app":"C:\\Workspaces\\_IDL\\mobile-repo\\android\\app\\build\\outputs\\apk\\debug\\app-debug.apk","autoWebview":true,"appPackage":"com.indifferentlanguages.mobile","appActivity":".MainActivity","automationName":"UiAutomator2","udid":"emulator-5554","fullReset":false,"noReset":true,"dontStopAppOnReset":true},"platformName":"Android","deviceName":"emulator-5554","app":"C:\\Workspaces\\_ID...
Sun, 17 Oct 2021 18:03:08 GMT [debug] [W3C (7c1249a8)] Calling AppiumDriver.performMultiAction() with args: [[{"action":"press","options":{"element":{"sessionId":"7c1249a8-335f-406f-b896-4de763450808","elementId":"73f5694e-4214-4b04-b644-d6e1f355ec40","element-6066-11e4-a52e-4f735466cecf":"73f5694e-4214-4b04-b644-d6e1f355ec40","selector":"//ion-toolbar/following::*[text() = 'Settings']","parent":{"sessionId":"7c1249a8-335f-406f-b896-4de763450808","capabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","deviceName":"Android Emulator","app":"C:\\Workspaces\\_IDL\\mobile-repo\\android\\app\\build\\outputs\\apk\\debug\\app-debug.apk","autoWebview":true,"appPackage":"com.indifferentlanguages.mobile","appActivity":".MainActivity","automationName":"UiAutomator2","udid":"emulator-5554","fullReset":false,"noReset":true,"dontStopAppOnReset":true},"platformName":"Android","deviceName":"emulator-5554","app":"C:\\Workspaces\\_IDL\\mobile-...
Sun, 17 Oct 2021 18:03:08 GMT [debug] [W3C (7c1249a8)] Encountered internal error running command: TypeError: Cannot read property 'action' of undefined
Sun, 17 Oct 2021 18:03:08 GMT [debug] [W3C (7c1249a8)]     at AndroidUiautomator2Driver.parseTouch (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\appium-android-driver\lib\commands\touch.js:246:4)
[debug] [W3C (7c1249a8)]     at mapper (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\appium-android-driver\lib\commands\touch.js:334:1)
[debug] [W3C (7c1249a8)]     at asyncmap (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\asyncbox\lib\asyncbox.js:104:24)
[debug] [W3C (7c1249a8)]     at AndroidUiautomator2Driver.performMultiAction (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\appium-android-driver\lib\commands\touch.js:334:1)
[debug] [W3C (7c1249a8)]     at commandExecutor (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\driver.js:335:9)
Sun, 17 Oct 2021 18:03:08 GMT [debug] [W3C (7c1249a8)]     at C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\async-lock\lib\index.js:146:12
[debug] [W3C (7c1249a8)]     at AsyncLock._promiseTry (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\async-lock\lib\index.js:280:31)
[debug] [W3C (7c1249a8)]     at exec (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\async-lock\lib\index.js:145:9)
[debug] [W3C (7c1249a8)]     at AsyncLock.acquire (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\async-lock\lib\index.js:162:3)
[debug] [W3C (7c1249a8)]     at AndroidUiautomator2Driver.executeCommand (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\driver.js:348:39)
Sun, 17 Oct 2021 18:03:08 GMT [debug] [W3C (7c1249a8)]     at AppiumDriver.executeCommand (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\lib\appium.js:563:36)
[debug] [W3C (7c1249a8)]     at runMicrotasks (<anonymous>)
[debug] [W3C (7c1249a8)]     at processTicksAndRejections (internal/process/task_queues.js:93:5)
[debug] [W3C (7c1249a8)]     at asyncHandler (C:\Workspaces\_IDL\mobile-repo\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:297:21)
Sun, 17 Oct 2021 18:03:08 GMT [HTTP] <-- POST /wd/hub/session/7c1249a8-335f-406f-b896-4de763450808/touch/multi/perform 500 99 ms - 633
[HTTP] 
[HTTP] --> DELETE /wd/hub/session/7c1249a8-335f-406f-b896-4de763450808
[HTTP] {}
[debug] [W3C (7c1249a8)] Calling AppiumDriver.deleteSession() with args: ["7c1249a8-335f-406f-b896-4de763450808"]

Here code which produces the error:

  async longClickElement(selector: string): Promise<wdio.Element<'async'> | false> {
    const element = await this.client.$(selector);

    await element.waitForExist();
 
    this.client.multiTouchPerform([{ action: 'press', options: { element } },
                                   { action: 'wait', options: { ms: 1100 } }]);

    return element;
  }

I did research and found a mistake (as I understand). But I don't know how to fix it.

There is single action passed to parseTouch

const states = await asyncmap(actions, async (action) => await this.parseTouch(action, true), false);

But parseTouch function waits for array of actions

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

and it fails on this line:

if (multi && _.last(gestures).action === 'release') {

@mykola-mokhnach
Copy link
Contributor

These interfaces are considered deprecated. Please switch to W3C actions usage. Check https://www.youtube.com/watch?v=oAJ7jwMNFVU for more details.

@tonn
Copy link
Author

tonn commented Oct 20, 2021

Ok... Thanks. There is a lack of documentation about this question, but I was able to find combination that is work

example for webdriver.io

  async nativeContext<T>(action: () => Promise<T> | T): Promise<T> {
    const [native, webview] = await this.client.getContexts();

    try {
      await this.client.switchContext(native);

      return await action();
    } finally {
      await this.client.switchContext(webview);
    }
  }

  @Once
  async getWebviewPosition(): Promise<{ x: number, y: number }> {
    return await this.nativeContext(async () => {
      const webview = await this.client.$('android.webkit.WebView'); // TODO: for IOS

      return await webview.getLocation();
    });
  }

  async longClickElement(selector: string, duration = 1100): Promise<wdio.Element<'async'>> {
    const element = await this.client.$(selector);

    await element.waitForExist();
  
    const webviewCoords = await this.getWebviewPosition();
    const rect = await this.client.getElementRect(element.elementId);
    const center = { x: Math.round(rect.x + rect.width / 2), y: Math.round(rect.y + rect.height / 2) + webviewCoords.y };

    const actions = [{
      type: 'pointer',
      id: 'finger1',
      parameters: {pointerType: 'touch'},
      actions: [
        { type: 'pointerMove', duration: 250, ...center },
        { type: 'pointerDown', button: 250 },
        { type: 'pause', duration },
        { type: 'pointerUp', button: 250 }
      ]
    }];

    await this.nativeContext(() => this.client.performActions(actions));

    return element;
  }

@tonn tonn closed this as completed Oct 20, 2021
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

No branches or pull requests

2 participants