Repository navigation
feat: add the Selenium bridge for RemoteWebDriver and BiDi #2463
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
+1,258
−62
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec3e7f5
build: add the selenium-bridge subproject
mykola-mokhnach 0d99d99
feat: add the Selenium bridge for RemoteWebDriver and BiDi
mykola-mokhnach aac8e51
docs: describe the Selenium bridge
mykola-mokhnach aae9d97
fix: let Selenium take over the session in the bridge
mykola-mokhnach 6ef46b1
ci: run the e2e tests on the beta Appium when it is available
mykola-mokhnach 538f926
ci: wait for the iOS simulator to settle after the boot
mykola-mokhnach c8d0333
ci: rerun the checks with the new Appium beta
mykola-mokhnach 1a6b44d
Merge branch 'master' into stage6
harsha509 d888936
fix: address the review comments on the Selenium bridge
mykola-mokhnach 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,63 @@ | ||
| // Resolves the versions of the Appium server and of a driver to install in e2e jobs. | ||
| // Usage: node resolve-appium-versions.mjs [--stable] <server package> <driver package> | ||
| // Both get their beta versions if both have a beta that is newer than the latest stable release, | ||
| // otherwise both get the latest stable ones. With --stable the stable versions are always used. | ||
| // The result is written to the step outputs `server` and `driver`. | ||
| import {execFile} from 'node:child_process'; | ||
| import {appendFile} from 'node:fs/promises'; | ||
| import {promisify} from 'node:util'; | ||
|
|
||
| const execFileAsync = promisify(execFile); | ||
|
|
||
| async function distTags(pkg) { | ||
| const {stdout} = await execFileAsync('npm', ['view', pkg, 'dist-tags', '--json']); | ||
| return JSON.parse(stdout); | ||
| } | ||
|
|
||
| // A prerelease of a version is older than that version, so only a higher major.minor.patch is newer | ||
| function isBetaNewerThanStable(beta, stable) { | ||
| const core = (version) => version.split('-')[0].split('.').map(Number); | ||
| const [b, s] = [core(beta), core(stable)]; | ||
| for (let i = 0; i < 3; i++) { | ||
| if (b[i] !== s[i]) { | ||
| return b[i] > s[i]; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| async function main(args) { | ||
| const stableOnly = args.includes('--stable'); | ||
| const [serverPackage, driverPackage] = args.filter((arg) => arg !== '--stable'); | ||
| if (!serverPackage || !driverPackage) { | ||
| throw new Error('Usage: resolve-appium-versions.mjs [--stable] <server package> <driver package>'); | ||
| } | ||
|
|
||
| const packages = await Promise.all( | ||
| [serverPackage, driverPackage].map(async (name) => { | ||
| const {latest, beta} = await distTags(name); | ||
| return {name, latest, beta, betaIsNewer: Boolean(beta) && isBetaNewerThanStable(beta, latest)}; | ||
| }), | ||
| ); | ||
| const useBeta = !stableOnly && packages.every((p) => p.betaIsNewer); | ||
| const [server, driver] = packages.map((p) => (useBeta ? p.beta : p.latest)); | ||
|
|
||
| const summary = [ | ||
| `Appium versions to install: ${useBeta ? 'beta' : 'stable'}${stableOnly ? ' (forced)' : ''}`, | ||
| ...packages.map((p) => `- ${p.name}: stable ${p.latest}, beta ${p.beta ?? 'none'} => ${useBeta ? p.beta : p.latest}`), | ||
| ].join('\n'); | ||
| console.log(summary); | ||
| if (process.env.GITHUB_STEP_SUMMARY) { | ||
| await appendFile(process.env.GITHUB_STEP_SUMMARY, `${summary}\n`); | ||
| } | ||
| if (process.env.GITHUB_OUTPUT) { | ||
| await appendFile(process.env.GITHUB_OUTPUT, `server=${server}\ndriver=${driver}\n`); | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| await main(process.argv.slice(2)); | ||
| } catch (e) { | ||
| console.error(e.message); | ||
| process.exit(1); | ||
| } |
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,56 @@ | ||
| # Selenium interoperability | ||
|
|
||
| Appium Java client depends on `selenium-api` only, and its drivers are not Selenium `RemoteWebDriver` instances. | ||
| The optional `java-client-selenium-bridge` artifact adapts an Appium driver for the Selenium code that needs one, | ||
| for example the Selenium `Augmenter`, or the BiDi modules like `LogInspector`. It depends on | ||
| `selenium-remote-driver`, so it is compiled against the Selenium releases from 4.50.0 on, like the core artifact. | ||
|
|
||
| ```gradle | ||
| dependencies { | ||
| implementation('io.appium:java-client:X.Y.Z') | ||
| implementation('io.appium:java-client-selenium-bridge:X.Y.Z') | ||
| } | ||
| ``` | ||
|
|
||
| ## RemoteWebDriver | ||
|
|
||
| `SeleniumBridge.asRemoteWebDriver` returns a Selenium `RemoteWebDriver` that works in the session of the Appium | ||
| driver. Both share the same session and the same HTTP client, so commands can be mixed freely. As long as the | ||
| result is referenced, the same instance is returned for the same Appium driver. Quitting the Selenium driver | ||
| quits the session. | ||
|
|
||
| ```java | ||
| var driver = new AndroidDriver(serverUrl, options); | ||
| RemoteWebDriver selenium = SeleniumBridge.asRemoteWebDriver(driver); | ||
| WebDriver augmented = new Augmenter().augment(selenium); | ||
| ``` | ||
|
|
||
| Elements are not interchangeable between the two drivers: an element that one driver found cannot be passed to | ||
| the other, for example as a script argument. Find the element again with the driver that needs it. | ||
|
|
||
| The commands of Selenium that Appium does not serve, like downloads, are not available. | ||
|
|
||
| ## BiDi | ||
|
|
||
| Create the session with the `webSocketUrl` capability (`options.enableBiDi()`), then pass the Selenium driver | ||
| to a BiDi module. Selenium opens the WebSocket connection when the bridge is created, with the timeouts, proxy, | ||
| credentials and SSL context of the `AppiumClientConfig` of the driver. If the connection cannot be made, the | ||
| BiDi modules fail with a `BiDiException`. | ||
|
|
||
| ```java | ||
| var driver = new AndroidDriver(serverUrl, options.enableBiDi()); | ||
| var selenium = SeleniumBridge.asRemoteWebDriver(driver); | ||
| try (var logInspector = new LogInspector(selenium)) { | ||
| logInspector.onGenericLog(entry -> System.out.println(entry.getText())); | ||
| driver.getPageSource(); | ||
| } finally { | ||
| selenium.closeBiDi(); | ||
| } | ||
| ``` | ||
|
|
||
| The connection stays open until `closeBiDi()` or `quit()`, so release it when you are done with the BiDi modules. | ||
| `closeBiDi()` keeps the session open, but the modules that were created before cannot be used afterwards. | ||
| The next `asRemoteWebDriver` call opens a new connection. | ||
|
|
||
| To customize the HTTP client that opens the WebSocket connection, use the `asRemoteWebDriver` overload that takes | ||
| a Selenium `HttpClient.Factory`. It creates a new Selenium driver with its own connection on every call. |
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
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.