{ | ||
"name": "wd-bidi", | ||
"version": "0.0.4-alpha-1", | ||
"description": "", | ||
"main": "build/index.js", | ||
"version": "0.0.4-alpha-10", | ||
"description": "WebDriver BiDi API for automation testing", | ||
"main": "./build/cjs/index.js", | ||
"module": "./build/esm/index.js", | ||
"types": "./build/types/index.d.ts", | ||
"scripts": { | ||
"lint": "eslint . --ext .ts", | ||
"build": "tsc" | ||
"clean": "rimraf ./build && rimraf ./docs", | ||
"build:es": "tsc", | ||
"build:cjs": "tsc -p tsconfig.cjs.json", | ||
"build": "npm run build:es && npm run build:cjs", | ||
"lint": "eslint .", | ||
"docs": "typedoc" | ||
}, | ||
@@ -14,3 +20,14 @@ "repository": { | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"WebDriver", | ||
"Bidi", | ||
"wd-bidi", | ||
"Webdriver BiDi", | ||
"WebDriver-BiDi", | ||
"BiDi-API-for-WebDriver", | ||
"WebDriver-Bidirectional", | ||
"BiDi-Protocol-WebDriver", | ||
"BiDi-WebDriver", | ||
"BiDi-Javascript-WebDriver-API" | ||
], | ||
"author": { | ||
@@ -20,3 +37,3 @@ "name": "Sri Harsha", | ||
}, | ||
"license": "ISC", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
@@ -27,10 +44,15 @@ "url": "https://github.com/harsha509/wd-bidi/issues" | ||
"devDependencies": { | ||
"@types/node": "^18.11.17", | ||
"@types/ws": "^8.5.3", | ||
"@typescript-eslint/eslint-plugin": "^5.47.0", | ||
"@typescript-eslint/parser": "^5.47.0", | ||
"eslint": "^8.30.0", | ||
"typescript": "^4.9.4", | ||
"ws": "^8.11.0" | ||
"@eslint/js": "^9.7.0", | ||
"@types/node": "^20.14.10", | ||
"@types/ws": "^8.5.11", | ||
"@typescript-eslint/eslint-plugin": "^7.16.0", | ||
"@typescript-eslint/parser": "^7.16.0", | ||
"eslint": "^8.57.0 ", | ||
"globals": "^15.8.0", | ||
"rimraf": "^6.0.1", | ||
"typedoc": "^0.26.4", | ||
"typescript": "^5.5.3", | ||
"typescript-eslint": "^7.16.0", | ||
"ws": "^8.18.0" | ||
} | ||
} |
# wd-bidi | ||
package for implementing [webdriver BIDI](https://w3c.github.io/webdriver-bidi/). | ||
The alpha-1 has basic class to create, subscribe and listen to events. Currently, the development of this package is ongoing and the next release will include a simple API for subscribing to and listening to multiple events. This will make it easier for developers to interact with the WebDriver BIDI protocol and handle multiple events within their applications. | ||
The alpha-4 has basic class to create, subscribe and listen to events. Currently, the development of this package is ongoing and the next release will | ||
include a simple API for subscribing to and listening to multiple events. | ||
This will make it easier for developers to interact with the WebDriver BIDI | ||
protocol and handle multiple events within their applications. | ||
### [API docs](https://harsha509.github.io/wd-bidi-docs/) | ||
# Usage | ||
```shell | ||
npm i wd-bidi | ||
npm i wd-bidi@latest | ||
``` | ||
Here is the sample code on implementation. Get complete code from [github](https://github.com/harsha509/selenium_bidi_demo). | ||
### BrowsingContext: Create context and listen to event | ||
```javascript | ||
@@ -18,5 +23,5 @@ require('chromedriver'); | ||
const opts = new Chrome.Options(); | ||
const { BIDI } = require('wd-bidi'); | ||
const {BiDi, BrowsingContext } = require('wd-bidi'); | ||
describe('Sample Bidi tests', ()=> { | ||
describe('BrowserContext: Create and listen to event', ()=> { | ||
let driver; | ||
@@ -31,20 +36,71 @@ | ||
it('should listen browserContext events', async () => { | ||
const caps = await driver.getCapabilities(); | ||
let WebSocketUrl = caps['map_'].get('webSocketUrl') | ||
const conn = new BiDi(WebSocketUrl.replace('localhost', '127.0.0.1')); | ||
// Subscribe to events | ||
const browsingContext = new BrowsingContext(conn); | ||
await browsingContext.events.contextCreated(); | ||
// create a tab | ||
await browsingContext.create({type: 'tab'}) | ||
// print the subscription result | ||
console.log(await browsingContext.events.eventSubscriptionData) | ||
}) | ||
after(async ()=> await driver.quit()) | ||
}) | ||
``` | ||
## Session: Subscribe to an event | ||
```javascript | ||
require('chromedriver'); | ||
const {Builder, By} = require('selenium-webdriver'); | ||
const Chrome= require('selenium-webdriver/chrome'); | ||
const opts = new Chrome.Options(); | ||
const { Session, BiDi, Log} = require('wd-bidi'); | ||
describe('Log Events', ()=> { | ||
let driver; | ||
before(async ()=> { | ||
driver = await new Builder() | ||
.forBrowser('chrome') | ||
.setChromeOptions(opts.set('webSocketUrl', true)) | ||
.build(); | ||
}) | ||
it('should listen to log events', async () => { | ||
const caps = await driver.getCapabilities(); | ||
let WebSocketUrl = caps['map_'].get('webSocketUrl') | ||
const bidi = new BIDI(WebSocketUrl.replace('localhost', '127.0.0.1')); | ||
const conn = new BiDi(WebSocketUrl.replace('localhost', '127.0.0.1')); | ||
const log = new Log(conn); | ||
// Subscribe to log events | ||
await bidi.send({ | ||
method: 'session.subscribe', | ||
params: { events: ['log.entryAdded'] } | ||
}) | ||
await log.events.entryAdded(); | ||
// trigger an event | ||
await driver.executeScript('console.log("Hello Bidi")', []) | ||
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html'); | ||
// listen to logEvent message and print | ||
bidi.socket.on('message', (data) => { | ||
console.log(JSON.parse(Buffer.from(data.toString()))) | ||
}) | ||
//generic log | ||
await driver.findElement(By.id('consoleLog')).click(); | ||
await driver.sleep(1000); | ||
console.log(log.events.eventSubscriptionData) | ||
// console error | ||
await driver.findElement(By.id('consoleError')).click(); | ||
await driver.sleep(1000); | ||
console.log(log.events.eventSubscriptionData) | ||
//js exception | ||
await driver.findElement(By.id('jsException')).click(); | ||
await driver.sleep(1000); | ||
console.log(log.events.eventSubscriptionData) | ||
// log with stacktrace | ||
await driver.findElement(By.id('logWithStacktrace')).click(); | ||
await driver.sleep(1000); | ||
console.log(log.events.eventSubscriptionData); | ||
}) | ||
@@ -56,4 +112,2 @@ | ||
___NOTE___: THIS IS NOT AN OFFICIAL PACKAGE from Webdriver BIDI community! | ||
{ | ||
"compilerOptions": { | ||
/* Language and Environment */ | ||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
"lib": ["es6"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||
/* Modules */ | ||
"module": "commonjs", /* Specify what module code is generated. */ | ||
"rootDir": ".", /* Specify the root folder within your source files. */ | ||
"resolveJsonModule": true, /* Enable importing .json files. */ | ||
/* JavaScript Support */ | ||
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ | ||
"outDir": "build", /* Specify an output folder for all emitted files. */ | ||
/* Interop Constraints */ | ||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ | ||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ | ||
/* Type Checking */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ | ||
/* Completeness */ | ||
"skipLibCheck": true, /* Skip type checking all .d.ts files. */ | ||
"declaration": true | ||
} | ||
} | ||
"target": "es2016", | ||
"lib": ["es6"], | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"rootDir": "src", | ||
"allowJs": true, | ||
"outDir": "./build/esm", | ||
"declaration": true, | ||
"declarationDir": "./build/types", | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": false, | ||
"noUnusedParameters": false, | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": ["node_modules"] | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
128955
673.67%99
482.35%0
-100%2991
814.68%111
94.74%12
71.43%1
Infinity%