-
Notifications
You must be signed in to change notification settings - Fork 12
feat: add tools to interact with the app #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
80f5885
add interaction commands
sudharsan-selvaraj 113572c
use locators in priority order
sudharsan-selvaraj 778a3ed
fix dependencies
sudharsan-selvaraj 64815ce
Update src/tools/generate-tests.ts
saikrishna321 29addeb
Update src/tools/generate-tests.ts
saikrishna321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Using appium generate test tool create automation test for below step | ||
|
|
||
| Steps: | ||
| 1. Open Gmail app | ||
| 2. Compose a email to [email protected] with subject "Test email from appium" | ||
| 3. Add body as "Hello World!" | ||
| 4. and send |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Using appium generate test tool create automation test for below step | ||
|
|
||
| STEPS: | ||
| 1. Open TODO app | ||
| 2. Add a todo list with Title "Complete appium mcp server" | ||
| 3. Use June 25 2025 as date | ||
| 4. Add it to personal list | ||
|
|
||
| Use JAVA + Testng for test generation |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| export const elementUUIDScheme = z | ||
| .string() | ||
| .describe('The uuid of the element returned by appium_find_element to click'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { FastMCP } from 'fastmcp/dist/FastMCP.js'; | ||
| import { z } from 'zod'; | ||
|
|
||
| export default function generateTest(server: FastMCP): void { | ||
| const generateTestSchema = z.object({ | ||
| steps: z.array(z.string()).describe('The steps of the test'), | ||
| }); | ||
|
|
||
| const instructions = (params: { steps: string[] }) => | ||
| [ | ||
| `## Instructions`, | ||
| `- You are a Appium test generator.`, | ||
| `- You are given a scenario and you need to generate a appium test for it.`, | ||
| `- Request user to select the platform first using select_platform tool and create a session`, | ||
| `- Use generate_locators tool to fetch all interactable elements from the current screen and use it to generate the tests`, | ||
| `- Element can only be clicked only if it is clickable.`, | ||
| `- Text can entered in the element only if it is focusable`, | ||
| `- If any interaction on element is failed, retry again with a differnt possible locator in the hierrarchy`, | ||
| `- Interact with the app using the tools provided and generate the test`, | ||
| '- DO NOT generate test code based on the scenario alone. DO run steps one by one using the tools provided instead.', | ||
| '- Only after all steps are completed, emit a Appium test based on message history', | ||
| '- Save generated test file in the tests directory', | ||
| `- Use generate://code-with-locators resource as reference for code generation`, | ||
| `- Always call find_element_tool to retrieve the element UUID before interacting with the element`, | ||
| `Steps:`, | ||
| ...params.steps.map((step, index) => `- ${index + 1}. ${step}`), | ||
| ].join('\n'); | ||
|
|
||
| server.addTool({ | ||
| name: 'appium_generate_tests', | ||
| description: 'Generate tests for a given mobile app', | ||
| parameters: generateTestSchema, | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| openWorldHint: false, | ||
| }, | ||
| execute: async (args: any, context: any): Promise<any> => { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: 'text', | ||
| text: instructions({ | ||
| steps: args.steps, | ||
| }), | ||
| }, | ||
| ], | ||
| }; | ||
| }, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,25 @@ | ||
| import { FastMCP } from 'fastmcp/dist/FastMCP.js'; | ||
| import createSession from './create-session.js'; | ||
| import generateLocators from './locators.js'; | ||
| import selectPlatform from './select-platform.js'; | ||
| import generateTest from './generate-tests.js'; | ||
| import findElement from './interactions/find.js'; | ||
| import clickElement from './interactions/click.js'; | ||
| import setValue from './interactions/setValue.js'; | ||
| import getText from './interactions/getText.js'; | ||
| import screenshot from './interactions/screenshot.js'; | ||
|
|
||
| export default function registerTools(server: any): void { | ||
| export default function registerTools(server: FastMCP): void { | ||
| selectPlatform(server); | ||
| createSession(server); | ||
| generateLocators(server); | ||
|
|
||
| findElement(server); | ||
| clickElement(server); | ||
| setValue(server); | ||
| getText(server); | ||
| screenshot(server); | ||
|
|
||
| generateTest(server); | ||
| console.log('All tools registered'); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.