New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wd-bidi

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wd-bidi - npm Package Compare versions

Comparing version 0.0.4-alpha-5 to 0.0.4-alpha-6

2

package.json
{
"name": "wd-bidi",
"version": "0.0.4-alpha-5",
"version": "0.0.4-alpha-6",
"description": "",

@@ -5,0 +5,0 @@ "main": "./build/cjs/index.js",

@@ -9,11 +9,11 @@ # wd-bidi

### [API docs](./docs/index.html)
### [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

@@ -24,5 +24,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;

@@ -37,12 +37,51 @@

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} = require('selenium-webdriver');
const Chrome= require('selenium-webdriver/chrome');
const opts = new Chrome.Options();
const { BiDi, Session} = require('wd-bidi');
describe('Session: Log entry added', ()=> {
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'));
// Subscribe to log events
await bidi.send({
method: 'session.subscribe',
params: { events: ['log.entryAdded'] }
})
let subEvent= { events: ['log.entryAdded'] }
const session = new Session(conn);
await session.subscribe(subEvent)

@@ -53,12 +92,11 @@ // trigger an event

// listen to logEvent message and print
bidi.socket.on('message', (data) => {
conn.getConnection.on('message', (data) => {
console.log(JSON.parse(Buffer.from(data.toString())))
})
})
after(async ()=> await driver.quit())
})
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc