|
| 1 | +--- |
| 2 | +title: WebDriver BiDi protocol support |
| 3 | +slug: support-bidi-protocol |
| 4 | +hide_table_of_contents: false |
| 5 | +date: 2025-05-06T14:00 |
| 6 | +--- |
| 7 | + |
| 8 | +import Admonition from "@theme/Admonition"; |
| 9 | +import mockNetworkRequestExampleUrl from "/video/blog/bidi/mock-network-request-example.mp4"; |
| 10 | +import networkResponsesExampleUrl from "/video/blog/bidi/network-responses-example.mp4"; |
| 11 | +import browserLogsExampleUrl from "/video/blog/bidi/browser-logs-example.mp4"; |
| 12 | +import screenFullPageExampleUrl from "/video/blog/bidi/screen-full-page-example.mp4"; |
| 13 | + |
| 14 | +Support for the [WebDriver BiDi protocol][bidi] (the future unified standard for browser automation) has been added in [testplane@8.27.0][testplane@8.27.0]. |
| 15 | + |
| 16 | +<!-- truncate --> |
| 17 | + |
| 18 | +WebDriver BiDi (Bidirectional) is a new cross-browser automation protocol that combines the best features of existing protocols: [W3C WebDriver][webdriver] and [Chrome DevTools Protocol (CDP)][cdp] (you can read more about them in our [article][webvider-vs-cdp]). |
| 19 | +Essentially, the new protocol extends the existing W3C WebDriver protocol and adds new cross-browser commands that replace the CDP protocol (which is not cross-browser compatible). |
| 20 | +Old webdriver commands still work via HTTP, while new commands provide bidirectional communication between the client and the browser via a WebSocket connection. |
| 21 | + |
| 22 | +The new protocol is currently supported by the following browsers: Chrome, Firefox, Edge. Safari support is not available yet. You can follow the supported browsers on this [page][bidi-browsers-support]. |
| 23 | + |
| 24 | +A list of BiDi protocol commands is available on this [page][bidi-commands]. |
| 25 | + |
| 26 | +### How to use? |
| 27 | + |
| 28 | +<Admonition type="warning"> |
| 29 | + BiDi protocol support in Testplane is available in browsers starting from version: chrome@128 |
| 30 | + and firefox@129. |
| 31 | +</Admonition> |
| 32 | + |
| 33 | +To use the BiDi protocol, you need to: |
| 34 | + |
| 35 | +- install testplane@8.27.0 or older; |
| 36 | +- specify the capability `webSocketUrl: true` in the `desiredCapabilities` field for the desired browser (it will be set by default in the next major version); |
| 37 | +- run the tests. |
| 38 | + |
| 39 | +### What can be done with the new protocol? |
| 40 | + |
| 41 | +#### Tracking and intercepting network requests/responses |
| 42 | + |
| 43 | +1. You can mock a request to testplane.io and return your own response: |
| 44 | + |
| 45 | +```typescript |
| 46 | +it("should mock testplane.io", async ({ browser }) => { |
| 47 | + await browser.networkAddIntercept({ phases: ["beforeRequestSent"] }); |
| 48 | + |
| 49 | + browser.on("network.beforeRequestSent", networkRequest => { |
| 50 | + browser.networkProvideResponse({ |
| 51 | + request: networkRequest.request.request, |
| 52 | + body: { |
| 53 | + type: "string", |
| 54 | + value: "hello world", |
| 55 | + }, |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + await browser.url("https://testplane.io"); |
| 60 | +}); |
| 61 | +``` |
| 62 | + |
| 63 | +<video src={mockNetworkRequestExampleUrl} width="100%" controls="controls"> |
| 64 | + Your browser does not support the video tag. |
| 65 | + <a href="video/blog/bidi/mock-network-request-example.mp4">Download the video</a>. |
| 66 | +</video> |
| 67 | + |
| 68 | +2. We will intercept all requests to the testplane.io resource and display a list of all loaded URLs: |
| 69 | + |
| 70 | +```typescript |
| 71 | +it("should log all loaded urls", async ({ browser }) => { |
| 72 | + browser.on("network.responseCompleted", networkResponse => |
| 73 | + console.log("got response from url:", networkResponse.response.url), |
| 74 | + ); |
| 75 | + |
| 76 | + await browser.url("https://testplane.io"); |
| 77 | +}); |
| 78 | +``` |
| 79 | + |
| 80 | +<video src={networkResponsesExampleUrl} width="100%" controls="controls"> |
| 81 | + Your browser does not support the video tag. |
| 82 | + <a href="video/blog/bidi/network-responses-example.mp4">Download the video</a>. |
| 83 | +</video> |
| 84 | + |
| 85 | +#### Displaying logs in the browser |
| 86 | + |
| 87 | +```typescript |
| 88 | +it("should show browser console logs", async ({ browser }) => { |
| 89 | + browser.on("log.entryAdded", entryAdded => console.log(JSON.stringify(entryAdded, null, 4))); |
| 90 | + |
| 91 | + await browser.execute(() => console.log("Hello Bidi")); |
| 92 | +}); |
| 93 | +``` |
| 94 | + |
| 95 | +<video src={browserLogsExampleUrl} width="100%" controls="controls"> |
| 96 | + Your browser does not support the video tag. |
| 97 | + <a href="video/blog/bidi/browser-logs-example.mp4">Download the video</a>. |
| 98 | +</video> |
| 99 | + |
| 100 | +#### Taking a screenshot of the entire page |
| 101 | + |
| 102 | +```typescript |
| 103 | +import * as fs from "node:fs"; |
| 104 | + |
| 105 | +it("should screen full page", async ({ browser }) => { |
| 106 | + await browser.url("https://www.npmjs.com/"); |
| 107 | + |
| 108 | + const tree = await browser.browsingContextGetTree({}); |
| 109 | + const file = await browser.browsingContextCaptureScreenshot({ |
| 110 | + context: tree.contexts[0].context, |
| 111 | + origin: "document", |
| 112 | + }); |
| 113 | + |
| 114 | + fs.writeFileSync("screenshot.png", Buffer.from(file.data, "base64")); |
| 115 | +}); |
| 116 | +``` |
| 117 | + |
| 118 | +<video src={screenFullPageExampleUrl} width="100%" controls="controls"> |
| 119 | + Your browser does not support the video tag. |
| 120 | + <a href="video/blog/bidi/screen-full-page-example.mp4">Download the video</a>. |
| 121 | +</video> |
| 122 | + |
| 123 | +### Conclusion |
| 124 | + |
| 125 | +While the BiDi protocol remains in the [Editor's Draft][editors-draft] stage, its potential as the future standard is already clear. |
| 126 | +Major browsers like Firefox have taken decisive steps toward adoption, [announcing the deprecation of CDP protocol support starting in version 129][ff-deprecate-cdp]. |
| 127 | + |
| 128 | +By embracing BiDi protocol support, we're empowering our users with: |
| 129 | + |
| 130 | +- enhanced test automation capabilities beyond what WebDriver could offer; |
| 131 | +- freedom from Puppeteer dependencies - eliminating the instability issues we've consistently observed in CDP-based implementations; |
| 132 | +- Future-proof testing infrastructure by aligning with emerging industry standards |
| 133 | + |
| 134 | +We encourage you to upgrade to the latest Testplane version and share your experience. Should you encounter any challenges, our team is ready to assist through [GitHub issue][gh-issues] - just create a ticket and we'll help resolve it promptly! |
| 135 | + |
| 136 | +[testplane@8.27.0]: https://github.com/gemini-testing/testplane/releases/tag/v8.27.0 |
| 137 | +[bidi]: https://w3c.github.io/webdriver-bidi/ |
| 138 | +[webdriver]: https://www.w3.org/TR/webdriver1/ |
| 139 | +[cdp]: https://chromedevtools.github.io/devtools-protocol/ |
| 140 | +[webvider-vs-cdp]: https://testplane.io/ru/docs/v8/reference/webdriver-vs-cdp/ |
| 141 | +[bidi-browsers-support]: https://wpt.fyi/results/webdriver/tests/bidi?label=master&label=stable&aligned |
| 142 | +[bidi-commands]: https://webdriver.io/docs/api/webdriverBidi |
| 143 | +[editors-draft]: https://www.w3.org/standards/types/#ED |
| 144 | +[ff-deprecate-cdp]: https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/ |
| 145 | +[puppeteer]: https://pptr.dev/ |
| 146 | +[gh-issues]: https://github.com/gemini-testing/testplane/issues |
0 commit comments