Skip to content

Commit

Permalink
chore: Raise more helpful error if a W3C action contains a web element (
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 26, 2024
1 parent 3bef542 commit 5d80cd8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/commands/gesture.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const commands = {
*/
async performActions(actions) {
this.log.debug(`Received the following W3C actions: ${JSON.stringify(actions, null, ' ')}`);
assertNoWebElements(actions);
// This is mandatory, since WDA only supports TOUCH pointer type
// and Selenium API uses MOUSE as the default one
const preprocessedActions = actions
Expand Down Expand Up @@ -564,6 +565,25 @@ const helpers = {

export default {...helpers, ...commands};

/**
* @param {import('@appium/types').ActionSequence[]} actionSeq
*/
function assertNoWebElements(actionSeq) {
const isOriginWebElement = (gesture) =>
_.isPlainObject(gesture) && 'origin' in gesture && JSON.stringify(gesture.origin).includes(':wdc:');
const hasWebElements = actionSeq
.some((action) => (action?.actions || []).some(isOriginWebElement));
if (hasWebElements) {
throw new errors.InvalidArgumentError(
`The XCUITest driver only supports W3C actions execution in the native context. ` +
`Although, your W3C action contains one or more web elements, ` +
`which cannot be automatically mapped to the native context. ` +
`Consider mapping their absolute web coordinates to native context coordinates ` +
`and passing them to your gesture instead.`
);
}
}

/**
* @typedef {import('../driver').XCUITestDriver} XCUITestDriver
* @typedef {import('@appium/types').Element} Element
Expand Down

0 comments on commit 5d80cd8

Please sign in to comment.