MCPcopy Create free account
hub / github.com/appium/appium / getPageSource

Method getPageSource

packages/universal-xml-plugin/lib/plugin.ts:64–105  ·  view source on GitHub ↗

* Returns the page source, translated to universal XML when translation is enabled. * `addIndexPath` adds an index path attribute to every node, which the XPath transformer uses.

(
    next: NextPluginCallback | null,
    driver: ExternalDriver,
    sessId?: any,
    addIndexPath: boolean = false,
  )

Source from the content-addressed store, hash-verified

62 * `addIndexPath` adds an index path attribute to every node, which the XPath transformer uses.
63 */
64 async getPageSource(
65 next: NextPluginCallback | null,
66 driver: ExternalDriver,
67 sessId?: any,
68 addIndexPath: boolean = false,
69 ): Promise<string> {
70 void sessId;
71 const source = (next ? await next() : await driver.getPageSource()) as string;
72 if (
73 !this.translationEnabled ||
74 typeof driver.getCurrentContext !== 'function' ||
75 (await driver.getCurrentContext()) !== 'NATIVE_APP'
76 ) {
77 return source;
78 }
79 const metadata: TransformMetadata = {};
80 const platformName = getPlatformName(driver);
81 if (platformName.toLowerCase() === 'android') {
82 metadata.appPackage = (driver.opts as Record<string, unknown>)?.appPackage as string;
83 }
84 const {xml, unknowns} = await transformSourceXml(source, platformName.toLowerCase(), {
85 metadata,
86 addIndexPath,
87 });
88 if (unknowns.nodes.length) {
89 this.log.warn(
90 `The XML mapper found ${unknowns.nodes.length} node(s) / ` +
91 `tag name(s) that it didn't know about. These should be ` +
92 `reported to improve the quality of the plugin: ` +
93 unknowns.nodes.join(', '),
94 );
95 }
96 if (unknowns.attrs.length) {
97 this.log.warn(
98 `The XML mapper found ${unknowns.attrs.length} attributes ` +
99 `that it didn't know about. These should be reported to ` +
100 `improve the quality of the plugin: ` +
101 unknowns.attrs.join(', '),
102 );
103 }
104 return xml;
105 }
106
107 /**
108 * Finds an element. XPath queries are translated against the universal XML source when

Callers 1

_findMethod · 0.95

Calls 6

getPlatformNameFunction · 0.85
transformSourceXmlFunction · 0.85
getCurrentContextMethod · 0.80
getPageSourceMethod · 0.65
warnMethod · 0.65
nextFunction · 0.50

Tested by

no test coverage detected