-
-
Notifications
You must be signed in to change notification settings - Fork 296
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
feat: enable appium-inspector as an appium plugin #1878
Changes from 53 commits
3ce0cfd
0764820
bc95a0a
f37a521
afa3bf8
9e514c0
5d42e24
1b812da
01a2652
b897b2e
090f50f
d92a944
659d9b7
30c634b
bfdc8e1
5b40a50
a994da9
fb89cf2
231bbc0
3b5fa7d
b9a371b
5469ea3
4c53dab
cb25743
dcf4f63
1c3edc0
86e7006
4d2f828
5248688
a4d14c6
c0934ab
4ed1bd3
9b84563
c67908c
cbb53d0
9f56ed5
b1eb482
972545a
c5fb734
5f5df23
abe014b
33748b8
94ec121
b355207
cb79ed3
3db1202
0ec99fa
fa48100
a42007f
5596c40
0e11407
53fefc4
5916dcc
a2f53a8
8daadd0
352f9a3
f736397
5ea336f
dcaace4
158b537
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,16 +34,19 @@ | |
"build": "npm run build:browser && npm run build:electron", | ||
"build:browser": "vite build", | ||
"build:browser:url": "vite build --base $PUBLIC_URL", | ||
"build:plugin": "vite build --base /inspector --outDir ../../plugins/dist-browser", | ||
"build:electron": "electron-vite build", | ||
"preview:browser": "npm run build:browser && vite preview", | ||
"preview:electron": "electron-vite preview", | ||
"pack:electron": "electron-builder build --publish never", | ||
"clean": "npm run clean:electron && npm run clean:browser && npm run clean:npm", | ||
"clean:electron": "rimraf dist/ && rimraf node_modules/.vite/ && rimraf node_modules/.vite-electron-renderer/", | ||
"clean:browser": "rimraf dist-browser/ && rimraf node_modules/.vite/", | ||
"clean:plugin": "rimraf plugins/dist-browser", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
"clean:npm": "rimraf package-lock.json && rimraf node_modules && npm install", | ||
"build:docs": "appium-docs build", | ||
"dev:docs": "appium-docs build --serve", | ||
"plugin:sync:version": "node ./scripts/sync-plugin.mjs", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
"publish:docs": "appium-docs build --deploy --push -b docs-site -m 'docs: build docs for appium-inspector@%s' --alias latest", | ||
"install-docs-deps": "appium-docs init --no-mkdocs", | ||
"postversion": "git pull --tags && git push && git push --tags", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Appium Inspector Plugin | ||
|
||
A plugin that integrates the [Appium Inspector](https://github.com/appium/appium-inspector) directly into your Appium server installation, providing a web-based interface for inspecting and interacting with your application under test. | ||
|
||
## Features | ||
|
||
- Web-based Appium Inspector interface accessible via `/inspector` endpoint with appium server | ||
- Full feature parity with standalone Appium Inspector | ||
|
||
## Installation | ||
|
||
Install the plugin using one of the following methods: | ||
|
||
```bash | ||
# Install from local directory | ||
appium plugin install --source=local /path/to/appium-inspector/plugins | ||
|
||
# Install from npm | ||
appium plugin install --source=npm appium-inspector-plugin | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to only include the npm method here ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, i think we can remove the local installtion after updating https://www.npmjs.com/package/appium-inspector-plugin. Currently I mainly expect to use local installation as this PR. I haven't tested npm installation yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remvoed via npm method for now as I haven't tested it yet. It might need more things to be adjusted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you invite https://www.npmjs.com/~kazucocoa to the npm package? @saikrishna321 Then, I'd like to add the package in https://www.npmjs.com/settings/appium/packages for future releases. |
||
|
||
> [!Note] | ||
> Appium 3 will support this plugin as a first-class plugin with `appium plugin install inspector` | ||
|
||
## Usage | ||
|
||
1. Start Appium server with the inspector plugin enabled: | ||
|
||
```bash | ||
appium --use-plugins=inspector --allow-cors | ||
``` | ||
|
||
2. Access the Inspector interface by navigating to: | ||
|
||
``` | ||
http://localhost:4723/inspector | ||
``` | ||
|
||
## Development | ||
|
||
1. `git clone` this repositiry | ||
2. `appium plugin install --source=local /path/to/appium-inspector/plugins` | ||
3. Update the plugin content with `npm run build:plugin` in `/path/to/appium-inspector` | ||
4. Start Appium with `appium --use-plugins=inspector --allow-cors` | ||
|
||
This plugin only needs the `appium` server as a `peerDependencies`. | ||
|
||
## Release | ||
|
||
(TODO: add this release steps in .github/workflows/package.yml later as another PR) | ||
|
||
1. Run `npm run plugin:sync:version` to sync the version with the root project.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say this script should be executed automatically as soon as we bump the version of the main project via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It will be a follow-up PR to treat npm publish stuff in my current plan. |
||
2. Run `npm publish` in `/path/to/appium-inspector/plugins` to publish the module | ||
|
||
## License | ||
|
||
[Apache-2.0](https://github.com/appium/appium-inspector/blob/main/LICENSE) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
|
||
import {BasePlugin} from '@appium/base-plugin'; | ||
saikrishna321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const PLUGIN_ROOT_PATH = '/inspector'; | ||
const INDEX_HTML = 'index.html'; | ||
const ROOT_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'dist-browser'); | ||
|
||
/** | ||
* Appium Inspector Plugin class | ||
* @extends {BasePlugin} | ||
*/ | ||
export class AppiumInspectorPlugin extends BasePlugin { | ||
/** | ||
* Creates an instance of AppiumInspectorPlugin | ||
* @param {string} name - The name of the plugin | ||
* @param {Record<string, unknown>} cliArgs - Command line arguments | ||
*/ | ||
constructor(name, cliArgs) { | ||
super(name, cliArgs); | ||
} | ||
|
||
/** | ||
* Handles inspector page requests | ||
* @param {import('express').Request} req - Express request object | ||
* @param {import('express').Response} res - Express response object | ||
* @returns {Promise<void>} | ||
*/ | ||
static async openInspector(req, res) { | ||
const reqPath = | ||
req.path === PLUGIN_ROOT_PATH ? INDEX_HTML : req.path.substring(PLUGIN_ROOT_PATH.length); | ||
res.sendFile(reqPath, {root: ROOT_DIR}); | ||
} | ||
|
||
/** | ||
* Updates the Express server configuration | ||
* @param {import('express').Application} expressApp - Express application instance | ||
* @returns {Promise<void>} | ||
*/ | ||
static async updateServer(expressApp) { | ||
// Handle both /inspector and /inspector/* paths | ||
expressApp.all(['/inspector', '/inspector/*'], AppiumInspectorPlugin.openInspector); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "appium-inspector-plugin", | ||
"version": "2024.12.1", | ||
"description": "An app inspector for use with an Appium server", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/appium/appium-inspector.git" | ||
}, | ||
"author": { | ||
"name": "Appium Developers", | ||
"url": "https://github.com/appium" | ||
}, | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/appium/appium-inspector/issues" | ||
}, | ||
"keywords": [ | ||
"appium" | ||
], | ||
"homepage": "https://github.com/appium/appium-inspector", | ||
"main": "index.mjs", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./index.mjs" | ||
} | ||
}, | ||
"peerDependencies": { | ||
"appium": "^2.0.0" | ||
}, | ||
"files": [ | ||
"index.mjs", | ||
"package.json", | ||
"dist-browser", | ||
"README.md" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"engines": { | ||
"node": ">=20.x", | ||
"npm": ">=10.x" | ||
}, | ||
"appium": { | ||
"pluginName": "inspector", | ||
"mainClass": "AppiumInspectorPlugin" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
|
||
import fs from 'node:fs/promises'; | ||
|
||
const ROOT_PKG_JSON_PATH = path.resolve( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
mykola-mokhnach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'..', | ||
'package.json', | ||
); | ||
const PLUGIN_PKG_JSON_PATH = path.resolve( | ||
path.dirname(fileURLToPath(import.meta.url)), | ||
'..', | ||
'plugins', | ||
'package.json', | ||
); | ||
|
||
/** | ||
* Return JSON parsed contents from the given path. | ||
* @param {string} path | ||
* @returns {Promise<object>} | ||
*/ | ||
async function readJsonContent(jsonPath) { | ||
return await JSON.parse(await fs.readFile(jsonPath, 'utf8')); | ||
mykola-mokhnach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
async function main() { | ||
const rootJsonContent = await readJsonContent(ROOT_PKG_JSON_PATH); | ||
mykola-mokhnach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const pluginJsonContent = await readJsonContent(PLUGIN_PKG_JSON_PATH); | ||
|
||
// To update ever version release | ||
pluginJsonContent.version = rootJsonContent.version; | ||
mykola-mokhnach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// These basic information should be the same with the top package.json | ||
pluginJsonContent.engines = rootJsonContent.engines; | ||
pluginJsonContent.license = rootJsonContent.license; | ||
pluginJsonContent.repository = rootJsonContent.repository; | ||
pluginJsonContent.author = rootJsonContent.author; | ||
pluginJsonContent.bugs = rootJsonContent.bugs; | ||
pluginJsonContent.homepage = rootJsonContent.homepage; | ||
|
||
// The new line in the last is to avoid prettier error. | ||
await fs.writeFile( | ||
PLUGIN_PKG_JSON_PATH, | ||
`${JSON.stringify(pluginJsonContent, null, 2)}\n`, | ||
'utf8', | ||
); | ||
} | ||
|
||
(async () => await main())(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be a part of the common
build
script?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to include this in
build
after completing npm publish work as well, so yes but not yet in this PR.