(
xmlStr: string,
platform: string,
{metadata = {} as TransformMetadata, addIndexPath = false}: TransformSourceXmlOptions = {},
)
| 30 | * @returns Promise resolving to transformed XML and unknown nodes/attributes |
| 31 | */ |
| 32 | export async function transformSourceXml( |
| 33 | xmlStr: string, |
| 34 | platform: string, |
| 35 | {metadata = {} as TransformMetadata, addIndexPath = false}: TransformSourceXmlOptions = {}, |
| 36 | ): Promise<{xml: string; unknowns: NodesAndAttributes}> { |
| 37 | // the ios <AppiumAUT> root deliberately gets no index path: the XCUITest driver leaves that |
| 38 | // wrapper out of the hierarchy it runs queries against, so index paths have to be relative to |
| 39 | // the node below it. the android <hierarchy> root does carry an index attribute and is part of |
| 40 | // the queried hierarchy, so it keeps its index path |
| 41 | const xmlObj = singletonXmlParser().parse(xmlStr); |
| 42 | const unknowns = transformNode(xmlObj, platform, { |
| 43 | metadata, |
| 44 | addIndexPath, |
| 45 | parentPath: '', |
| 46 | }); |
| 47 | let transformedXml = singletonXmlBuilder().build(xmlObj).trim(); |
| 48 | transformedXml = `<?xml version="1.0" encoding="UTF-8"?>\n${transformedXml}`; |
| 49 | return {xml: transformedXml, unknowns}; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Gets the universal node name for a platform-specific node name |
no test coverage detected