Skip to content

Comments

feat: add context optimization#94

Open
JinTanba wants to merge 3 commits intoappium:mainfrom
JinTanba:feature-context-op
Open

feat: add context optimization#94
JinTanba wants to merge 3 commits intoappium:mainfrom
JinTanba:feature-context-op

Conversation

@JinTanba
Copy link

@JinTanba JinTanba commented Jan 14, 2026

Page Source Filtering

Summary

  • Add page source filtering for Android to reduce output size by ~92%

New Tools

Page Source Filtering

The appium_get_page_source tool now returns filtered JSON for Android devices instead of raw XML:

Metric Before After Reduction
Output size ~80KB ~6KB 92%
Elements ~120 ~40 67%

Filtered output includes:

  • Interactive elements (buttons, inputs, etc.)
  • Elements with content-desc (accessibility)
  • Elements with resource-id
  • Locator strategy/selector for direct use with appium_find_element

Example output:

{
  "elements": [
    {
      "type": "Button",
      "text": "Login",
      "strategy": "accessibility id",
      "selector": "Login button",
      "clickable": true
    }
  ],
  "stats": {
    "totalElements": 120,
    "filteredElements": 41
  }
}

Use raw=true parameter to get unfiltered XML if needed.

Test Plan

  • Verified with Twitter app page source
  • Verified with Instagram app page source
  • Build passes

@JinTanba JinTanba closed this Jan 15, 2026
@JinTanba JinTanba reopened this Jan 15, 2026
Comment on lines +134 to +139
if (el['@_text']) {
return {
strategy: '-android uiautomator',
selector: `new UiSelector().text("${el['@_text']}")`,
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to avoid using this UiSelector since Google is going to deprecate it
https://developer.android.com/training/testing/other-components/ui-automator-legacy#ui-automator

]);

// Interactive classes that should always be kept
const INTERACTIVE_CLASSES = new Set([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you collect them? (I'm not sure if they are sufficient for this "interactive" meaning.)
If you have a reference for these list, it makes sense to leave such a url etc in the comment for future maintenance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are other layout classes from the apps that needs to be fetched, which is not in the list here? We should all the users to append to this list from the config we have

};
}

// Layout containers that should be excluded
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As same as INTERACTIVE_CLASSES, it makes sense to leave a rerefence for them

@@ -0,0 +1,67 @@
/**
* Test script to verify page-source-filter with real data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this kind of code into tests https://github.com/appium/appium-mcp/tree/main/src/tests and implement as test code with jest

]);

// Interactive classes that should always be kept
const INTERACTIVE_CLASSES = new Set([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are other layout classes from the apps that needs to be fetched, which is not in the list here? We should all the users to append to this list from the config we have

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants