fix(xml): fiddle with xpath transform since xcuitest xml is mismatched between driver and WDA
MODIFY
packages/appium-plugins/packages/universal-xml/lib/plugin.js
packages/appium-plugins/packages/universal-xml/lib/plugin.js
@@ -45,21 +45,32 @@ export default class UniversalXMLPlugin extends BasePlugin {
}
async _find (multiple, next, driver, strategy, selector) {
+ const {platformName} = driver.caps;
if (strategy.toLowerCase() !== 'xpath') {
return await next();
}
const xml = await this.getPageSource(null, driver, true);
- const newSelector = transformQuery(selector, xml, multiple);
+ let newSelector = transformQuery(selector, xml, multiple);
// if the selector was not able to be transformed, that means no elements were found that
// matched, so do the appropriate thing based on element vs elements
if (newSelector === null) {
+ log.warn(`Selector was not able to be translated to underlying XML. Either the requested ` +
+ `element does not exist or there was an error in translation`);
if (multiple) {
return [];
}
throw new errors.NoSuchElementError();
}
+ if (platformName.toLowerCase() === 'ios') {
+ // with the XCUITest driver, the <AppiumAUT> wrapper element is present in the source but is
+ // not present in the source considered by WDA, so our index path based xpath queries will
+ // not work with WDA as-is. We need to remove the first path segment.
+ newSelector = newSelector.replace(/^\/\*\[1\]/, '');
+ }
+ log.info(`Selector was translated to: ${newSelector}`);
+
// otherwise just run the transformed query!
const finder = multiple ? 'findElements' : 'findElement';
return await driver[finder](strategy, newSelector);

MODIFY
packages/appium-plugins/packages/universal-xml/package-lock.json
packages/appium-plugins/packages/universal-xml/package-lock.json
{
"name": "@appium/universal-xml-plugin",
- "version": "0.0.1",
+ "version": "1.0.0-beta.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+ "@appium/base-plugin": {
+ "version": "1.6.1",
+ "resolved": "https://registry.npmjs.org/@appium/base-plugin/-/base-plugin-1.6.1.tgz",
+ "integrity": "sha512-CeHCkAYiLP2uP7ecIgzcLsxMQwDIfm1Rt0lIE5CG/JS6hdnpy2MYoTbb9x0SloayA003MlaHeF0/sG4s7XQc/w==",
+ "requires": {
+ "appium-support": "^2.48.0"
+ }
+ },
"@babel/runtime": {
"version": "7.12.5",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.12.5.tgz",

MODIFY
packages/appium-plugins/packages/universal-xml/test/unit/plugin-specs.js
packages/appium-plugins/packages/universal-xml/test/unit/plugin-specs.js
@@ -33,7 +33,7 @@ describe('UniversalXMLPlugin', function () {
driver.caps = {platformName: 'iOS'};
// mock out the findElement function to just return an xml node from the fixture
driver.findElement = (strategy, selector) => {
- const nodes = runQuery(selector, XML_IOS);
+ const nodes = runQuery(selector, XML_IOS.replace(/<\/?AppiumAUT>/, ''));
return nodes[0];
};
const node = await p.findElement(next, driver, 'xpath', '//TextInput[@axId="username"]');

fix(xml): fiddle with xpath transform since xcuitest xml is mismatched between driver and WDA