-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat(selenium-devtools-py): Python Selenium adapter, and a runnable backend entry #246
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
Open
vishnuv688
wants to merge
23
commits into
main
Choose a base branch
from
vv/selenium-python-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,575
−17
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6a1c33c
feat(selenium-py-devtools): add Python Selenium adapter
vishnuv688 d441d6a
chore(selenium-py-devtools): remove python-spike proof-of-concept
vishnuv688 6bd69a9
ci(selenium-py-devtools): add path-filtered test + OIDC release workf…
vishnuv688 2aa29c5
feat(selenium-py-devtools): WS transport, backend launch, dashboard w…
vishnuv688 7046401
feat(selenium-py-devtools): BiDi console + network capture
vishnuv688 2fec768
feat(selenium-py-devtools): DOM snapshot capture via injected collector
vishnuv688 cdb5ff9
feat(selenium-py-devtools): main-thread per-command screencast recorder
vishnuv688 326fb59
feat(selenium-py-devtools): send test-file source for the Source tab
vishnuv688 85815da
feat(selenium-py-devtools): stream runner logs + stdout to the Console
vishnuv688 efc57a3
feat(selenium-py-devtools): command capture core + per-command screen…
vishnuv688 71e9a8e
feat(selenium-py-devtools): pytest plugin
vishnuv688 abc0cf3
docs(selenium-py-devtools): README + runnable web-form example
vishnuv688 2d49142
Merge branch 'main' into vv/selenium-python-integration
vishnuv688 2dec0b8
Merge branch 'main' into vv/selenium-python-integration
vishnuv688 6a423b8
Potential fix for pull request finding 'CodeQL / Workflow does not co…
vishnuv688 eb6969d
refactor(selenium-py-devtools): rename the package to devtools-selenium
vishnuv688 c25dcde
refactor(selenium-devtools-py): name the package, module and director…
vishnuv688 7fdbe55
chore(py-backend): Wired backend for selenium py demo
vishnuv688 14e12d6
Merge branch 'main' into vv/selenium-python-integration
vishnuv688 0cb56bb
Merge branch 'main' into vv/selenium-python-integration
vishnuv688 91b2ee2
test(selenium-devtools-py): stop three tests depending on a build art…
vishnuv688 2b09465
fix(selenium-devtools-py): write run output to test-results, like the…
vishnuv688 f867b03
chore(selenium-devtools-py): stop the python job running on shared, a…
vishnuv688 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,9 @@ | ||
| --- | ||
| "@wdio/devtools-backend": minor | ||
| --- | ||
|
|
||
| The backend ships a runnable entry, so a non-Node adapter can start the dashboard itself. | ||
|
|
||
| - `dist/server.js` is a new CLI entry, exposed as the `devtools-backend` bin. `node packages/backend/dist/server.js` and `npx @wdio/devtools-backend` both start the live dashboard, and `--port` / `--hostname` / `--help` are accepted. | ||
| - `dist/index.js` stays the library entry the JS adapters import in-process. Its "start if run directly" guard is gone rather than repaired: `show-trace.ts` imports `start` from index, which makes index a shared module whose body tsup hoists into `dist/chunk-*.js`, and there `import.meta.url` is the chunk's path and can never equal `process.argv[1]`. The guard was therefore dead in every build, which is why `node dist/index.js` imported a module and exited 0 without serving. A leaf entry keeps its body in its own output file, so the new file needs no guard at all. | ||
| - `dev:app` now runs `dist/server.js`, since it was watching an entry that could not start. |
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,52 @@ | ||
| name: Manual PyPI Publish | ||
|
|
||
| # Mirrors release.yml's manual, button-triggered shape for the Python adapter. | ||
| # Unlike npm (NPM_TOKEN), PyPI uses trusted publishing (OIDC) — no secret. | ||
| # Bump the version in packages/selenium-devtools-py/pyproject.toml before running. | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| target: | ||
| description: 'Publish target' | ||
| required: true | ||
| type: choice | ||
| default: pypi | ||
| options: | ||
| - pypi | ||
| - testpypi | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: packages/selenium-devtools-py | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
| environment: ${{ inputs.target }} | ||
| permissions: | ||
| id-token: write # PyPI trusted publishing (OIDC) — no token/secret needed | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| ref: 'main' | ||
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | ||
| with: | ||
| python-version: '3.12' | ||
| - name: 🧪 Unit tests (release guard) | ||
| run: PYTHONPATH=src python -m unittest discover -s tests | ||
| - name: 📦 Build sdist + wheel | ||
| run: | | ||
| python -m pip install --upgrade build | ||
| python -m build | ||
| - name: 🚀 Publish to PyPI | ||
| if: ${{ inputs.target == 'pypi' }} | ||
| uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # release/v1 | ||
| with: | ||
| packages-dir: packages/selenium-devtools-py/dist | ||
| - name: 🚀 Publish to TestPyPI | ||
| if: ${{ inputs.target == 'testpypi' }} | ||
| uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # release/v1 | ||
| with: | ||
| packages-dir: packages/selenium-devtools-py/dist | ||
| repository-url: https://test.pypi.org/legacy/ |
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,46 @@ | ||
| name: Python Adapter | ||
|
|
||
| # Deliberately NOT triggered by packages/shared/**, even though the adapter's | ||
| # wire contract is generated from it. Doing so put a Python check on every PR | ||
| # that touched shared, which is most of them, and a red Python job would block | ||
| # work unrelated to this adapter. The trade-off: a shared change that breaks the | ||
| # contract is not caught here at the moment it lands. It is still caught by the | ||
| # drift check below on the next PR that touches this package, which regenerates | ||
| # _contract.py and fails on any diff. Revisit once the adapter is published and | ||
| # the coupling is worth the noise. | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - packages/selenium-devtools-py/** | ||
| - .github/workflows/python.yml | ||
| pull_request: | ||
| paths: | ||
| - packages/selenium-devtools-py/** | ||
| - .github/workflows/python.yml | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: packages/selenium-devtools-py | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ['3.9', '3.12'] | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Contract is in sync with shared | ||
| run: | | ||
| python scripts/gen_contract.py | ||
| git diff --exit-code src/selenium_devtools/_contract.py | ||
| - name: 🧪 Unit tests | ||
| run: PYTHONPATH=src python -m unittest discover -s tests | ||
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,3 @@ | ||
| # Run output goes to test-results/, which the root .gitignore already covers. | ||
| # *.webm stays for videos written by older versions of the adapter. | ||
| *.webm |
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,35 @@ | ||
| """The smallest useful DevTools example: three devtools lines, one Selenium test. | ||
|
|
||
| This is the script reproduced in the integration one-pager, so keep the two in | ||
| sync when either changes. | ||
|
|
||
| Run it: | ||
|
|
||
| pip install -e packages/selenium-devtools-py | ||
| python examples/selenium/python-test/web_form.py | ||
|
|
||
| ``enable()`` starts the dashboard backend itself when none is running. Set | ||
| DEVTOOLS_PORT instead to attach to one you already have open. Run output (the | ||
| screencast .webm) lands in ``test-results/`` beside this file, matching the JS | ||
| adapters. | ||
| """ | ||
|
|
||
| import selenium_devtools as devtools | ||
| from selenium import webdriver | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.chrome.options import Options | ||
|
|
||
| devtools.enable() # opens the dashboard, starts capturing | ||
|
|
||
| options = Options() | ||
| options.add_argument("--headless=new") # drop this line to watch the browser | ||
| options.add_argument("--window-size=1280,1024") # bigger viewport, fuller screencast | ||
| driver = webdriver.Chrome(options=options) | ||
| try: | ||
| driver.get("https://www.selenium.dev/selenium/web/web-form.html") | ||
| driver.find_element(By.NAME, "my-text").send_keys("Selenium") | ||
| driver.find_element(By.CSS_SELECTOR, "button").click() | ||
| print(driver.find_element(By.ID, "message").text) | ||
| finally: | ||
| driver.quit() | ||
| devtools.wait_for_dashboard_close() # hold the UI open to inspect |
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
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,44 @@ | ||
| /** | ||
| * Argv parsing for the `devtools-backend` bin. Split from `server.ts` because | ||
| * that file starts a server as its module body, so a unit test cannot import it. | ||
| */ | ||
|
|
||
| export const SERVER_USAGE = ` | ||
| Usage: devtools-backend [options] | ||
|
|
||
| Options: | ||
| --port <number> Preferred port; a free one is chosen if it is taken | ||
| --hostname <host> Host to bind (default: localhost) | ||
| -h, --help Show this message | ||
| ` | ||
|
|
||
| export interface ServerArgs { | ||
| help: boolean | ||
| port?: number | ||
| hostname?: string | ||
| } | ||
|
|
||
| /** Read `--name value` or `--name=value`, whichever the caller used. */ | ||
| function option(args: string[], name: string): string | undefined { | ||
| const flag = `--${name}` | ||
| const at = args.indexOf(flag) | ||
| if (at !== -1) { | ||
| return args[at + 1] | ||
| } | ||
| return args.find((arg) => arg.startsWith(`${flag}=`))?.slice(flag.length + 1) | ||
| } | ||
|
|
||
| /** | ||
| * A port is kept only when it parses as a positive integer, so `--port` with no | ||
| * value, `--port abc` and `--port 0` all fall through to the server's own | ||
| * default rather than binding something the caller did not ask for. | ||
| */ | ||
| export function parseServerArgs(args: string[]): ServerArgs { | ||
| const port = Number(option(args, 'port')) | ||
| const hostname = option(args, 'hostname') | ||
| return { | ||
| help: args.includes('-h') || args.includes('--help'), | ||
| ...(Number.isInteger(port) && port > 0 ? { port } : {}), | ||
| ...(hostname ? { hostname } : {}) | ||
| } | ||
| } |
Oops, something went wrong.
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.