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

webdriverjs

Package Overview
Dependencies
Maintainers
4
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 1.1.1 to 1.2.0

lib/commands/drag.js

17

lib/commands/buttonClick.js
// Deprecated but included for backward compatibility. Alias for 'click' command.
module.exports = function buttonClick () {
return this.click.apply(this, arguments);
}
var isMobile = require('../helpers/isMobile')(this.desiredCapabilities);
if(!isMobile) {
return this.click.apply(this, arguments);
} else {
// TODO replace tap command with touchMove/touchDown/touchUp command chain
// (if implemented in appium)
return this.tap.apply(this, arguments);
}
};

41

lib/commands/click.js
var clickHelper = require('../helpers/click');
module.exports = function click (cssSelector, callback) {
var self = this;
module.exports = function click (selector, callback) {
this.element(cssSelector, function(err,result) {
var isMobile = require('../helpers/isMobile')(this.desiredCapabilities);
if(!isMobile) {
if(err === null && result.value) {
this.element(selector, function(err,result) {
self.elementIdClick(result.value.ELEMENT, function(err,result) {
if(err === null && result.value) {
if(err && err.status === 13 && result && result.value && result.value.message && result.value.message.indexOf('Element is not clickable at point') !== -1) {
this.elementIdClick(result.value.ELEMENT, function(err,result) {
// if an element can't be clicked, execute the helper function
self.execute(clickHelper(cssSelector),[],callback);
if(err && err.status === 13 && result && result.value && result.value.message && result.value.message.indexOf('Element is not clickable at point') !== -1) {
} else {
callback(err,result);
}
});
// if an element can't be clicked, execute the helper function
this.execute(clickHelper(selector),[],callback);
} else {
} else {
callback(err,result);
}
});
callback(err,result);
} else {
}
});
callback(err,result);
}
});
} else {
this.tap(selector,callback);
}
};
module.exports = function dragAndDrop (cssSelectorItem, cssSelectorDropDestination, callback) {
this
.moveToObject(cssSelectorItem)
.buttonDown()
.moveToObject(cssSelectorDropDestination)
.buttonUp(callback);
var isMobile = require('../helpers/isMobile')(this.desiredCapabilities);
if(!isMobile) {
this.moveToObject(cssSelectorItem)
.buttonDown()
.moveToObject(cssSelectorDropDestination)
.buttonUp(callback);
} else {
this.getLocation(cssSelectorItem,function(err,res) {
if(err === null && res) {
this.touchDown(res.x,res.y)
.getLocation(cssSelectorDropDestination,function(err,res) {
if(err === null && res) {
this.touchMove(res.x,res.y)
.touchUp(res.x,res.y,callback);
} else {
callback(err,res);
}
});
} else {
callback(err,res);
}
});
}
};
module.exports = function moveToObject (cssSelector, callback) {
var self = this;
var isMobile = require('../helpers/isMobile')(this.desiredCapabilities);

@@ -8,4 +8,24 @@ this.element(cssSelector,function(err,result) {

self.moveTo(result.value.ELEMENT,callback);
if(!isMobile) {
this.moveTo(result.value.ELEMENT,callback);
} else {
this.elementIdLocation(result.value.ELEMENT, function(err,res) {
if(err !== null && res) {
this.touchMove(result.value.x,result.value.y,callback);
} else {
callback(err,res);
}
});
}
} else {

@@ -12,0 +32,0 @@

@@ -1,2 +0,2 @@

/**
/**
* RequestHandler

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

var RequestHandler = module.exports = function(options) {
module.exports = function(options) {

@@ -49,4 +49,4 @@ 'use strict';

this.defaultHeaders['Authorization'] = 'Basic ' + new Buffer(options.auth).toString('base64');
this.defaultHeaders['Credentials'] = options.auth;
this.defaultHeaders.Authorization = 'Basic ' + new Buffer(options.auth).toString('base64');
this.defaultHeaders.Credentials = options.auth;

@@ -86,3 +86,3 @@ delete options.user;

// we need to set the requests content-length. either from the data that is sent or 0 if nothing is sent
if (data !== "") {
if (data !== '') {
this.fullRequestOptions.headers['Content-Length'] = Buffer.byteLength(JSON.stringify(data));

@@ -97,3 +97,3 @@ } else {

request.on("error", function(err) {
request.on('error', function(err) {
log.error(err);

@@ -124,22 +124,43 @@

// parse data to get the sessionID
try {
this.sessionID = data !== '' ? JSON.parse(data).sessionId : null;
data = JSON.parse(data);
} catch(e) {
console.log('\n');
log.error(typeof data === 'string' ? data : 'Couldn\'t connect to remote server', true);
log.log('Exiting process with 1', null, true);
process.exit(1);
return;
// if data isn't a vaild JSON we can assume that something went wrong
// (e.g. wrong platform/browser combination in tests on cloud services like Sauce Labs)
// in this cases data is typeof string and contains an error message
data = {
message: data
};
}
if(!this.sessionID) try {
var locationList = response.headers.location.split("/");
var sessionId = locationList[locationList.length - 1];
this.sessionID = sessionId;
} catch(err) {
console.log('\n');
log.error('COULDNT GET A SESSION ID', true);
log.log('Exiting process with 1', null, true);
process.exit(1);
return;
this.sessionID = data.sessionId;
// check if we got a session id
if(!this.sessionID) {
// if not, data didn't contain this information, last change is
// trying to get the ID in the old fashioned way via header.location
try {
var locationList = response.headers.location.split('/');
var sessionId = locationList[locationList.length - 1];
this.sessionID = sessionId;
} catch(err) {
// if that wasn't successful output an error message and
// exit process with 1
console.log('\n');
log.error('COULDNT GET A SESSION ID', true);
if(typeof data.message === 'string') {
log.error(data.message,true);
} else if(data.value) {
log.error(data.value.message,true);
log.error(data.value.origValue,true);
}
log.log('Exiting process with 1', null, true);
process.exit(1);
return;
}
}

@@ -164,3 +185,3 @@

if (newOptions.path && newOptions.path !== "") {
if (newOptions.path && newOptions.path !== '') {
path += newOptions.path;

@@ -243,3 +264,3 @@ }

log.error('NO SESSION, EXITING');
callback({error: true, message:"no session id"});
callback({error: true, message: 'no session id'});
}

@@ -246,0 +267,0 @@

@@ -20,3 +20,3 @@ var buildPrototype = require('./utils/buildPrototype.js');

options = merge({
this.options = merge({
host: '127.0.0.1',

@@ -35,13 +35,13 @@ port: 4444

if (options && options.username && options.accessKey) {
this._authString = options.username+":"+options.accessKey;
if (this.options && this.options.username && this.options.accessKey) {
this._authString = this.options.username+":"+this.options.accessKey;
}
this.requestHandler = new RequestHandler(options);
this.requestHandler = new RequestHandler(this.options);
this.log = log({
logLevel: options.logLevel || 'silent',
screenshotPath: options.screenshotPath
logLevel: this.options.logLevel || 'silent',
screenshotPath: this.options.screenshotPath
});
};
}

@@ -58,3 +58,3 @@ // use the chained API reference to add static methods

}
}
};

@@ -68,2 +68,2 @@ // addCommand added here because it's synchronous and thus does not need

return this;
}
};
{
"name": "webdriverjs",
"description": "A nodejs bindings implementation for selenium 2.0/webdriver",
"version": "1.1.1",
"version": "1.2.0",
"homepage": "https://github.com/camme/webdriverjs",

@@ -30,3 +30,4 @@ "author": "camilo tapia <camilo.tapia@gmail.com>",

"scripts": {
"test": "mocha",
"pretest": "cd test/site/www && ../../../node_modules/.bin/bower install",
"test": "node test/runner.js",
"prepublish": "npm prune"

@@ -37,4 +38,7 @@ },

"chai": "~1.8.1",
"request": "~2.30.0",
"jshint": "~2.4.1"
"request": "~2.31.0",
"jshint": "~2.4.1",
"saucelabs": "~0.1.1",
"glob": "~3.2.7",
"bower": "~1.2.8"
},

@@ -41,0 +45,0 @@ "tags": [

@@ -186,6 +186,12 @@ Webdriver/selenium 2.0 javascript bindings for nodejs [![Build Status](https://travis-ci.org/camme/webdriverjs.png?branch=master)](https://travis-ci.org/camme/webdriverjs) [![Dependency Status](https://gemnasium.com/camme/webdriverjs.png)](https://gemnasium.com/camme/webdriverjs)

- **doubleClick(`String` selector, `Function` callback)**<br>Clicks on an element based on a selector
- **drag(`String` selector, `Number` startX, `Number` startY, `Number` endX, `Number` endY, `Number` touchCount, `Number` duration, `Function` callback)**<br>Perform a drag on the screen or an element (works only on [Appium](https://github.com/appium/appium/blob/master/docs/gestures.md))
- **dragAndDrop(`String` sourceCssSelector, `String` destinationCssSelector, `Function` callback)**<br>Drags an item to a destination
- **dragDown(`String` selector, `Number` touchCount, `Number` duration, `Function` callback)**<br>Perform a drag down on an element (works only on [Appium](https://github.com/appium/appium/blob/master/docs/gestures.md))
- **dragLeft(`String` selector, `Number` touchCount, `Number` duration, `Function` callback)**<br>Perform a drag left on an element (works only on [Appium](https://github.com/appium/appium/blob/master/docs/gestures.md))
- **dragRight(`String` selector, `Number` touchCount, `Number` duration, `Function` callback)**<br>Perform a drag right on an element (works only on [Appium](https://github.com/appium/appium/blob/master/docs/gestures.md))
- **dragUp(`String` selector, `Number` touchCount, `Number` duration, `Function` callback)**<br>Perform a drag up on an element (works only on [Appium](https://github.com/appium/appium/blob/master/docs/gestures.md))
- **end(`Function` callback)**<br>Ends a sessions (closes the browser)
- **endAll(`Function` callback)**<br>Ends all sessions (closes the browser)
- **execute(`String` or `Function` script, `Array` arguments, `Function` callback)**<br>Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. If script is a `Function`, arguments is required.
- **flick(`String` selector, `Number` startX, `Number` startY, `Number` endX, `Number` endY, `Number` touchCount, `Function` callback)**<br>Perform a flick on the screen or an element (works only on [Appium](https://github.com/appium/appium/blob/master/docs/gestures.md))
- **getAttribute(`String` selector, `String` attribute name, `Function` callback)**<br>Get an attribute from an dom obj based on the selector and attribute name

@@ -198,2 +204,3 @@ - **getCookie(`String` name, `Function` callback)**<br>Gets the cookie for current page.

- **getLocationInView(`String` selector, `Function` callback)**<br>Gets the x and y coordinate for an object based on the selector in the view
- **getOrientation(`Function` callback)**<br>Get the current browser orientation.
- **getSource(`Function` callback)**<br>Gets source code of the page

@@ -208,2 +215,3 @@ - **getTabIds(`Function` callback)**<br>Retrieve the list of all window handles available to the session.

- **leftClick(`String` selector, `Function` callback)**<br>Apply left click at an element. If selector is not provided, click at the last moved-to location.
- **hold(`String` selector,`Function` callback)**<br>Long press on an element using finger motion events.
- **middleClick(`String` selector, `Function` callback)**<br>Apply middle click at an element. If selector is not provided, click at the last moved-to location.

@@ -214,8 +222,13 @@ - **moveToObject(`String` selector, `Function` callback)**<br>Moves the page to the selected dom object

- **refresh(`Function` callback)**<br>Refresh the current page
- **release(`String` selector, `Function` callback)**<br>Finger up on an element.
- **rightClick(`String` selector, `Function` callback)**<br>Apply right click at an element. If selector is not provided, click at the last moved-to location.
- **saveScreenshot(`String` path to file, `Function` callback)**<br>Saves a screenshot as a png from the current state of the browser
- **scroll(`String` selector, `Function`callback)**<br>Scroll to a specific element. You can also pass two offset values as parameter to scroll to a specific position (e.g. `scroll(xoffset,yoffset,callback)`).
- **setCookie(`Object` cookie, `Function` callback)**<br>Sets a [cookie](http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object) for current page.
- **setOrientation(`String` orientation, `Function` callback)**<br>Set the current browser orientation.
- **setValue(`String` selector, `String|String[]` value, `Function` callback)**<br>Sets a value to an object found by a selector (clears value before). You can also use unicode characters like `Left arrow` or `Back space`. You'll find all supported characters [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value). To do that, the value has to correspond to a key from the table.
- **submitForm(`String` selector, `Function` callback)**<br>Submits a form found by the selector
- **switchTab(`String` tab ID)**<br>switch focus to a particular tab/window
- **tap(`String` selector,`Number` x,`Number` y,`Number` tapCount,`Number` touchCount,`Number` duration,`Function` callback)**<br>Perform a tap on the screen or an element (works only on [Appium](https://github.com/appium/appium/blob/master/docs/gestures.md))
- **touch(`String` selector, `Function` callback)**<br>Finger down on an element.
- **waitFor(`String` selector, `Integer` milliseconds, `Function` callback)**<br>Waits for an object in the dom (selected by selector) for the amount of milliseconds provided. the callback is called with false if the object isnt found.

@@ -257,2 +270,3 @@

- [keys](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/keys)
- [orientation](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/orientation)
- [moveto](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/moveto)

@@ -268,2 +282,13 @@ - [refresh](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/refresh)

- [title](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/title)
- [touchClick](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/click)
- [touchDoubleClick](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/doubleclick)
- [touchDown](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/down)
- [touchFlick](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/flick)
- [touchFlickPrecise](https://github.com/appium/appium/blob/master/docs/gestures.md)
- [touchLongClick](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/longclick)
- [touchMove](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/move)
- [touchScroll](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/scroll)
- [touchSwipe](https://github.com/appium/appium/blob/master/docs/gestures.md)
- [touchTap](https://github.com/appium/appium/blob/master/docs/gestures.md)
- [touchUp](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/touch/up)
- [url](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/url)

@@ -270,0 +295,0 @@ - [window](http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/window)

@@ -8,2 +8,7 @@ var merge = require('lodash.merge');

if(process.env._ENV === 'mobile') {
var mobile = require('./mobile');
asked = merge(asked,mobile);
}
module.exports = merge(defaults, asked);
module.exports = {
testPage: {
url: 'http://127.0.0.1:8080/test/site/index.html',
url2: 'http://127.0.0.1:8080/test/site/two.html',
start: 'http://127.0.0.1:8080/test/site/www/index.html',
subPage: 'http://127.0.0.1:8080/test/site/www/two.html'
},

@@ -6,0 +6,0 @@ host: 'localhost',

module.exports = {
"testPage": {
"url": 'http://127.0.0.1:8080/test/site/index.html',
"url2": 'http://127.0.0.1:8080/test/site/two.html',
testPage: {
start: 'http://127.0.0.1:8080/test/site/www/index.html',
subPage: 'http://127.0.0.1:8080/test/site/www/two.html',
gestureTest: 'http://127.0.0.1:8080/test/site/www/gestureTest.html'
},
"host": "ondemand.saucelabs.com",
"port": 80,
"logLevel": "silent",
"desiredCapabilities" : {
"browserName": process.env._BROWSER.replace(/_/g,' '),
"platform": process.env._PLATFORM.replace(/_/g,' '),
"version": process.env._VERSION,
"device-orientation": process.env._DEVICEORIENTATION || "",
"device-type": process.env._DEVICETYPE || "",
"tunnel-identifier": process.env.TRAVIS_JOB_NUMBER,
"tags": ["webdriverjs","api","test"],
"name": "webdriverjs API test",
"build": process.env.TRAVIS_BUILD_NUMBER,
"username": process.env.SAUCE_USERNAME,
"accessKey": process.env.SAUCE_ACCESS_KEY
host: 'ondemand.saucelabs.com',
port: 80,
logLevel: 'command',
desiredCapabilities : {
browserName: (process.env._BROWSER || '').replace(/_/g,' '),
platform: (process.env._PLATFORM || '').replace(/_/g,' '),
version: process.env._VERSION,
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
'idle-timeout': 900,
tags: ['webdriverjs','api','test'],
name: 'webdriverjs API test',
build: process.env.TRAVIS_BUILD_NUMBER,
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY
}
};

@@ -17,6 +17,6 @@ describe('addCommand', function () {

this.getTitle(function(err, title) {
callback(err, title === expectedTitle)
callback(err, title === expectedTitle);
});
})
})
});
});

@@ -26,4 +26,4 @@ it('added a `getUrlAndTitle` command',function(done) {

.getUrlAndTitle(function(err,result){
assert.equal(null, err)
assert.strictEqual(result.url, conf.testPage.url);
assert.equal(null, err);
assert.strictEqual(result.url, conf.testPage.start);
assert.strictEqual(result.title, conf.testPage.title);

@@ -34,4 +34,4 @@ })

})
.call(done)
.call(done);
});
});

@@ -35,3 +35,3 @@ describe('Promises', function() {

client.doubleClick('.btn1', function(err) {
client.click('.btn1', function(err) {
assert.equal(null, err);

@@ -87,2 +87,2 @@ result += '8';

});
})
});

@@ -1,2 +0,2 @@

describe('singleton option', function() {
describe.skip('singleton option', function() {
var c1;

@@ -6,3 +6,3 @@ var c2;

before(function() {
before(function(done) {
var webdriverjs = require('../../index.js');

@@ -18,2 +18,4 @@ var merge = require('lodash.merge');

}));
c1.init().url(conf.testPage.subPage, done);
});

@@ -25,24 +27,16 @@

describe('when browsing on one reference', function() {
before(function(done) {
c1
.init()
.url(conf.testPage.url2, done);
});
it('browses on the other reference', function(done) {
c2
.url(function(err, res) {
assert.equal(res.value, conf.testPage.subPage);
})
.getTitle(function(err, title) {
assert.equal(title, 'two');
done(err);
});
});
it('browses on the other reference', function(done) {
c2
.url(function(err, res) {
assert.equal(res.value, conf.testPage.url2);
})
.getTitle(function(err, title) {
assert.equal(title, 'two');
done(err);
});
});
it('should end other reference probably', function(done) {
c1.end(done);
});
it('should end other reference probably', function(done) {
c1.end(done);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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