Socket
Socket
Sign inDemoInstall

wd

Package Overview
Dependencies
Maintainers
1
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wd - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

.gitignore

165

lib/main.js

@@ -38,2 +38,6 @@ var http = require("http")

this.sessionID = null;
this.username = username;
this.accessKey = accessKey;
// default
this.options = {

@@ -43,8 +47,4 @@ host: host || '127.0.0.1'

, path: '/wd/hub/session'
, method: 'POST'
, headers: {
'Connection': 'keep-alive'
}
};
this.desiredCapabilities = {
};
this.defaultCapabilities = {
browserName: "firefox"

@@ -55,13 +55,38 @@ , version: ""

}
// saucelabs default
if ((username != null) && (accessKey != null)) {
this.defaultCapabilities.platform = "VISTA";
}
if (username && accessKey) {
var authString = username+":"+accessKey;
var buf = new Buffer(authString);
this.options['headers'] = {
'Authorization': 'Basic '+ buf.toString('base64')
this._applyHttpOpts = function(opt, over) {
opt.method = over.method || 'POST';
opt.headers = opt.headers || {}
opt.headers['Connection'] = 'keep-alive';
if (opt.method === 'POST' || opt.method === 'GET')
opt.headers['Accept'] = 'application/json';
if( opt.method == 'POST' )
opt.headers['Content-Type'] = 'application/json';
return opt;
}
// for init method only
this._getInitOpts = function() {
var opt = new Object();
for (var o in this.options) {
opt[o] = this.options[o];
}
this.desiredCapabilities.platform = "VISTA";
if ((this.username != null) && (this.accessKey != null)) {
var authString = this.username + ":" + this.accessKey;
var buf = new Buffer(authString);
opt['headers'] = {
'Authorization': 'Basic '+ buf.toString('base64')
}
}
this._applyHttpOpts(opt, {})
return opt;
}
this.getOpts = function(over) {
// for all methods except init
this._getOpts = function(over) {
var opt = new Object();

@@ -71,13 +96,9 @@ for (var o in this.options) {

}
opt['path'] += '/'+this.sessionID;
if(this.sessionID != null)
opt['path'] += '/'+this.sessionID;
if (over.url) {
opt['path'] += over.url;
}
if (over.method) {
opt['method'] = over.method;
}
this._applyHttpOpts(opt, over)
this.emit('command', opt['method'], over.url || '--');
opt['headers'] = { 'Accept': 'application/json' };
if( opt['method'] == 'POST' )
opt['headers']['Content-Type'] = 'application/json';
return opt;

@@ -94,3 +115,4 @@ }

var opts = {method: "GET"};
var options = _this.getOpts(opts);
debugger
var options = _this._getOpts(opts);
options['path'] = '/wd/hub/status';

@@ -106,26 +128,21 @@

var _this = this;
//allow desired ovveride to be left out
if (typeof desired == "function") {
cb = desired;
desired = null;
desired = {};
}
// making copy
var _desired = {};
for (var k in desired) {
_desired[k] = desired[k];
}
if (desired && desired.browserName) {
this.desiredCapabilities.browserName = desired.browserName;
// defaulting capabilities when necessary
for (var k in this.defaultCapabilities) {
_desired[k] = _desired[k] || this.defaultCapabilities[k];
}
if (desired && desired.version) {
this.desiredCapabilities.version = desired.version;
}
if (desired && desired.javascriptEnabled) {
this.desiredCapabilities.javascriptEnabled = desired.javascriptEnabled;
}
if (desired && desired.platform) {
this.desiredCapabilities.platform = desired.platform;
}
if (desired && desired.name) {
this.desiredCapabilities.name = desired.name;
}
var req = http.request(_this.options, function(res) {
var req = http.request(_this._getInitOpts(), function(res) {
var data = '';

@@ -154,3 +171,3 @@ res.on('data', function(chunk) {

req.on('error', function(e) { cb(e); });
req.write(JSON.stringify({desiredCapabilities: _this.desiredCapabilities}));
req.write(JSON.stringify({desiredCapabilities: _desired}));
req.end();

@@ -162,3 +179,3 @@ };

var opts = {url: '', method: "GET"};
var options = _this.getOpts(opts);
var options = _this._getOpts(opts);

@@ -176,3 +193,3 @@ var req = http.request(options, callbackWithData(cb, 'value'));

var opts = {method: "GET"};
var options = _this.getOpts(opts);
var options = _this._getOpts(opts);
options['path'] = '/wd/hub/sessions';

@@ -212,3 +229,3 @@

var req = http.request(
_this.getOpts(
_this._getOpts(
{url:'/window', method:'DELETE'}

@@ -227,3 +244,3 @@ ), function(res) {

var req = http.request(
_this.getOpts(
_this._getOpts(
{method:'DELETE'}

@@ -246,3 +263,3 @@ ), function(res) {

var req = http.request(
_this.getOpts({url:'/execute'})
_this._getOpts({url:'/execute'})
, callbackWithData(cb, 'value'));

@@ -259,3 +276,3 @@

var req = http.request(
_this.getOpts({url:'/execute'})
_this._getOpts({url:'/execute'})
, callbackWithData(cb, 'value'));

@@ -272,3 +289,3 @@

var req = http.request(
_this.getOpts({url:'/execute_async'})
_this._getOpts({url:'/execute_async'})
, callbackWithData(cb, 'value'));

@@ -285,3 +302,3 @@

var req = http.request(
_this.getOpts({url:'/url'}), function(res) {
_this._getOpts({url:'/url'}), function(res) {
if (cb){ cb(); }

@@ -298,3 +315,3 @@ });

var req = http.request(
_this.getOpts({url: '/refresh'}),
_this._getOpts({url: '/refresh'}),
function(res) {

@@ -313,3 +330,3 @@ if (cb){ cb(); }

var req = http.request(
_this.getOpts({url:'/timeouts/implicit_wait'}), function(res) {
_this._getOpts({url:'/timeouts/implicit_wait'}), function(res) {
if (cb){ cb(); }

@@ -330,3 +347,3 @@ });

var req = http.request(
_this.getOpts({url:'/timeouts/async_script'}), function(res) {
_this._getOpts({url:'/timeouts/async_script'}), function(res) {
if (cb){ cb(); }

@@ -344,3 +361,3 @@ });

var req = http.request(
_this.getOpts({url:'/timeouts/timeouts'}), function(res) {
_this._getOpts({url:'/timeouts/timeouts'}), function(res) {
if (cb){ cb(); }

@@ -359,3 +376,3 @@ });

var req = http.request(
_this.getOpts({url:'/element'}), function(res) {
_this._getOpts({url:'/element'}), function(res) {
res.setEncoding('utf8');

@@ -411,3 +428,3 @@

};
var req = http.request(_this.getOpts(opts), callbackWithData(cb, 'value'));
var req = http.request(_this._getOpts(opts), callbackWithData(cb, 'value'));
req.on('error', function(e) { cb(e); });

@@ -426,3 +443,3 @@ req.write('');

var req = http.request(
_this.getOpts({url: '/element/' + element + '/click'}),
_this._getOpts({url: '/element/' + element + '/click'}),
function(res) {

@@ -443,3 +460,3 @@ if (cb) { cb(); }

var req = http.request(
_this.getOpts({url:'/moveto'}), function(res) {
_this._getOpts({url:'/moveto'}), function(res) {
if (cb){ cb(); }

@@ -462,3 +479,3 @@ });

var req = http.request(
_this.getOpts({url:'/moveto'}), function(res) {
_this._getOpts({url:'/moveto'}), function(res) {
if (cb){ cb(); }

@@ -480,3 +497,3 @@ });

var req = http.request(
_this.getOpts({url:'/buttondown'}), function(res) {
_this._getOpts({url:'/buttondown'}), function(res) {
if (cb){ cb(); }

@@ -495,3 +512,3 @@ });

var req = http.request(
_this.getOpts({url:'/buttonup'}), function(res) {
_this._getOpts({url:'/buttonup'}), function(res) {
if (cb){ cb(); }

@@ -510,3 +527,3 @@ });

var req = http.request(
_this.getOpts({url:'/click'}), function(res) {
_this._getOpts({url:'/click'}), function(res) {
if (cb){ cb(); }

@@ -526,3 +543,3 @@ });

var req = http.request(
_this.getOpts({url:'/doubleclick'}), function(res) {
_this._getOpts({url:'/doubleclick'}), function(res) {
if (cb){ cb(); }

@@ -544,3 +561,3 @@ });

var req = http.request(
_this.getOpts({url:'/element/' + element + '/value'}), function(res) {
_this._getOpts({url:'/element/' + element + '/value'}), function(res) {
if (cb){ cb(); }

@@ -559,3 +576,3 @@ });

var req = http.request(
_this.getOpts({url: '/element/' + element + '/clear'}),
_this._getOpts({url: '/element/' + element + '/clear'}),
function(res) {

@@ -573,3 +590,3 @@ cb();

var opts = {url:'/title', method: "GET"};
var req = http.request(_this.getOpts(opts), callbackWithData(cb, 'value'));
var req = http.request(_this._getOpts(opts), callbackWithData(cb, 'value'));
req.on('error', function(e) { cb(e); });

@@ -584,3 +601,3 @@ req.write('');

var doTextReq = function(el) {
var url = _this.getOpts({
var url = _this._getOpts({
url: '/element/' + el + '/text',

@@ -612,3 +629,3 @@ method: "GET"

var req = http.request(
_this.getOpts({url:'/accept_alert'}), function(res) {
_this._getOpts({url:'/accept_alert'}), function(res) {
if (cb){ cb(); }

@@ -626,3 +643,3 @@ });

var req = http.request(
_this.getOpts({url:'/dismiss_alert'}), function(res) {
_this._getOpts({url:'/dismiss_alert'}), function(res) {
if (cb){ cb(); }

@@ -638,3 +655,3 @@ });

var req = http.request(
this.getOpts({url:'/element/active'}), callbackWithData(function(e, o){
this._getOpts({url:'/element/active'}), callbackWithData(function(e, o){
cb(null, o['ELEMENT'])

@@ -648,3 +665,3 @@ }, 'value'));

var _this = this;
var url = _this.getOpts({url:'/url', method: "GET"});
var url = _this._getOpts({url:'/url', method: "GET"});
var req = http.request(url, callbackWithData(cb, 'value'));

@@ -658,3 +675,3 @@ req.on('error', function(e) { cb(e); });

var _this = this;
var url = _this.getOpts({url:'/cookie', method: "GET"});
var url = _this._getOpts({url:'/cookie', method: "GET"});
var req = http.request(url, callbackWithData(cb, 'value'));

@@ -680,3 +697,3 @@ req.on('error', function(e) { cb(e); });

var _this = this;
var url = _this.getOpts({url: '/cookie', method: 'POST'});
var url = _this._getOpts({url: '/cookie', method: 'POST'});
var body = { cookie: cookie };

@@ -696,3 +713,3 @@ var req = http.request(url, function() {

var req = http.request(
_this.getOpts(
_this._getOpts(
{url:'/cookie', method:'DELETE'}

@@ -711,3 +728,3 @@ ), function(res) {

var req = http.request(
_this.getOpts(
_this._getOpts(
{url:'/cookie/' + encodeURIComponent(name) , method:'DELETE'}

@@ -714,0 +731,0 @@ ), function(res) {

@@ -1,16 +0,24 @@

{ "name" : "wd"
, "description" : "WebDriver/Selenium 2 node.js client"
, "tags" : ["web", "automation", "browser", "javascript"]
, "version" : "0.0.12"
, "author" : "Adam Christian <adam.christian@gmail.com>"
, "repository" :
{ "type" : "git"
, "url" : "https://github.com/admc/wd.git"
{
"name" : "wd"
, "description" : "WebDriver/Selenium 2 node.js client"
, "tags" : ["web", "automation", "browser", "javascript"]
, "version" : "0.0.13"
, "author" : "Adam Christian <adam.christian@gmail.com>"
, "repository" :
{ "type" : "git"
, "url" : "https://github.com/admc/wd.git"
}
, "bugs" :
{ "url" : "https://github.com/admc/wd/issues" }
, "engines" : ["node"]
, "main" : "./lib/main"
, "bin" : { "wd" : "./lib/bin.js" }
, "directories" : { "lib" : "./lib" }
, "devDependencies" : {
"nodeunit" : "latest"
,"should": "latest"
,"coffee-script": "latest"
,"express": "latest"
,"async": "latest"
}
, "bugs" :
{ "url" : "https://github.com/admc/wd/issues" }
, "engines" : ["node"]
, "main" : "./lib/main"
, "bin" : { "wd" : "./lib/bin.js" }
, "directories" : { "lib" : "./lib" }
}

@@ -31,4 +31,4 @@ # WD.js -- A light weight WebDriver/Se2 client for node.js

//Adding additional desired capabilities
x.desiredCapabilities.public = true;
x.desiredCapabilities.tags = ["one", "boom"];
x.defaultCapabilities.public = true;
x.defaultCapabilities.tags = ["one", "boom"];

@@ -45,21 +45,30 @@ > x.init() or x.init({desired capabilities ovveride})

<pre>
var webdriver = require("wd")
var webdriver = require('wd')
, assert = require('assert');
//get a new intsance
var browser = webdriver.remote();
//instantiate the session
browser.init({browserName:"chrome"}, function() {
//goto url
browser.get("http://www.jelly.io", function() {
//exec js
browser.eval("window.location.href", function(a, o) {
//print the js output
console.log(o);
//goto another url
browser.get("http://www.seleniumhq.org", function() {
//kill the session and browser
browser.quit(function() {
//kill the session
console.log("DONE!");
browser.on('status', function(info){
console.log('\x1b[36m%s\x1b[0m', info);
});
browser.on('command', function(meth, path){
console.log(' > \x1b[33m%s\x1b[0m: %s', meth, path);
});
desired = {
browserName:'chrome'
, tags: ["examples"]
, name = "This is an example test"
}
browser.init(desired, function() {
browser.get("http://saucelabs.com/test/guinea-pig", function() {
browser.title(function(err, title) {
assert.ok(~title.indexOf('I am a page title - Sauce Labs'), 'Wrong title!');
browser.elementById('submit', function(err, el) {
browser.clickElement(el, function() {
browser.eval("window.location.href", function(err, title) {
assert.ok(~title.indexOf('#'), 'Wrong title!');
browser.quit()
})
})

@@ -70,3 +79,2 @@ })

})
</pre>

@@ -102,1 +110,10 @@

</pre>
## Run the tests!
<pre>
- Run the selenium server: java -jar selenium-server.jar
- cd wd
- npm install .
- make
- look at the results!
</pre>
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