Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webdriverjs

Package Overview
Dependencies
Maintainers
3
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webdriverjs - npm Package Compare versions

Comparing version 0.7.6 to 0.7.8

lib/commands/endAll.js

30

index.js

@@ -20,2 +20,4 @@ /**

var oneInstance = null;
// expose the man function

@@ -31,7 +33,31 @@ // if we need a singleton, we provide the option here

singletonInstance = new WebdriverJS(options);
oneInstance = singletonInstance;
}
return singletonInstance;
} else {
return new WebdriverJS(options);
var newInstance = new WebdriverJS(options);
oneInstance = newInstance;
return newInstance;
}
};
};
exports.endAll = function(callback) {
var client = new WebdriverJS({logLevel:'silent'});
client.endAll(callback);
}
exports.sessions = function(callback) {
var client = new WebdriverJS({logLevel:'silent'});
var sessions = null;
var error = null
client.sessions(function(err, result) {
if (!err) {
sessions = result.value;
}
else {
error = err;
}
}).end(function() {
callback(error, sessions)
});
}

@@ -1,3 +0,8 @@

exports.command = function (doWhat, callback) {
exports.command = function (doWhat, sessionId, callback) {
if (typeof sessionId == "function") {
callback = sessionId;
delete sessionId;
}
var commandOptionsGet = {

@@ -13,2 +18,9 @@ path:"/session/:sessionId",

if (typeof sessionId == 'string') {
commandOptionsDelete.path = commandOptionsDelete.path.replace(":sessionId", sessionId);
commandOptionsDelete.requiresSession = false;
commandOptionsGet.path = commandOptionsGet.path.replace(":sessionId", sessionId);
commandOptionsGet.requiresSession = false;
}
if (typeof doWhat === "function") {

@@ -15,0 +27,0 @@ callback = doWhat;

11

lib/utils/RequestHandler.js

@@ -144,3 +144,8 @@ /**

if(this.sessionID === null) {
// if we dont have asession id we set it here, unless we
// call commands that dont require session ids, for
// example /sessions. The call to /sessions is not
// connected to a session itself and it therefore doesnt
// require it
if(this.sessionID === null && this.fullRequestOptions.requiresSession !== false) {
this.setSessionID(response);

@@ -172,5 +177,5 @@ }

log.result(result, data, function (err, res) {
if (!this.sessionID) {
if (!this.sessionID && this.fullRequestOptions.requiresSession !== false) {
log.error('NO SESSION, EXITING');
process.exit(1);
callback({error: true, message:"no session id"});
}

@@ -177,0 +182,0 @@

@@ -30,2 +30,4 @@ /**

options = options || {};
this.chain = true;

@@ -89,2 +91,2 @@ this.sessionId = null;

});
};
};
{
"name": "webdriverjs",
"description": "A nodejs bindings implementation for selenium 2.0/webdriver",
"version": "0.7.6",
"version": "0.7.8",
"homepage": "https://github.com/camme/webdriverjs",

@@ -6,0 +6,0 @@ "author": "camilo tapia <camilo.tapia@gmail.com>",

@@ -75,32 +75,16 @@ Webdriver/selenium 2.0 javascript bindings for nodejs [![Build Status](https://travis-ci.org/christian-bromann/webdriverjs.png)](https://travis-ci.org/christian-bromann/webdriverjs)

### Extending
If you want to extend with your own set of commands there is a method called addCommand:
## webdriverjs howto
Webdriverjs has just a few methods. Most of the methods you will use regurarly are the methods available from the client. To begin using Webdriverjs you just need to create a client. And to create a client, just do the following:
```js
var client = require("webdriverjs").remote();
var webdriverjs = require("webdriverjs"); // You load the module as usual
var client = webdriverjs.remote({}); // To create a client you just call the remote method
// create a command the returns the current url and title as one result
// just to show an example
client.addCommand("getUrlAndTitle", function(callback) {
this.url(function(err,urlResult) {
this.getTitle(function(err,titleResult) {
var specialResult = {url: urlResult.value, title: titleResult};
if (typeof callback == "function") {
callback(err,specialResult);
}
})
The remote method takes an object with the options needed to create the client. The available options are which capabilities the client should have. Here is an example:
var client = WebdriverJS.remote({
desiredCapabilities: {}, // read more below
singelton: false, // boolean, default true
logLevel: 'silent' // string, default is 'verbose' but it can also be 'silent' (read more below)
});
});
client
.init()
.url('http://www.github.com')
.getUrlAndTitle(function(err,result){
expect(err).to.be.null;
assert.strictEqual(result.url,'https://github.com/');
assert.strictEqual(result.title,'GitHub · Build software better, together.');
})
.end();
```
### Options

@@ -151,2 +135,46 @@

### webdriverjs.endAll
If you wish to end all sessions, you can call the endAll method:
require("webdriverjs").endAll(callback);
Where callback is an optional parameter. This method can be used if you run lots of tests, and you want to make sure that all sessions on your selenium server are closed when you are done. Usually its enough to close each client with its end() method, but if you, for some reason, want to make sure that no sessions are open, use endAll(). (note: this method is also available from the client returned from .remote() as well, but its the same as webdriverjs.endAll())
### webdriverjs.sessions
To get a list of all open sessions, you can call:
require("webdriverjs").sessions(callback);
which wil return an array with all sessions from selenium (note: this method is also available from the client returned from .remote() as well, but its the same as webdriverjs.sessions()).
### Extending
If you which to extend with your own set of commands there is a method called addCommand available from the client object:
```js
var client = require("webdriverjs").remote();
// create a command the returns the current url and title as one result
// just to show an example
client.addCommand("getUrlAndTitle", function(callback) {
this.url(function(err,urlResult) {
this.getTitle(function(err,titleResult) {
var specialResult = {url: urlResult.value, title: titleResult};
if (typeof callback == "function") {
callback(err,specialResult);
}
})
});
});
client
.init()
.url('http://www.github.com')
.getUrlAndTitle(function(err,result){
expect(err).to.be.null;
assert.strictEqual(result.url,'https://github.com/');
assert.strictEqual(result.title,'GitHub · Build software better, together.');
})
.end();
```
# List of current helper methods

@@ -156,35 +184,36 @@ These are the current implemented helper methods. All methods take from 0 to a couple of parameters.

- addValue(`String` css selector, `String` value, `Function` callback)<br>adds a value to an object found by a css selector
- buttonClick(`String` css selector, `Function` callback)<br>click on a button using a css selector
- call(callback)<br>call given function in async order of current command queue
- clearElement(`String` css selector, `Function` callback)<br>clear an element of text
- click(`String` css selector, `Function` callback)<br>Clicks on an element based on a css selector
- deleteCookie(`String` name, `Function` callback)<br>Delete a cookie for current page.
- doubleClick(`String` css selector, `Function` callback)<br>Clicks on an element based on a css selector
- dragAndDrop(`String` sourceCssSelector, `String` destinationCssSelector, `Function` callback)<br>Drags an item to a destination
- end(`Function` callback)<br>Ends a sessions (closes the browser)
- execute(`String` script, `Array` arguments, `Function` callback)<br>Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
- getAttribute(`String` css selector, `String` attribute name, `Function` callback)<br>Get an attribute from an dom obj based on the css selector and attribute name
- getCookie(name, `Function` callback)<br>Gets the cookie for current page.
- getCssProperty(`String` css selector, `String` css property name, `Function` callback)<br>Gets a css property from a dom object selected with a css selector
- getElementCssProperty(`String` find by, `String` finder, `String` css property name, `Function` callback)<br>Gets a css property from a dom object selected with one of the base selecting mechanisms in the webdriver protocol (class name, css selector, id, name, link text, partial link text, tag name, xpath)
- getElementSize(`String` css selector, `Function` callback)<br>Get the elements size. The element is found with a css selector
- getLocation(`String` css selector, `Function` callback)<br>Gets the x and y coordinate for an object based on the css selector
- getLocationInView(`String` css selector, `Function` callback)<br>Gets the x and y coordinate for an object based on the css selector in the view
- getSize(`String` css selector, `Function` callback)<br>Gets the width and height for an object based on the css selector
- getSource(`Function` callback)<br>Gets source code of the page
- getTagName(`String` css selector, `Function` callback)<br>Gets the tag name of a dom obj found by the css selector
- getText(`String` css selector, `Function` callback)<br>Gets the text content from a dom obj found by the css selector
- getTitle(`Function` callback)<br>Gets the title of the page
- getValue(`String` css selector, `Function` callback)<br>Gets the value of a dom obj found by css selector
- isSelected(`String` css selector, `Function` callback)<br>Return true or false if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected (found by css selector).
- isVisible(`String` css selector, `Function` callback)<br>Return true or false if the selected dom obj is visible (found by css selector)
- moveToObject(`String` css selector, `Function` callback)<br>Moves the page to the selected dom object
- pause(`Integer` milliseconds, `Function` callback)<br>Pauses the commands by the provided milliseconds
- refresh(`Function` callback)<br>Refresh the current page
- saveScreenshot(`String` path to file, `Function` callback)<br>Saves a screenshot as a png from the current state of the browser
- setCookie(`Object` cookie, `Function` callback)<br>Sets a [cookie](http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object) for current page.
- setValue(`String` css selector, `String` value, `Function` callback)<br>Sets a value to an object found by a css selector (clears value before)
- submitForm(`String` css selector, `Function` callback)<br>Submits a form found by the css selector
- waitFor(`String` css selector, `Integer` milliseconds, `Function` callback)<br>Waits for an object in the dom (selected by css selector) for the amount of milliseconds provided. the callback is called with false if the object isnt found.
- **addValue(`String` css selector, `String` value, `Function` callback)**<br>adds a value to an object found by a css selector
- **buttonClick(`String` css selector, `Function` callback)**<br>click on a button using a css selector
- **call(callback)**<br>call given function in async order of current command queue
- **clearElement(`String` css selector, `Function` callback)**<br>clear an element of text
- **click(`String` css selector, `Function` callback)**<br>Clicks on an element based on a css selector
- **deleteCookie(`String` name, `Function` callback)**<br>Delete a cookie for current page.
- **doubleClick(`String` css selector, `Function` callback)**<br>Clicks on an element based on a css selector
- **dragAndDrop(`String` sourceCssSelector, `String` destinationCssSelector, `Function` callback)**<br>Drags an item to a destination
- **end(`Function` callback)**<br>Ends a sessions (closes the browser)
- **endAll(`Function` callback)**<br>Ends all sessions (closes the browser)
- **execute(`String` script, `Array` arguments, `Function` callback)**<br>Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
- **getAttribute(`String` css selector, `String` attribute name, `Function` callback)**<br>Get an attribute from an dom obj based on the css selector and attribute name
- **getCookie(name, `Function` callback)**<br>Gets the cookie for current page.
- **getCssProperty(`String` css selector, `String` css property name, `Function` callback)**<br>Gets a css property from a dom object selected with a css selector
- **getElementCssProperty(`String` find by, `String` finder, `String` css property name, `Function` callback)**<br>Gets a css property from a dom object selected with one of the base selecting mechanisms in the webdriver protocol (class name, css selector, id, name, link text, partial link text, tag name, xpath)
- **getElementSize(`String` css selector, `Function` callback)**<br>Get the elements size. The element is found with a css selector
- **getLocation(`String` css selector, `Function` callback)**<br>Gets the x and y coordinate for an object based on the css selector
- **getLocationInView(`String` css selector, `Function` callback)**<br>Gets the x and y coordinate for an object based on the css selector in the view
- **getSize(`String` css selector, `Function` callback)**<br>Gets the width and height for an object based on the css selector
- **getSource(`Function` callback)**<br>Gets source code of the page
- **getTagName(`String` css selector, `Function` callback)**<br>Gets the tag name of a dom obj found by the css selector
- **getText(`String` css selector, `Function` callback)**<br>Gets the text content from a dom obj found by the css selector
- **getTitle(`Function` callback)**<br>Gets the title of the page
- **getValue(`String` css selector, `Function` callback)**<br>Gets the value of a dom obj found by css selector
- **isSelected(`String` css selector, `Function` callback)**<br>Return true or false if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected (found by css selector).
- **isVisible(`String` css selector, `Function` callback)**<br>Return true or false if the selected dom obj is visible (found by css selector)
- **moveToObject(`String` css selector, `Function` callback)**<br>Moves the page to the selected dom object
- **pause(`Integer` milliseconds, `Function` callback)**<br>Pauses the commands by the provided milliseconds
- **refresh(`Function` callback)**<br>Refresh the current page
- **saveScreenshot(`String` path to file, `Function` callback)**<br>Saves a screenshot as a png from the current state of the browser
- **setCookie(`Object` cookie, `Function` callback)**<br>Sets a [cookie](http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object) for current page.
- **setValue(`String` css selector, `String` value, `Function` callback)**<br>Sets a value to an object found by a css selector (clears value before)
- **submitForm(`String` css selector, `Function` callback)**<br>Submits a form found by the css selector
- **waitFor(`String` css selector, `Integer` milliseconds, `Function` callback)**<br>Waits for an object in the dom (selected by css selector) for the amount of milliseconds provided. the callback is called with false if the object isnt found.

@@ -194,2 +223,5 @@ # List of current implemented wire protocol bindings

- [alertAccept](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/accept_alert)
- [alertDismiss](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/dismiss_alert)
- [alertText](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/alert_text)
- [buttondown](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttondown)

@@ -217,2 +249,3 @@ - [buttonup](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttonup)

- [session](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId)
- [sessions](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/sessions)
- [status](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/status)

@@ -219,0 +252,0 @@ - [submit](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/submit)

@@ -10,3 +10,3 @@ /* jshint -W024 */

webdriverjs = require('../index'),
//startSelenium = require('./startSelenium'),
startSelenium = require('./startSelenium'),
testpageURL = 'http://webdriverjs.christian-bromann.com/',

@@ -393,3 +393,27 @@ testpageURL = 'http://wdjs.local/',

});
it('closeAll ends all sessions', function(done) {
var client1 = webdriverjs.remote({logLevel:'silent',desiredCapabilities:capabilities}).init();
var client2 = webdriverjs.remote({logLevel:'silent',desiredCapabilities:capabilities}).init();
client1.url(testpageURL).call(function() {
client2.url(testpageURL).call(function() {
webdriverjs.endAll(function(err) {
webdriverjs.sessions(function(err, sessions) {
should.not.exist(err);
sessions.should.have.lengthOf(0);
require("child_process").exec("ps aux | grep 'phantomjs'", function(err, result) {
result = result.replace(/grep 'phantomjs'/g, '');
result = result.replace(/grep phantomjs/g, '');
result.should.not.include('phantomjs');
done();
});
});
});
});
});
});
});

@@ -399,3 +423,5 @@

client.end();
//});
});
});
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