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: do nothing for an empty array in w3c actions #919

Merged
merged 4 commits into from
Jul 18, 2024

Conversation

KazuCocoa
Copy link
Member

@KazuCocoa KazuCocoa commented Jul 18, 2024

Instead of appium/appium-xcuitest-driver#2431

According to https://www.w3.org/TR/webdriver1/#input-source-state

If actions is undefined or is not an Array, return error with error code invalid argument.

So, I think an empty array should not return an error...? instead, it could just skip the actions.

With this change, vanilla selenium's send_keys w3c actions via xcuitest driver logic will be:

[HTTP] --> POST /session/8dc9d907-6540-4ec2-8921-75f27e77bf7f/actions {"actions":[{"type":"pointer","id":"touch","actions":[{"type":"pause","duration":0},{"type":"pause","duration":0}],"parameters":{"pointerType":"touch"}},{"type":"key","id":"keyboard","actions":[{"type":"keyDown","value":"a"},{"type":"keyUp","value":"a"}]}]}
[debug] [XCUITestDriver@b5a8] Calling AppiumDriver.performActions() with args: [[{"type":"pointer","id":"touch","actions":[{"type":"pause","duration":0},{"type":"pause","duration":0}],"parameters":{"pointerType":"touch"}},{"type":"key","id":"keyboard","actions":[{"type":"keyDown","value":"a"},{"type":"keyUp","value":"a"}]}],"8dc9d907-6540-4ec2-8921-75f27e77bf7f"]
[debug] [XCUITestDriver@b5a8] Executing command 'performActions'
[debug] [XCUITestDriver@b5a8] Received the following W3C actions: [
  {
    "type": "pointer",
    "id": "touch",
    "actions": [
      {
        "type": "pause",
        "duration": 0
      },
      {
        "type": "pause",
        "duration": 0
      }
    ],
    "parameters": {
      "pointerType": "touch"
    }
  },
  {
    "type": "key",
    "id": "keyboard",
    "actions": [
      {
        "type": "keyDown",
        "value": "a"
      },
      {
        "type": "keyUp",
        "value": "a"
      }
    ]
  }
]
[debug] [XCUITestDriver@b5a8] Preprocessed actions: [
  {
    "type": "pointer",
    "id": "touch",
    "actions": [],
    "parameters": {
      "pointerType": "touch"
    }
  },
  {
    "type": "key",
    "id": "keyboard",
    "actions": [
      {
        "type": "keyDown",
        "value": "a"
      },
      {
        "type": "keyUp",
        "value": "a"
      }
    ]
  }
]
[debug] [XCUITestDriver@b5a8] Matched '/actions' to command name 'performActions'
[debug] [XCUITestDriver@b5a8] Proxying [POST /actions] to [POST http://127.0.0.1:8100/session/C763F861-FA8B-4245-A1C2-010A062D0995/actions] with body: {"actions":[{"type":"pointer","id":"touch","actions":[],"parameters":{"pointerType":"touch"}},{"type":"key","id":"keyboard","actions":[{"type":"keyDown","value":"a"},{"type":"keyUp","value":"a"}]}]}
[IOSSimulatorLog] [IOS_SYSLOG_ROW] 2024-07-17 21:15:55.032 Df WebDriverAgentRunner-Runner[72170:4b4fdc] (WebDriverAgentLib) Action items in the action id 'touch' had an empty array. Skipping the action.
[IOSSimulatorLog] [IOS_SYSLOG_ROW] 2024-07-17 21:15:55.033 Df testmanagerd[65740:4b55ef] [com.apple.dt.xctest:Default] Synthesizing event with implicit confirmation interval 5:
[IOSSimulatorLog] [IOS_SYSLOG_ROW] <XCSynthesizedEventRecord 'W3C Touch Action display 0'>
[IOSSimulatorLog] [IOS_SYSLOG_ROW] Path 1:
# ruby
driver.action.send_keys('a').perform

For now, the command raises:

Selenium::WebDriver::Error::UnknownError: An unknown server-side error occurred while processing the command. Original error: Error Domain=com.facebook.WebDriverAgent Code=1 "It is mandatory to have at least one gesture item defined for each action. Action with id 'touch' contains none" UserInfo={NSLocalizedDescription=It is mandatory to have at least one gesture item defined for each action. Action with id 'touch' contains none}

@KazuCocoa KazuCocoa changed the title fix: do nothing for an empty array actions fix: do nothing for an empty array in w3c actions Jul 18, 2024
@KazuCocoa KazuCocoa marked this pull request as ready for review July 18, 2024 05:41
@mykola-mokhnach
Copy link

mykola-mokhnach commented Jul 18, 2024

Please update the testErroneousGestures test

@mykola-mokhnach
Copy link

Please also port the fix to mac2 driver when you have time

@kkb912002
Copy link

it is very good at the moment.

However, in the long term, it would be appreciated if the following actions could be supported with the xcuitest driver.

(not frequently needed, but...)
Example of a pointer+key combination using the Shift key to click on a specific element for 500ms.
Zero pauses must not be removed.

[
  {
    "type": "pointer",
    ...
    "actions": [
      { "type": "pause", "duration": 0 }, // for Shift key down
      { "type": "pointerMove", "duration": 250, "x": 0, "y": 0, "origin": { ... } },
      { "type": "pointerDown", "duration": 0, "button": 0 },
      { "type": "pause", "duration": 500 },
      { "type": "pause", "duration": 0 }, // for Shift key up
      { "type": "pointerUp", "duration": 0, "button": 0 }
    ]
  },
  {
    "type": "key",
    ...
    "actions": [
      { "type": "keyDown", "value": "\ue008" }, // Shift key down
      { "type": "pause", "duration": 0 }, // for pointer move
      { "type": "pause", "duration": 0 }, // for pointer down
      { "type": "pause", "duration": 500 },
      { "type": "keyUp", "value": "\ue008" },
      { "type": "pause", "duration": 0 }, // for pointer up
    ]
  }
]

@KazuCocoa
Copy link
Member Author

Perhaps... such action can done via bluetooth keyboard usage only on a mobile device...? I haven't used but I guess...

@kkb912002
Copy link

It's just that according to the specifications, such a combination should be possible, but I haven't seen it either. Hahaha.
Of course, it doesn't seem urgent to go that far right now.

@KazuCocoa
Copy link
Member Author

hm, failed tests (testErroneousGestures) have no issue on my local machine. Possibly CI spec-related.

@KazuCocoa KazuCocoa merged commit 9e70ec1 into master Jul 18, 2024
41 of 47 checks passed
@KazuCocoa KazuCocoa deleted the actions-empty-array branch July 18, 2024 07:10
github-actions bot pushed a commit that referenced this pull request Jul 18, 2024
## [8.7.8](v8.7.7...v8.7.8) (2024-07-18)

### Bug Fixes

* do nothing for an empty array in w3c actions ([#919](#919)) ([9e70ec1](9e70ec1))
Copy link

🎉 This issue has been resolved in version 8.7.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mykola-mokhnach
Copy link

it is very good at the moment.

However, in the long term, it would be appreciated if the following actions could be supported with the xcuitest driver.

(not frequently needed, but...) Example of a pointer+key combination using the Shift key to click on a specific element for 500ms. Zero pauses must not be removed.

[
  {
    "type": "pointer",
    ...
    "actions": [
      { "type": "pause", "duration": 0 }, // for Shift key down
      { "type": "pointerMove", "duration": 250, "x": 0, "y": 0, "origin": { ... } },
      { "type": "pointerDown", "duration": 0, "button": 0 },
      { "type": "pause", "duration": 500 },
      { "type": "pause", "duration": 0 }, // for Shift key up
      { "type": "pointerUp", "duration": 0, "button": 0 }
    ]
  },
  {
    "type": "key",
    ...
    "actions": [
      { "type": "keyDown", "value": "\ue008" }, // Shift key down
      { "type": "pause", "duration": 0 }, // for pointer move
      { "type": "pause", "duration": 0 }, // for pointer down
      { "type": "pause", "duration": 500 },
      { "type": "keyUp", "value": "\ue008" },
      { "type": "pause", "duration": 0 }, // for pointer up
    ]
  }
]

Unfortunately this is not possible with iOS XCTest APIs. They simply ignore modifier keys on input.

@kkb912002
Copy link

Unfortunately this is not possible with iOS XCTest APIs. They simply ignore modifier keys on input.

Although the example was a modifier key, empty pauses can also be included on one side when using two or more pointer actions without a key action to satisfy the concept of "Tick".
(Working draft)
https://www.w3.org/TR/webdriver2/#actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants