@nbakka/mcp-appium 1.0.26 → 1.0.27
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/package.json +1 -1
- package/src/lib/server.js +16 -20
package/package.json
CHANGED
package/src/lib/server.js
CHANGED
|
@@ -147,44 +147,40 @@ server.tool(
|
|
|
147
147
|
// Get visible text elements including duplicates
|
|
148
148
|
server.tool(
|
|
149
149
|
"get_visible_text_elements",
|
|
150
|
-
"Get all visible texts from screen
|
|
150
|
+
"Get all visible texts from screen JSON source including duplicates",
|
|
151
151
|
{},
|
|
152
152
|
async () => {
|
|
153
153
|
if (!state.sessionId) return { content: [{ type: "text", text: "No active session" }] };
|
|
154
154
|
try {
|
|
155
155
|
const response = await axios.get(`${APPIUM_URL}/session/${state.sessionId}/source`);
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
function collectTexts(node, texts = []) {
|
|
156
|
+
const data = response.data;
|
|
157
|
+
console.log(response.data);
|
|
158
|
+
function collectTextsFromJson(node, texts = []) {
|
|
161
159
|
if (!node) return texts;
|
|
162
|
-
|
|
163
160
|
if (Array.isArray(node)) {
|
|
164
|
-
node.forEach(child =>
|
|
161
|
+
node.forEach(child => collectTextsFromJson(child, texts));
|
|
165
162
|
return texts;
|
|
166
163
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
else {
|
|
164
|
+
if (typeof node === "object") {
|
|
165
|
+
if (node.text && node.text.trim() !== "") {
|
|
166
|
+
texts.push(node.text.trim());
|
|
167
|
+
}
|
|
168
|
+
if (node.children) {
|
|
169
|
+
collectTextsFromJson(node.children, texts);
|
|
170
|
+
}
|
|
175
171
|
for (const key in node) {
|
|
176
|
-
if (typeof node[key] === "object") {
|
|
177
|
-
|
|
172
|
+
if (key !== "text" && key !== "children" && typeof node[key] === "object") {
|
|
173
|
+
collectTextsFromJson(node[key], texts);
|
|
178
174
|
}
|
|
179
175
|
}
|
|
180
176
|
}
|
|
181
177
|
return texts;
|
|
182
178
|
}
|
|
183
179
|
|
|
184
|
-
const allTexts =
|
|
180
|
+
const allTexts = collectTextsFromJson(data);
|
|
185
181
|
return { content: [{ type: "json", json: allTexts }] };
|
|
186
182
|
} catch (e) {
|
|
187
|
-
return { content: [{ type: "text", text: `Error fetching or parsing
|
|
183
|
+
return { content: [{ type: "text", text: `Error fetching or parsing source: ${e.message}` }] };
|
|
188
184
|
}
|
|
189
185
|
}
|
|
190
186
|
);
|