appium-mcp 1.98.0 → 1.99.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +30 -0
- package/dist/locators/element-filter.d.ts +3 -1
- package/dist/locators/element-filter.d.ts.map +1 -1
- package/dist/locators/element-filter.js +44 -14
- package/dist/locators/element-filter.js.map +1 -1
- package/dist/locators/generate-all-locators.d.ts +6 -1
- package/dist/locators/generate-all-locators.d.ts.map +1 -1
- package/dist/locators/generate-all-locators.js +1 -1
- package/dist/locators/generate-all-locators.js.map +1 -1
- package/dist/locators/locator-generation.d.ts +4 -3
- package/dist/locators/locator-generation.d.ts.map +1 -1
- package/dist/locators/locator-generation.js +31 -10
- package/dist/locators/locator-generation.js.map +1 -1
- package/dist/locators/types.d.ts +3 -0
- package/dist/locators/types.d.ts.map +1 -0
- package/dist/locators/types.js +2 -0
- package/dist/locators/types.js.map +1 -0
- package/dist/tools/gestures/schema.d.ts.map +1 -1
- package/dist/tools/gestures/schema.js +7 -15
- package/dist/tools/gestures/schema.js.map +1 -1
- package/dist/tools/interactions/screen-recording.d.ts.map +1 -1
- package/dist/tools/interactions/screen-recording.js +4 -1
- package/dist/tools/interactions/screen-recording.js.map +1 -1
- package/dist/tools/test-generation/locators.d.ts.map +1 -1
- package/dist/tools/test-generation/locators.js +19 -5
- package/dist/tools/test-generation/locators.js.map +1 -1
- package/dist/ui/inspector-screenshot-script.d.ts +3 -0
- package/dist/ui/inspector-screenshot-script.d.ts.map +1 -0
- package/dist/ui/inspector-screenshot-script.js +164 -0
- package/dist/ui/inspector-screenshot-script.js.map +1 -0
- package/dist/ui/mcp-ui-utils.d.ts.map +1 -1
- package/dist/ui/mcp-ui-utils.js +14 -73
- package/dist/ui/mcp-ui-utils.js.map +1 -1
- package/dist/ui/page-source-inspector-app.d.ts.map +1 -1
- package/dist/ui/page-source-inspector-app.js +79 -75
- package/dist/ui/page-source-inspector-app.js.map +1 -1
- package/dist/ui/xml-inspector-scripts.d.ts +4 -0
- package/dist/ui/xml-inspector-scripts.d.ts.map +1 -0
- package/dist/ui/xml-inspector-scripts.js +91 -0
- package/dist/ui/xml-inspector-scripts.js.map +1 -0
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/locators/element-filter.ts +50 -16
- package/src/locators/generate-all-locators.ts +13 -7
- package/src/locators/locator-generation.ts +43 -10
- package/src/locators/types.ts +2 -0
- package/src/tools/gestures/schema.ts +7 -17
- package/src/tools/interactions/screen-recording.ts +4 -1
- package/src/tools/test-generation/locators.ts +31 -7
- package/src/ui/inspector-screenshot-script.ts +163 -0
- package/src/ui/mcp-ui-utils.ts +15 -73
- package/src/ui/page-source-inspector-app.ts +80 -75
- package/src/ui/xml-inspector-scripts.ts +91 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { INSPECTOR_SCREENSHOT_SCRIPT } from './inspector-screenshot-script.js';
|
|
2
|
+
import { XML_FORMAT_SCRIPT, XML_SEARCH_SCRIPT } from './xml-inspector-scripts.js';
|
|
1
3
|
/**
|
|
2
4
|
* Static MCP App used by appium_get_page_source.
|
|
3
5
|
*
|
|
@@ -35,10 +37,19 @@ export function createPageSourceInspectorAppUI() {
|
|
|
35
37
|
.viewer { height: 320px; min-height: 160px; resize: vertical; overflow: auto; padding: 20px; }
|
|
36
38
|
.xml-content, .selector { margin: 0; font: 12px/1.75 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
37
39
|
.xml-content { white-space: pre; color: #c5d3e7; }
|
|
40
|
+
mark[data-active] { outline: 2px solid #91baff; background: #ff963c; }
|
|
41
|
+
.search-status { padding: 6px 20px; color: var(--muted); font-size: 12px; }
|
|
42
|
+
.search-status:empty { display: none; }
|
|
38
43
|
mark { border-radius: 3px; background: #eac77a; color: #252019; }
|
|
39
44
|
.empty, .hint { color: var(--muted); }
|
|
40
45
|
.empty { font-family: inherit; }
|
|
41
46
|
.hint { margin: 6px 0 0; font-size: 12px; }
|
|
47
|
+
.screenshot-panel { border-top: 1px solid var(--line); padding: 20px; }
|
|
48
|
+
.screenshot-frame { position: relative; width: fit-content; max-width: 100%; margin: 12px auto; }
|
|
49
|
+
.screenshot-frame img { display: block; max-width: 100%; max-height: 480px; }
|
|
50
|
+
.element-overlay { position: absolute; border: 2px solid #ff963c; background: #ff963c33; pointer-events: none; }
|
|
51
|
+
#screenshotElement { width: 100%; margin: 10px 0; padding: 8px; background: var(--panel); color: var(--text); border: 1px solid var(--line); }
|
|
52
|
+
#selectedXmlElement { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
|
|
42
53
|
.locators { border-top: 1px solid var(--line); padding: 20px; }
|
|
43
54
|
h2 { margin: 0; font-size: 14px; font-weight: 600; }
|
|
44
55
|
#locatorStatus { margin: 16px 0 10px; color: var(--accent); font-size: 12px; }
|
|
@@ -59,21 +70,38 @@ export function createPageSourceInspectorAppUI() {
|
|
|
59
70
|
<span class="info" id="sourceInfo">Waiting for page source…</span>
|
|
60
71
|
</summary>
|
|
61
72
|
<div class="toolbar">
|
|
62
|
-
<input type="search" class="search-box" id="searchBox" placeholder="
|
|
73
|
+
<input type="search" class="search-box" id="searchBox" placeholder="Search elements…" aria-label="Search elements" title="Highlight XML text and find locator candidates by element tag or attribute value">
|
|
63
74
|
<div class="toolbar-right">
|
|
75
|
+
<button class="btn btn-secondary" id="takeScreenshotButton">Take screenshot</button>
|
|
64
76
|
<button class="btn btn-secondary" id="formatButton">Format XML</button>
|
|
65
77
|
<button class="btn btn-secondary" id="copyButton">Copy XML</button>
|
|
66
78
|
</div>
|
|
67
79
|
</div>
|
|
80
|
+
<div id="searchStatus" class="search-status" role="status" aria-live="polite"></div>
|
|
68
81
|
<div class="viewer" title="Drag the bottom-right corner to resize vertically">
|
|
69
82
|
<pre class="xml-content empty" id="xmlContent">Waiting for page source…</pre>
|
|
70
83
|
</div>
|
|
84
|
+
<section id="screenshotPanel" class="screenshot-panel" hidden aria-label="Screenshot preview">
|
|
85
|
+
<h2>Screenshot & XML elements</h2>
|
|
86
|
+
<p class="hint">Capture refreshes XML too. Select an element to overlay its bounds. Images and XML are captured sequentially; keep the screen still. Supports x/y/width/height and Android bounds.</p>
|
|
87
|
+
<p id="screenshotStatus" role="status" aria-live="polite"></p>
|
|
88
|
+
<div class="screenshot-frame">
|
|
89
|
+
<img id="inspectorScreenshot" alt="Device screenshot" hidden>
|
|
90
|
+
<div id="elementOverlay" class="element-overlay" hidden></div>
|
|
91
|
+
</div>
|
|
92
|
+
<label for="screenshotElement">XML element (filtered by Search)</label>
|
|
93
|
+
<select id="screenshotElement"><option value="">Select an XML element to highlight</option></select>
|
|
94
|
+
<pre id="selectedXmlElement"></pre>
|
|
95
|
+
</section>
|
|
71
96
|
<section class="locators" aria-labelledby="locatorsHeading">
|
|
72
97
|
<div class="section-header">
|
|
73
98
|
<h2 id="locatorsHeading">Locator candidates</h2>
|
|
74
|
-
<button class="btn" id="generateButton">
|
|
99
|
+
<button class="btn" id="generateButton">Find locators</button>
|
|
75
100
|
</div>
|
|
76
|
-
<p class="hint">
|
|
101
|
+
<p class="hint">Find locators for elements matching the search text in their type or attributes (name, label, text, ID, etc.). Matches ignore case and may include hidden elements. Fetches fresh XML; leave search blank for the default candidate list.</p>
|
|
102
|
+
<label class="hint" for="xpathAttributes">Preferred XPath attributes (optional)</label>
|
|
103
|
+
<input type="text" class="search-box" id="xpathAttributes" placeholder="AutomationId, data-testid" aria-describedby="xpathAttributesHelp" style="display:block;width:100%;margin-top:6px">
|
|
104
|
+
<p class="hint" id="xpathAttributesHelp">Comma-separated attribute names, in priority order. Existing attributes remain as fallback.</p>
|
|
77
105
|
<div id="locatorResults" hidden>
|
|
78
106
|
<p id="locatorStatus" role="status" aria-live="polite"></p>
|
|
79
107
|
<div class="locator-results" id="locatorOutput"></div>
|
|
@@ -82,6 +110,9 @@ export function createPageSourceInspectorAppUI() {
|
|
|
82
110
|
</details>
|
|
83
111
|
<script>
|
|
84
112
|
(() => {
|
|
113
|
+
${XML_FORMAT_SCRIPT}
|
|
114
|
+
${XML_SEARCH_SCRIPT}
|
|
115
|
+
${INSPECTOR_SCREENSHOT_SCRIPT}
|
|
85
116
|
const PAGE_SOURCE_PREFIX = 'Page source retrieved successfully: \\n\\\`\\\`\\\`xml ';
|
|
86
117
|
const xmlContent = document.getElementById('xmlContent');
|
|
87
118
|
const sourceInfo = document.getElementById('sourceInfo');
|
|
@@ -90,11 +121,16 @@ export function createPageSourceInspectorAppUI() {
|
|
|
90
121
|
const locatorResults = document.getElementById('locatorResults');
|
|
91
122
|
const locatorStatus = document.getElementById('locatorStatus');
|
|
92
123
|
const locatorOutput = document.getElementById('locatorOutput');
|
|
124
|
+
const xmlSearch = createXmlSearch(xmlContent, document.getElementById('searchStatus'));
|
|
93
125
|
let source = '';
|
|
94
126
|
let savedFile;
|
|
95
127
|
let nextRequestId = 1;
|
|
96
128
|
const pendingRequests = new Map();
|
|
97
129
|
|
|
130
|
+
const screenshotInspector = createScreenshotInspector(
|
|
131
|
+
(name, args) => sendRequest('tools/call', {name, arguments: args}), setSource, sourceFromToolResult,
|
|
132
|
+
);
|
|
133
|
+
|
|
98
134
|
function sendRequest(method, params) {
|
|
99
135
|
const id = nextRequestId++;
|
|
100
136
|
window.parent.postMessage({jsonrpc: '2.0', id, method, params}, '*');
|
|
@@ -128,30 +164,9 @@ export function createPageSourceInspectorAppUI() {
|
|
|
128
164
|
return text;
|
|
129
165
|
}
|
|
130
166
|
|
|
131
|
-
function appendHighlightedText(container, text, query) {
|
|
132
|
-
const lowerText = text.toLowerCase();
|
|
133
|
-
const lowerQuery = query.toLowerCase();
|
|
134
|
-
let position = 0;
|
|
135
|
-
|
|
136
|
-
while (position < text.length) {
|
|
137
|
-
const matchIndex = lowerText.indexOf(lowerQuery, position);
|
|
138
|
-
if (matchIndex === -1) {
|
|
139
|
-
container.appendChild(document.createTextNode(text.slice(position)));
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (matchIndex > position) {
|
|
143
|
-
container.appendChild(document.createTextNode(text.slice(position, matchIndex)));
|
|
144
|
-
}
|
|
145
|
-
const mark = document.createElement('mark');
|
|
146
|
-
mark.textContent = text.slice(matchIndex, matchIndex + query.length);
|
|
147
|
-
container.appendChild(mark);
|
|
148
|
-
position = matchIndex + query.length;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
167
|
function renderSource() {
|
|
153
168
|
const query = searchBox.value.trim();
|
|
154
|
-
|
|
169
|
+
xmlSearch.render('', '');
|
|
155
170
|
xmlContent.classList.toggle('empty', source.length === 0);
|
|
156
171
|
if (savedFile) {
|
|
157
172
|
sourceInfo.textContent = savedFile.bytes + ' bytes saved';
|
|
@@ -160,59 +175,22 @@ export function createPageSourceInspectorAppUI() {
|
|
|
160
175
|
}
|
|
161
176
|
if (!source) {
|
|
162
177
|
xmlContent.textContent = 'No page source was returned.';
|
|
163
|
-
} else if (!query) {
|
|
164
|
-
xmlContent.textContent = source;
|
|
165
178
|
} else {
|
|
166
|
-
|
|
179
|
+
xmlSearch.render(source, query);
|
|
167
180
|
}
|
|
168
181
|
sourceInfo.textContent = source.length + ' characters';
|
|
169
182
|
}
|
|
170
183
|
|
|
171
184
|
function setSource(nextSource) {
|
|
172
185
|
source = nextSource;
|
|
186
|
+
screenshotInspector.updateSource(source);
|
|
173
187
|
renderSource();
|
|
174
188
|
}
|
|
175
189
|
|
|
176
190
|
function formatXML() {
|
|
177
191
|
if (!source) return;
|
|
178
192
|
try {
|
|
179
|
-
|
|
180
|
-
const documentNode = parser.parseFromString(source, 'text/xml');
|
|
181
|
-
if (!documentNode.documentElement || documentNode.getElementsByTagName('parsererror').length) {
|
|
182
|
-
throw new Error('Invalid XML');
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function indentElement(element, depth) {
|
|
186
|
-
if (element.getAttribute('xml:space') === 'preserve') return;
|
|
187
|
-
const children = Array.from(element.childNodes);
|
|
188
|
-
const hasMixedContent = children.some((child) =>
|
|
189
|
-
child.nodeType === 4 || (child.nodeType === 3 && (child.nodeValue || '').trim()),
|
|
190
|
-
);
|
|
191
|
-
if (hasMixedContent || !children.some((child) => child.nodeType === 1)) return;
|
|
192
|
-
|
|
193
|
-
for (const child of children) {
|
|
194
|
-
if (child.nodeType === 3) {
|
|
195
|
-
element.removeChild(child);
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
if (child.nodeType === 1) indentElement(child, depth + 1);
|
|
199
|
-
element.insertBefore(documentNode.createTextNode('\\n' + ' '.repeat(depth + 1)), child);
|
|
200
|
-
}
|
|
201
|
-
element.appendChild(documentNode.createTextNode('\\n' + ' '.repeat(depth)));
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
indentElement(documentNode.documentElement, 0);
|
|
205
|
-
const serializer = new XMLSerializer();
|
|
206
|
-
let formattedSource = Array.from(documentNode.childNodes)
|
|
207
|
-
.filter((node) => node.nodeType !== 3)
|
|
208
|
-
.map((node) => serializer.serializeToString(node))
|
|
209
|
-
.join('\\n');
|
|
210
|
-
const declaration = source.match(/^\\s*(<\\?xml\\s[^?]*\\?>)/);
|
|
211
|
-
if (declaration && !formattedSource.startsWith('<?xml ')) {
|
|
212
|
-
formattedSource = declaration[1] + '\\n' + formattedSource;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
source = formattedSource;
|
|
193
|
+
source = formatXml(source);
|
|
216
194
|
renderSource();
|
|
217
195
|
} catch {
|
|
218
196
|
window.alert('Failed to format XML');
|
|
@@ -268,22 +246,44 @@ export function createPageSourceInspectorAppUI() {
|
|
|
268
246
|
});
|
|
269
247
|
}
|
|
270
248
|
|
|
249
|
+
function parseLocatorResult(result) {
|
|
250
|
+
const text = (result?.content || [])
|
|
251
|
+
.filter(item => item.type === 'text')
|
|
252
|
+
.map(item => item.text)
|
|
253
|
+
.join('\\n');
|
|
254
|
+
if (result?.isError) throw new Error(text || 'Tool returned an error');
|
|
255
|
+
const data = JSON.parse(text);
|
|
256
|
+
if (!Array.isArray(data.interactableElements)) throw new Error('No locator data returned');
|
|
257
|
+
return data.interactableElements;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function describeLocatorResults(count, query) {
|
|
261
|
+
if (query) {
|
|
262
|
+
const matches = count ? count + ' matching elements' : 'No matching elements';
|
|
263
|
+
return matches + ' for “' + query + '” in freshly fetched XML.';
|
|
264
|
+
}
|
|
265
|
+
if (!count) return 'No supported elements found in the fetched XML.';
|
|
266
|
+
return 'Candidates generated for ' + count + ' elements from freshly fetched XML.';
|
|
267
|
+
}
|
|
268
|
+
|
|
271
269
|
async function generateLocators() {
|
|
272
270
|
if (generateButton.disabled) return;
|
|
271
|
+
const query = searchBox.value.trim();
|
|
273
272
|
generateButton.disabled = true;
|
|
274
273
|
locatorResults.hidden = false;
|
|
275
274
|
locatorStatus.textContent = 'Fetching XML and generating candidates…';
|
|
276
275
|
locatorOutput.textContent = '';
|
|
277
276
|
try {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
277
|
+
const xpathAttributes = [...new Set((document.getElementById('xpathAttributes').value || '')
|
|
278
|
+
.split(',').map(name => name.trim()).filter(Boolean))];
|
|
279
|
+
if (xpathAttributes.length > 20 || xpathAttributes.some(name => !/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(name))) {
|
|
280
|
+
throw new Error('Enter up to 20 attribute names, separated by commas (no XPath expressions or namespace prefixes).');
|
|
281
|
+
}
|
|
282
|
+
const args = query ? {query} : {};
|
|
283
|
+
if (xpathAttributes.length) args.xpathAttributes = xpathAttributes;
|
|
284
|
+
const result = await sendRequest('tools/call', {name: 'generate_locators', arguments: args});
|
|
285
|
+
const elements = parseLocatorResult(result);
|
|
286
|
+
locatorStatus.textContent = describeLocatorResults(elements.length, query);
|
|
287
287
|
renderLocators(elements);
|
|
288
288
|
} catch (error) {
|
|
289
289
|
locatorStatus.textContent = 'Failed to generate locators: ' + error.message;
|
|
@@ -313,7 +313,11 @@ export function createPageSourceInspectorAppUI() {
|
|
|
313
313
|
}
|
|
314
314
|
});
|
|
315
315
|
|
|
316
|
-
searchBox.addEventListener('input',
|
|
316
|
+
searchBox.addEventListener('input', () => {
|
|
317
|
+
renderSource();
|
|
318
|
+
screenshotInspector.filter(searchBox.value);
|
|
319
|
+
});
|
|
320
|
+
searchBox.addEventListener('keydown', xmlSearch.handleKeyDown);
|
|
317
321
|
document.getElementById('copyButton').addEventListener('click', copyToClipboard);
|
|
318
322
|
document.getElementById('formatButton').addEventListener('click', formatXML);
|
|
319
323
|
document.getElementById('generateButton').addEventListener('click', generateLocators);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-source-inspector-app.js","sourceRoot":"","sources":["../../src/ui/page-source-inspector-app.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO
|
|
1
|
+
{"version":3,"file":"page-source-inspector-app.js","sourceRoot":"","sources":["../../src/ui/page-source-inspector-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,2BAA2B,EAAC,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B;IAC5C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAuGD,iBAAiB;QACjB,iBAAiB;QACjB,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6OhC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-inspector-scripts.d.ts","sourceRoot":"","sources":["../../src/ui/xml-inspector-scripts.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,eAAO,MAAM,iBAAiB,QAsC7B,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAiD7B,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** Shared browser helpers embedded by both inspector transports. Keep these scripts data-free. */
|
|
2
|
+
export const XML_FORMAT_SCRIPT = String.raw `
|
|
3
|
+
function formatXml(source) {
|
|
4
|
+
const documentNode = new DOMParser().parseFromString(source, 'text/xml');
|
|
5
|
+
if (!documentNode.documentElement || documentNode.getElementsByTagName('parsererror').length) {
|
|
6
|
+
throw new Error('Invalid XML');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function indentElement(element, depth) {
|
|
10
|
+
// Whitespace can be meaningful in mixed content, CDATA and preserved subtrees.
|
|
11
|
+
if (element.getAttribute('xml:space') === 'preserve') return;
|
|
12
|
+
const children = Array.from(element.childNodes);
|
|
13
|
+
const hasText = children.some(child =>
|
|
14
|
+
child.nodeType === 4 || (child.nodeType === 3 && (child.nodeValue || '').trim())
|
|
15
|
+
);
|
|
16
|
+
if (hasText || !children.some(child => child.nodeType === 1)) return;
|
|
17
|
+
for (const child of children) {
|
|
18
|
+
if (child.nodeType === 3) {
|
|
19
|
+
element.removeChild(child);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (child.nodeType === 1) indentElement(child, depth + 1);
|
|
23
|
+
element.insertBefore(documentNode.createTextNode('\n' + ' '.repeat(depth + 1)), child);
|
|
24
|
+
}
|
|
25
|
+
element.appendChild(documentNode.createTextNode('\n' + ' '.repeat(depth)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
indentElement(documentNode.documentElement, 0);
|
|
29
|
+
const serializer = new XMLSerializer();
|
|
30
|
+
let formatted = Array.from(documentNode.childNodes)
|
|
31
|
+
.filter(node => node.nodeType !== 3)
|
|
32
|
+
.map(node => serializer.serializeToString(node))
|
|
33
|
+
.join('\n');
|
|
34
|
+
const declaration = source.match(/^\s*(<\?xml\s[^?]*\?>)/);
|
|
35
|
+
if (declaration && !formatted.startsWith('<?xml ')) {
|
|
36
|
+
formatted = declaration[1] + '\n' + formatted;
|
|
37
|
+
}
|
|
38
|
+
return formatted;
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
export const XML_SEARCH_SCRIPT = String.raw `
|
|
42
|
+
function createXmlSearch(container, status) {
|
|
43
|
+
let matches = [];
|
|
44
|
+
let activeIndex = -1;
|
|
45
|
+
|
|
46
|
+
function render(text, query) {
|
|
47
|
+
container.textContent = '';
|
|
48
|
+
matches = [];
|
|
49
|
+
activeIndex = -1;
|
|
50
|
+
query = query.trim();
|
|
51
|
+
status.textContent = '';
|
|
52
|
+
if (!query) {
|
|
53
|
+
container.textContent = text;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const lowerText = text.toLowerCase();
|
|
57
|
+
const lowerQuery = query.toLowerCase();
|
|
58
|
+
let position = 0;
|
|
59
|
+
while (position < text.length) {
|
|
60
|
+
const index = lowerText.indexOf(lowerQuery, position);
|
|
61
|
+
if (index === -1) break;
|
|
62
|
+
container.appendChild(document.createTextNode(text.slice(position, index)));
|
|
63
|
+
const mark = document.createElement('mark');
|
|
64
|
+
mark.textContent = text.slice(index, index + query.length);
|
|
65
|
+
container.appendChild(mark);
|
|
66
|
+
matches.push(mark);
|
|
67
|
+
position = index + query.length;
|
|
68
|
+
}
|
|
69
|
+
container.appendChild(document.createTextNode(text.slice(position)));
|
|
70
|
+
status.textContent = matches.length ? matches.length + ' matches · Enter / Shift+Enter to navigate' : 'No matches';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleKeyDown(event) {
|
|
74
|
+
if (event.key !== 'Enter' || event.isComposing) return;
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
if (!matches.length) return;
|
|
77
|
+
if (activeIndex >= 0) matches[activeIndex].removeAttribute('data-active');
|
|
78
|
+
const step = event.shiftKey ? -1 : 1;
|
|
79
|
+
activeIndex = activeIndex < 0
|
|
80
|
+
? (event.shiftKey ? matches.length - 1 : 0)
|
|
81
|
+
: (activeIndex + step + matches.length) % matches.length;
|
|
82
|
+
const match = matches[activeIndex];
|
|
83
|
+
match.setAttribute('data-active', 'true');
|
|
84
|
+
match.scrollIntoView({block: 'nearest', inline: 'nearest'});
|
|
85
|
+
status.textContent = (activeIndex + 1) + ' / ' + matches.length + ' · Enter / Shift+Enter to navigate';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {render, handleKeyDown};
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
//# sourceMappingURL=xml-inspector-scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-inspector-scripts.js","sourceRoot":"","sources":["../../src/ui/xml-inspector-scripts.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsC1C,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiD1C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.99.1",
|
|
4
4
|
"description": "Intelligent MCP server providing AI assistants with powerful tools and resources for Appium mobile automation",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/appium/appium-mcp/issues"
|
package/server.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"name": "io.github.appium/appium-mcp",
|
|
4
4
|
"title": "MCP Appium - Mobile Development and Automation Server",
|
|
5
5
|
"description": "MCP server for Appium mobile automation on iOS and Android devices with test creation tools.",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.99.1",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "appium-mcp",
|
|
11
|
-
"version": "1.
|
|
11
|
+
"version": "1.99.1",
|
|
12
12
|
"transport": {
|
|
13
13
|
"type": "stdio"
|
|
14
14
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {JSONElement} from './source-parsing.js';
|
|
2
|
+
import type {DriverName} from './types.js';
|
|
2
3
|
|
|
3
4
|
export interface FilterOptions {
|
|
5
|
+
query?: string;
|
|
4
6
|
includeTagNames?: string[];
|
|
5
7
|
excludeTagNames?: string[];
|
|
6
8
|
requireAttributes?: string[];
|
|
@@ -16,9 +18,10 @@ export function shouldIncludeElement(
|
|
|
16
18
|
element: JSONElement,
|
|
17
19
|
filters: FilterOptions,
|
|
18
20
|
isNative: boolean,
|
|
19
|
-
automationName:
|
|
21
|
+
automationName: DriverName,
|
|
20
22
|
): boolean {
|
|
21
23
|
const {
|
|
24
|
+
query,
|
|
22
25
|
includeTagNames = [],
|
|
23
26
|
excludeTagNames = ['hierarchy'],
|
|
24
27
|
requireAttributes = [],
|
|
@@ -27,6 +30,10 @@ export function shouldIncludeElement(
|
|
|
27
30
|
clickableOnly = false,
|
|
28
31
|
} = filters;
|
|
29
32
|
|
|
33
|
+
if (!matchesSearchQuery(element, query)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
if (!matchesTagFilters(element, includeTagNames, excludeTagNames)) {
|
|
31
38
|
return false;
|
|
32
39
|
}
|
|
@@ -46,6 +53,15 @@ export function shouldIncludeElement(
|
|
|
46
53
|
return true;
|
|
47
54
|
}
|
|
48
55
|
|
|
56
|
+
/** Literal substring matching applies only to this element, never its descendants. */
|
|
57
|
+
function matchesSearchQuery(element: JSONElement, query?: string): boolean {
|
|
58
|
+
const search = query?.trim().toLowerCase();
|
|
59
|
+
if (!search) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return [element.tagName, ...Object.values(element.attributes)].some((value) => value.toLowerCase().includes(search));
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
/**
|
|
50
66
|
* Determines if an element matches the tag name filters
|
|
51
67
|
*/
|
|
@@ -84,7 +100,7 @@ function matchesAttributeFilters(
|
|
|
84
100
|
/**
|
|
85
101
|
* Determines if an element is interactable/fetchable based on platform
|
|
86
102
|
*/
|
|
87
|
-
function isInteractableElement(element: JSONElement, isNative: boolean, automationName:
|
|
103
|
+
function isInteractableElement(element: JSONElement, isNative: boolean, automationName: DriverName): boolean {
|
|
88
104
|
if (!isNative) {
|
|
89
105
|
const tag = element.tagName.toLowerCase();
|
|
90
106
|
const attrs = element.attributes;
|
|
@@ -99,20 +115,38 @@ function isInteractableElement(element: JSONElement, isNative: boolean, automati
|
|
|
99
115
|
(attrs.tabindex !== undefined && Number(attrs.tabindex) >= 0)
|
|
100
116
|
);
|
|
101
117
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
let interactableTags: string[];
|
|
119
|
+
switch (automationName) {
|
|
120
|
+
case 'uiautomator2':
|
|
121
|
+
interactableTags = [
|
|
122
|
+
'EditText',
|
|
123
|
+
'Button',
|
|
124
|
+
'ImageButton',
|
|
125
|
+
'CheckBox',
|
|
126
|
+
'RadioButton',
|
|
127
|
+
'Switch',
|
|
128
|
+
'ToggleButton',
|
|
129
|
+
'TextView',
|
|
130
|
+
];
|
|
131
|
+
break;
|
|
132
|
+
case 'xcuitest':
|
|
133
|
+
interactableTags = [
|
|
134
|
+
'XCUIElementTypeTextField',
|
|
135
|
+
'XCUIElementTypeSecureTextField',
|
|
136
|
+
'XCUIElementTypeButton',
|
|
137
|
+
'XCUIElementTypeImage',
|
|
138
|
+
'XCUIElementTypeSwitch',
|
|
139
|
+
'XCUIElementTypeStaticText',
|
|
140
|
+
'XCUIElementTypeTextView',
|
|
141
|
+
'XCUIElementTypeCell',
|
|
142
|
+
'XCUIElementTypeLink',
|
|
143
|
+
];
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
// Other native drivers use their own XML schemas. Do not require mobile
|
|
147
|
+
// element types or clickable/focusable attributes before generating XPath.
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
116
150
|
|
|
117
151
|
return (
|
|
118
152
|
interactableTags.some((tag) => element.tagName.includes(tag)) ||
|
|
@@ -7,6 +7,12 @@ import type {FilterOptions} from './element-filter.js';
|
|
|
7
7
|
import {getSuggestedLocators} from './locator-generation.js';
|
|
8
8
|
import {xmlToJSON} from './source-parsing.js';
|
|
9
9
|
import type {JSONElement} from './source-parsing.js';
|
|
10
|
+
import type {DriverName} from './types.js';
|
|
11
|
+
|
|
12
|
+
export interface LocatorGenerationOptions extends FilterOptions {
|
|
13
|
+
/** Additional XPath attributes, tried before the built-in attributes. */
|
|
14
|
+
xpathAttributes?: string[];
|
|
15
|
+
}
|
|
10
16
|
|
|
11
17
|
export interface ElementWithLocators {
|
|
12
18
|
tagName: string;
|
|
@@ -31,8 +37,8 @@ export interface ElementWithLocators {
|
|
|
31
37
|
export function generateAllElementLocators(
|
|
32
38
|
sourceXML: string,
|
|
33
39
|
isNative: boolean = true,
|
|
34
|
-
automationName:
|
|
35
|
-
filters:
|
|
40
|
+
automationName: DriverName,
|
|
41
|
+
filters: LocatorGenerationOptions = {},
|
|
36
42
|
): ElementWithLocators[] {
|
|
37
43
|
const sourceJSON = xmlToJSON(sourceXML);
|
|
38
44
|
const results: ElementWithLocators[] = [];
|
|
@@ -76,8 +82,8 @@ function processElement(
|
|
|
76
82
|
element: JSONElement,
|
|
77
83
|
sourceXML: string,
|
|
78
84
|
isNative: boolean,
|
|
79
|
-
automationName:
|
|
80
|
-
filters:
|
|
85
|
+
automationName: DriverName,
|
|
86
|
+
filters: LocatorGenerationOptions,
|
|
81
87
|
results: ElementWithLocators[],
|
|
82
88
|
): void {
|
|
83
89
|
if (!shouldIncludeElement(element, filters, isNative, automationName)) {
|
|
@@ -85,7 +91,7 @@ function processElement(
|
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
try {
|
|
88
|
-
const strategyMap = getSuggestedLocators(element, sourceXML, isNative, automationName);
|
|
94
|
+
const strategyMap = getSuggestedLocators(element, sourceXML, isNative, automationName, filters.xpathAttributes);
|
|
89
95
|
results.push(transformElementWithLocators(element, strategyMap));
|
|
90
96
|
} catch (error) {
|
|
91
97
|
log.error(`Error generating locators for element at path ${element.path}:`, error);
|
|
@@ -99,8 +105,8 @@ function traverseAndProcessElements(
|
|
|
99
105
|
element: JSONElement | null,
|
|
100
106
|
sourceXML: string,
|
|
101
107
|
isNative: boolean,
|
|
102
|
-
automationName:
|
|
103
|
-
filters:
|
|
108
|
+
automationName: DriverName,
|
|
109
|
+
filters: LocatorGenerationOptions,
|
|
104
110
|
results: ElementWithLocators[],
|
|
105
111
|
): void {
|
|
106
112
|
if (!element) {
|