Socket
Socket
Sign inDemoInstall

wd

Package Overview
Dependencies
Maintainers
4
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.2.2 to 0.2.3

doc/api.md

243

doc/jsonwire-full-mapping.md

@@ -5,6 +5,6 @@ <table class="wikitable">

<td width="50%" style="border: 1px solid #ccc; padding: 5px;">
<strong>JsonWireProtocol</strong>
<strong>category / JsonWireProtocol method</strong>
</td>
<td width="50%" style="border: 1px solid #ccc; padding: 5px;">
<strong>wd</strong>
<strong>wd methods</strong>
</td>

@@ -1165,5 +1165,15 @@ </tr>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
Retrieves the current session id.<br>
getSessionId(cb) -&gt; cb(err, sessionId)<br>
getSessionId()<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
Opens a new window (using Javascript window.open):<br>

@@ -1179,3 +1189,3 @@ newWindow(url, name, cb) -&gt; cb(err)<br>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>

@@ -1188,7 +1198,9 @@ <td style="border: 1px solid #ccc; padding: 5px;">

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
setHTTPInactivityTimeout(ms)<br>
ms: how many milliseconds to wait for any communication with the WebDriver server (i.e. any command to complete) before the connection is considered lost<br>
configureHttp(opts)<br>
opts example:<br>
{timeout:60000, retries: 3, 'retryDelay': 15, baseUrl='http://example.com/'}<br>
more info in README.<br>
</td>

@@ -1198,6 +1210,10 @@ </tr>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
waitForElement(using, value, timeout, cb) -&gt; cb(err)<br>
waitFor(asserter, timeout, pollFreq, cb) -&gt; cb(err, return_value)<br>
timeout and pollFreq are optional (default 1000ms/200ms)<br>
waitFor(opts, cb) -&gt; cb(err)<br>
opts with the following fields: timeout, pollFreq, asserter.<br>
asserter like: function(browser , cb) -&gt; cb(err, satisfied, return_value)<br>
</td>

@@ -1207,6 +1223,11 @@ </tr>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
waitForVisible(using, value, timeout, cb) -&gt; cb(err)<br>
waitForElement(using, value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElement(using, value, timeout, pollFreq, cb) -&gt; cb(err)<br>
timeout and pollFreq are optional (default 1000ms/200ms)<br>
waitForElement(using, value, opts, cb) -&gt; cb(err)<br>
opts with the following fields: timeout, pollFreq, asserter.<br>
asserter like: function(element , cb) -&gt; cb(err, satisfied)<br>
</td>

@@ -1216,14 +1237,8 @@ </tr>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
waitForElementByClassName(value, timeout, cb) -&gt; cb(err)<br>
waitForElementByCssSelector(value, timeout, cb) -&gt; cb(err)<br>
waitForElementById(value, timeout, cb) -&gt; cb(err)<br>
waitForElementByName(value, timeout, cb) -&gt; cb(err)<br>
waitForElementByLinkText(value, timeout, cb) -&gt; cb(err)<br>
waitForElementByPartialLinkText(value, timeout, cb) -&gt; cb(err)<br>
waitForElementByTagName(value, timeout, cb) -&gt; cb(err)<br>
waitForElementByXPath(value, timeout, cb) -&gt; cb(err)<br>
waitForElementByCss(value, timeout, cb) -&gt; cb(err)<br>
saveScreenshot(path, cb) -&gt; cb(err, filePath)<br>
path maybe a full file path, a directory path (finishing with /),<br>
the screenshot name, or left blank (will create a file in the system temp dir).<br>
</td>

@@ -1233,14 +1248,16 @@ </tr>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
waitForVisibleByClassName(value, timeout, cb) -&gt; cb(err)<br>
waitForVisibleByCssSelector(value, timeout, cb) -&gt; cb(err)<br>
waitForVisibleById(value, timeout, cb) -&gt; cb(err)<br>
waitForVisibleByName(value, timeout, cb) -&gt; cb(err)<br>
waitForVisibleByLinkText(value, timeout, cb) -&gt; cb(err)<br>
waitForVisibleByPartialLinkText(value, timeout, cb) -&gt; cb(err)<br>
waitForVisibleByTagName(value, timeout, cb) -&gt; cb(err)<br>
waitForVisibleByXPath(value, timeout, cb) -&gt; cb(err)<br>
waitForVisibleByCss(value, timeout, cb) -&gt; cb(err)<br>
waitForElementByClassName(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElementByCssSelector(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElementById(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElementByName(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElementByLinkText(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElementByPartialLinkText(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElementByTagName(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElementByXPath(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
waitForElementByCss(value, asserter, timeout, pollFreq, cb) -&gt; cb(err)<br>
asserter, timeout, pollFreq are optional, opts may be passed instead,<br>
as in waitForElement.<br>
</td>

@@ -1250,3 +1267,3 @@ </tr>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>

@@ -1260,3 +1277,3 @@ <td style="border: 1px solid #ccc; padding: 5px;">

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>

@@ -1270,3 +1287,3 @@ <td style="border: 1px solid #ccc; padding: 5px;">

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>

@@ -1281,12 +1298,9 @@ <td style="border: 1px solid #ccc; padding: 5px;">

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
Waits for JavaScript condition to be true (polling within wd client):<br>
waitForCondition(conditionExpr, timeout, pollFreq, cb) -&gt; cb(err, boolean)<br>
waitForCondition(conditionExpr, timeout, cb) -&gt; cb(err, boolean)<br>
waitForCondition(conditionExpr, cb) -&gt; cb(err, boolean)<br>
Waits for JavaScript condition to be true (async script polling within browser):<br>
waitForConditionInBrowser(conditionExpr, timeout, pollFreq, cb) -&gt; cb(err, boolean) <br>
conditionExpr: condition expression, should return a boolean<br>
timeout: timeout (optional, default: 1000)<br>
pollFreq: pooling frequency (optional, default: 100)<br>
timeout and pollFreq are optional, default: 1000/100.<br>
return true if condition satisfied, error otherwise.<br>

@@ -1297,13 +1311,6 @@ </td>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
Waits for JavaScript condition to be true (async script polling within browser):<br>
waitForConditionInBrowser(conditionExpr, timeout, pollFreq, cb) -&gt; cb(err, boolean)<br>
waitForConditionInBrowser(conditionExpr, timeout, cb) -&gt; cb(err, boolean)<br>
waitForConditionInBrowser(conditionExpr, cb) -&gt; cb(err, boolean)<br>
conditionExpr: condition expression, should return a boolean<br>
timeout: timeout (optional, default: 1000)<br>
pollFreq: pooling frequency (optional, default: 100)<br>
return true if condition satisfied, error otherwise.<br>
sauceJobUpdate(jsonData, cb) -&gt; cb(err)<br>
</td>

@@ -1313,5 +1320,29 @@ </tr>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
sauceJobStatus(hasPassed, cb) -&gt; cb(err)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
sleep(ms, cb) -&gt; cb(err)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
noop(cb) -&gt; cb(err)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
Equivalent to the python sendKeys binding. Upload file if<br>

@@ -1324,3 +1355,3 @@ a local file is detected, otherwise behaves like type.<br>

<td style="border: 1px solid #ccc; padding: 5px;">
EXTRA
extra
</td>

@@ -1331,3 +1362,111 @@ <td style="border: 1px solid #ccc; padding: 5px;">

</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
element.sleep(ms, cb) -&gt; cb(err)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
extra
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
element.noop(cb) -&gt; cb(err)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
asserter
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
asserters.nonEmptyText<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
asserter
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
asserters.textInclude(content) -&gt; Asserter<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
asserter
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
asserters.isVisible<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
asserter
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
asserters.isHidden<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
asserter
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
asserters.jsCondition(jsConditionExpr) -&gt; Asserter<br>
jsConditionExpr: js script expression, should evaluate as boolean.<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
wd
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
wd.configureHttp(opts)<br>
opts example:<br>
{timeout:60000, retries: 3, 'retryDelay': 15, baseUrl='http://example.com/'}<br>
more info in README.<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
wd
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
wd.showHideDeprecation(boolean)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
wd
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
wd.addAsyncMethod(name, func)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
wd
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
wd.addPromiseMethod(name, func)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
wd
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
wd.addPromiseChainMethod(name, func)<br>
</td>
</tr>
<tr>
<td style="border: 1px solid #ccc; padding: 5px;">
wd
</td>
<td style="border: 1px solid #ccc; padding: 5px;">
wd.removeMethod(name, func)<br>
</td>
</tr>
</tbody>
</table>

@@ -5,6 +5,6 @@ <table class="wikitable">

<td width="50%" style="border: 1px solid #ccc; padding: 5px;">
<strong>JsonWireProtocol</strong>
<strong>category / JsonWireProtocol method</strong>
</td>
<td width="50%" style="border: 1px solid #ccc; padding: 5px;">
<strong>wd</strong>
<strong>wd methods</strong>
</td>

@@ -11,0 +11,0 @@ </tr>

@@ -13,3 +13,5 @@ var mappingType = process.argv[2] || 'supported';

JSON.parse(fs.readFileSync('tmp/webdriver-dox.json').toString()),
JSON.parse(fs.readFileSync('tmp/element-dox.json').toString())
JSON.parse(fs.readFileSync('tmp/element-dox.json').toString()),
JSON.parse(fs.readFileSync('tmp/main-dox.json').toString()),
JSON.parse(fs.readFileSync('tmp/asserters-dox.json').toString())
];

@@ -75,3 +77,5 @@

if(_(wd_v.tags).filter(function (t) {
return t.type === 'jsonWire';
return t.type === 'jsonWire' ||
t.type === 'asserter' ||
t.type === 'wd';
}).size() === 0){

@@ -98,3 +102,53 @@ var current = {

// asserter section
_(jsonDocs).each(function (jsonDoc) {
_(jsonDoc).each(function (wd_v) {
if(_(wd_v.tags).filter(function (t) {
return t.type === 'asserter';
}).size() > 0){
var current = {
asserter: true,
wd_doc: []
};
var desc = _(wd_v.description.full.split('\n')).filter(function (l) {
return l !== '';
}).map(function (l) {
return {line: l};
}).value();
current.wd_doc.push({ 'desc': desc });
current.wd_doc1 = current.wd_doc;
if( (mappingType === 'full') ||
(mappingType === 'supported') ) {
resMapping.push(current);
}
}
});
});
// wd section
_(jsonDocs).each(function (jsonDoc) {
_(jsonDoc).each(function (wd_v) {
if(_(wd_v.tags).filter(function (t) {
return t.type === 'wd';
}).size() > 0){
var current = {
wd: true,
wd_doc: []
};
var desc = _(wd_v.description.full.split('\n')).filter(function (l) {
return l !== '';
}).map(function (l) {
return {line: l};
}).value();
current.wd_doc.push({ 'desc': desc });
current.wd_doc1 = current.wd_doc;
if( (mappingType === 'full') ||
(mappingType === 'supported') ) {
resMapping.push(current);
}
}
});
});
// missing section, looking for errors

@@ -101,0 +155,0 @@ _(jsonDocs).each(function (jsonDoc) {

@@ -22,2 +22,3 @@ /* global describe, it, before , beforeEach, after*/

describe('mocha spec examples', function() {
this.timeout(10000);

@@ -24,0 +25,0 @@ // using mocha-as-promised and chai-as-promised is the best way

@@ -381,2 +381,17 @@ //Element object

/**
* element.sleep(ms, cb) -> cb(err)
*/
element.prototype.sleep = function(ms, cb) {
cb = cb || function() {};
setTimeout(cb , ms);
};
/**
* element.noop(cb) -> cb(err)
*/
element.prototype.noop = function(cb) {
if(cb) { cb(); }
};
exports.element = element;

@@ -6,6 +6,7 @@ var __slice = Array.prototype.slice;

var utils = require('./utils');
var deprecator = utils.deprecator;
var config = require('./config');
var _ = require("lodash");
var Q = require('q');
var factory = exports.factory = {

@@ -120,2 +121,35 @@ WebDriver: Webdriver

// todo: allow adding element methods
function addPromiseChainMethod(name, method) {
var wrappedMethod = function() {
var args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
var promise = new Q(method.apply(this, args));
this._enrich(promise);
return promise;
};
PromiseChainWebdriver.prototype[name] = wrappedMethod;
}
function addPromiseMethod(name, method) {
var wrappedMethod = function() {
var args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return new Q(method.apply(this, args));
};
PromiseWebdriver.prototype[name] = wrappedMethod;
addPromiseChainMethod(name, method);
}
function addAsyncMethod(name, method) {
Webdriver.prototype[name] = method;
PromiseWebdriver.prototype[name] = PromiseWebdriver._wrapAsync(method);
PromiseChainWebdriver.prototype[name] = PromiseChainWebdriver._wrapAsync(method);
}
function removeMethod(name) {
delete Webdriver.prototype[name];
delete PromiseWebdriver.prototype[name];
delete PromiseChainWebdriver.prototype[name];
}
// creates a webdriver object using the Q promise wrap not chained

@@ -153,5 +187,58 @@ function promiseRemote() {

// Actualizes promise wrappers
rewrap: wrap,
rewrap: function() {
deprecator.warn('rewrap',
'rewrap has been deprecated, use addAsyncMethod instead.');
wrap();
},
// config
/**
* wd.configureHttp(opts)
*
* opts example:
* {timeout:60000, retries: 3, 'retryDelay': 15, baseUrl='http://example.com/'}
* more info in README.
*
* @wd
*/
configureHttp: config.configureHttp,
getHttpConfig: function() { return _(config.httpConfig).clone(); },
// deprecation
/**
* wd.showHideDeprecation(boolean)
*
* @wd
*/
showHideDeprecation: deprecator.showHideDeprecation.bind(deprecator),
// add/remove methods
/**
* wd.addAsyncMethod(name, func)
*
* @wd
*/
addAsyncMethod: addAsyncMethod,
/**
* wd.addPromiseMethod(name, func)
*
* @wd
*/
addPromiseMethod: addPromiseMethod,
/**
* wd.addPromiseChainMethod(name, func)
*
* @wd
*/
addPromiseChainMethod: addPromiseChainMethod,
/**
* wd.removeMethod(name, func)
*
* @wd
*/
removeMethod: removeMethod,
// Useful stuff
Asserter: require('./asserters').Asserter,
asserters: require('./asserters'),
SPECIAL_KEYS: SPECIAL_KEYS,

@@ -158,0 +245,0 @@ Q: Q,

@@ -1,6 +0,7 @@

var __slice = Array.prototype.slice
, Q = require('q')
, _ = require('lodash')
, EventEmitter = require('events').EventEmitter
, slice = Array.prototype.slice.call.bind(Array.prototype.slice);
var __slice = Array.prototype.slice,
Q = require('q'),
_ = require('lodash'),
EventEmitter = require('events').EventEmitter,
slice = Array.prototype.slice.call.bind(Array.prototype.slice),
utils = require('./utils');

@@ -11,3 +12,3 @@ // The method below returns no result, so we are able hijack the result to

var elementChainableMethods = ['clear','click','doubleClick','doubleclick',
'flick','sendKeys','submit','type','keys','moveTo'];
'flick','sendKeys','submit','type','keys','moveTo','sleep','noop'];

@@ -17,3 +18,3 @@ // gets the list of methods to be promisified.

return _(Obj).functions().filter(function(fname) {
return !fname.match('^chain$|^toString$|^_') &&
return !fname.match('^toString$|^_') &&
!EventEmitter.prototype[fname];

@@ -23,12 +24,7 @@ }).value();

// promise detection
function isPromise(x) {
return (typeof x === "object" || typeof x === "function") && x !== null && typeof x.then === "function";
}
// enriches a promise with the browser + element methods.
function enrich(obj, browser){
function enrich(obj, browser) {
// There are cases were enrich may be called on non-promise objects.
// It is easier and safer to check within the method.
if(isPromise(obj) && !obj.__wd_promise_enriched) {
if(utils.isPromise(obj) && !obj.__wd_promise_enriched) {
var promise = obj;

@@ -56,5 +52,4 @@

var elementPromisedMethods =
Element? filterPromisedMethods(Element.prototype) : [];
var allPromisedMethods = _.union(promisedMethods,
filterPromisedMethods(browserProto), elementPromisedMethods);
Element ? filterPromisedMethods(Element.prototype) : [];
var allPromisedMethods = _.union(promisedMethods, elementPromisedMethods);

@@ -70,3 +65,3 @@ // adding browser + element methods to the current promise.

var scopeHint;
if(args && args[0] && typeof args[0] === 'string' && args[0].match(/^<$|^>$/)) {
if(args && args[0] && typeof args[0] === 'string' && args[0].match(/^[<>]$/)) {
scopeHint = args[0];

@@ -79,3 +74,3 @@ args = _.rest(args);

// if the result is an element it has priority
if(Element && res instanceof Element) {el=res;}
if(Element && res instanceof Element) { el = res; }

@@ -93,7 +88,7 @@ // testing the water for the next call scope

if(isBrowserMethod && isElementMethod){
if(isBrowserMethod && isElementMethod) {
// we need to resolve the conflict.
if(scopeHint === '<' ){
if(scopeHint === '<') {
isElementMethod = false;
} else if(scopeHint === '>' ){
} else if(scopeHint === '>') {
isBrowserMethod = false;

@@ -110,6 +105,6 @@ } else if(fname.match(/element/) || (Element && args[0] instanceof Element)) {

if(isElementMethod){
if(isElementMethod) {
// element method case.
return el[fname].apply(el, args).then(function(res) {
if( _.indexOf(elementChainableMethods, fname) >= 0) {
if(_.indexOf(elementChainableMethods, fname) >= 0) {
// method like click, where no result is expected, we return

@@ -157,3 +152,3 @@ // the element to make it chainable

deferred.promise.then(function() {
_this.emit("promise", _this, fname , args , "finished" );
_this.emit("promise", _this, fname , args , "finished");
});

@@ -170,7 +165,3 @@

// (Based on the API as of 2012/12/1 this assumption is always correct)
if (typeof args[args.length - 1] === 'function' &&
!fname.match('Mock')) // This is for the mocking method of wd-tractor
// which are the only cases of sync call with
// function parameters.
// Should find a better way if more cases arise
if(typeof args[args.length - 1] === 'function')
{

@@ -188,6 +179,6 @@ // Remove to replace it with our callback and then call it

args.push(deferred.makeNodeResolver());
_this.emit("promise", _this, fname , args , "calling" );
_this.emit("promise", _this, fname , args , "calling");
fn.apply(this, args);
if(chainable){
if(chainable) {
return enrich(deferred.promise, this);

@@ -222,3 +213,3 @@ } else {

_(filterPromisedMethods(WebDriver.prototype)).each(function(fname) {
promiseWebdriver.prototype[fname] = wrap(WebDriver.prototype[fname], fname );
promiseWebdriver.prototype[fname] = wrap(WebDriver.prototype[fname], fname);
});

@@ -228,14 +219,40 @@

_(filterPromisedMethods(Element.prototype)).each(function(fname) {
promiseElement.prototype[fname] = wrap(Element.prototype[fname], fname );
promiseElement.prototype[fname] = wrap(Element.prototype[fname], fname);
});
// used to by chai-as-promised
promiseWebdriver.prototype._enrich = function(target){
/**
* Starts the chain (promised driver only)
* browser.chain()
* element.chain()
*/
promiseWebdriver.prototype.chain = promiseWebdriver.prototype.noop;
promiseElement.prototype.chain = promiseElement.prototype.noop;
/**
* Resolves the promise (promised driver only)
* browser.resolve(promise)
* element.resolve(promise)
*/
promiseWebdriver.prototype.resolve = function(promise) {
var qPromise = new Q(promise);
this._enrich(qPromise);
return qPromise;
};
promiseElement.prototype.resolve = function(promise) {
var qPromise = new Q(promise);
this._enrich(qPromise, this.browser);
return qPromise;
};
// used to by chai-as-promised and custom methods
promiseWebdriver.prototype._enrich = function(target) {
if(chainable) { enrich(target, this); }
};
promiseElement.prototype._enrich = function(target){
promiseElement.prototype._enrich = function(target) {
if(chainable) { enrich(target, this.browser); }
};
// used to wrap custom methods
promiseWebdriver._wrapAsync = wrap;
// helper to allow easier promise debugging.

@@ -262,3 +279,3 @@ promiseWebdriver.prototype._debugPromise = function() {

}).join(', ') + ' )';
console.log(' --> ' + status + context + " " + method + args );
console.log(' --> ' + status + context + " " + method + args);
});

@@ -265,0 +282,0 @@ };

@@ -40,3 +40,4 @@ var Args = require("vargs").Constructor;

// core methods:
"then", "catch", "fail", "progress", "finally", "fin", "done"
"then", "catch", "fail", "progress", "finally", "fin", "done",
"thenResolve", "thenReject"
];

@@ -54,1 +55,25 @@

};
// promise detection
exports.isPromise = function(x) {
return (typeof x === "object" || typeof x === "function") && x !== null && typeof x.then === "function";
};
exports.deprecator = {
deprecationMessageShown: {},
warnDeprecated: true,
showHideDeprecation: function(status) {
if(status !== undefined) { this.warnDeprecated = status; }
else { this.warnDeprecated = !this.warnDeprecated; }
},
warn: function(cat, message) {
if(this.warnDeprecated && !this.deprecationMessageShown[cat]) {
this.deprecationMessageShown[cat] = 1;
console.warn(message);
}
}
};

@@ -10,3 +10,3 @@ {

],
"version": "0.2.2",
"version": "0.2.3",
"author": "Adam Christian <adam.christian@gmail.com>",

@@ -56,3 +56,5 @@ "contributors": [

"archiver": "~0.4.10",
"lodash": "~1.3.1"
"lodash": "~1.3.1",
"tmp": "0.0.21",
"string": "~1.6.1"
},

@@ -73,3 +75,3 @@ "devDependencies": {

"istanbul": "~0.1.44",
"string": "~1.6.0"
"promise-simple": "~0.1.0"
},

@@ -76,0 +78,0 @@ "scripts": {

@@ -1,6 +0,8 @@

# WD.js -- WebDriver/Selenium 2 for node.js
- Mailing List: https://groups.google.com/forum/#!forum/wdjs
# WD.js
## Status
**node.js Webdriver/Selenium 2 client**
- [Site](http://admc.io/wd/)
- [Mailing List](https://groups.google.com/forum/#!forum/wdjs)
[![Build Status](https://secure.travis-ci.org/admc/wd.png?branch=master)](http://travis-ci.org/admc/wd)

@@ -37,29 +39,12 @@ [![Selenium Test Status](https://saucelabs.com/buildstatus/wdjs)](https://saucelabs.com/u/wdjs)

## 0.2.x Release
## Release notes
### 0.2.0
Many changes have been introduced in 0.2.x versions, please check
[here](https://github.com/admc/wd/blob/master/doc/release-notes.md) for more details.
- New wrapper: promise chain.
- Old chain api is deprecated (It is still available, but you will see a depreciation message).
- There are some changes in the way the element and webdriver classes are passed around
which may affect external wrappers. External wrappers should now subclass those 2 classes.
### 0.2.3 caveats
- Most wait methods have been deprecated replaced by waitFor/waitForElement + asserters. See doc below, don't hesitate to add more asserters if you feel it is useful for others.
- Manual monkey patching is not recommended anymore, there were some side use cases which were not easy to cover.
Use addAsyncMethod/addPromiseMethod/addPromiseChainMethod methods instead. See doc below.
### 0.2.1
- New test suite using the promise chain api.
- `browser.Q` was moved to `wd.Q`.
### 0.2.2
- chai-as-promised v4 compatible.
- Promise wrappers can now be monkey patched directly.
- New saucelabs helpers.
Incompatibilities:
- There is a new method to call, `wd.rewrap()`, to propagate async monkey
patching to promise. (see [here](https://github.com/admc/wd/blob/master/examples/promise/monkey.patch-with-async.js#L35) and the monkey patch section below)
- The chai-as-promised setup has changed in V4, look out for the `transferPromiseness`
line in the examples. (see [here](https://github.com/admc/wd/blob/master/examples/promise/chrome.js#L15))
## Usage

@@ -119,3 +104,3 @@

## Generators Api
## Generators api

@@ -196,5 +181,5 @@ ### Yiewd

[supported](https://github.com/admc/wd/blob/master/doc/jsonwire-mapping.md)
[jsonwire mapping + api doc](https://github.com/admc/wd/blob/master/doc/api.md)
[full json wire mapping](https://github.com/admc/wd/blob/master/doc/jsonwire-full-mapping.md)
[åfull jsonwire mapping](https://github.com/admc/wd/blob/master/doc/jsonwire-full-mapping.md)

@@ -258,3 +243,3 @@ ### JsonWireProtocol

#### Url object created via `url.parse`
#### Url object created via url.parse

@@ -301,21 +286,123 @@ [URL module documentation](http://nodejs.org/docs/v0.10.0/api/url.html#url_url)

### Monkey patching
### Waiting for something
You may want to monkey patch the webdriver class in order to add custom functionalities.
Below are the methods to use to wait for a condition:
- `browser.waitFor(asserter, timeout, pollFreq, cb) -> cb(err, value)`: generic wait method, the return value is provided by the asserter when the condition is satisfied.
- `browser.waitForElementBy???(value ,asserter, timeout, pollFreq, cb) -> cb(err, el)`: waits for a element then a
condition, then returns the element.
- `browser.waitForConditionInBrowser(conditionExpr, timeout, pollFreq, cb) -> cb(err, boolean)`: waits for a js condition within a browser, then returns a boolean.
Asserters should be written using either models below . `target` may be `browser` and/or `element` depending on the context.
```js
// async
var asyncAsserter = new Asserter(
function(target,cb) {
...
cb(err, satisfied, value);
}
);
// promise
var promiseAsserter = new Asserter(
function(target) {
...
return promise; // promise resolved with the wait_for return value.
// Promise asserter should throw errors marked with `err.retriable=true`
// when the condition is not satisfied.
}
);
```
Example [here](https://github.com/admc/wd/blob/master/examples/promise/wait-for.js).
There are ready to use asserters [here](https://github.com/admc/wd/blob/master/lib/asserters.js),
See also the asserter category in the api doc [here](https://github.com/admc/wd/blob/master/doc/api.md).
### Adding custom methods
- `wd.addAsyncMethod(name, method)`: This is for regular async methods with callback as the last argument. This will not only add the method to the async browser prototype, but also wrap the method and add it to the promise and promiseChain prototypes.
- `wd.addPromiseMethod(name, method)`: This is for promise returning methods NOT USING CHAIN internally. This will not only add the method to the promise browser prototype, but also wrap the method and add it to the promiseChain prototype (but not to the async prototype).
- `wd.addPromiseChainMethod(name, method)`: This is for promise returning methods USING CHAIN internally. This will only add the method to the promiseChain browser prototype (but neither to async nor to promise browser prototypes).
If you are only using the promise chain api, you should probably stick with `wd.addPromiseChainMethod(name, method)`.
You may remove a custom method with `wd.removeMethod(name)`. Not sure why you would want to do that, but that will remove the method from the 3 prototypes.
Please refer to the following examples:
- [pure promise](https://github.com/admc/wd/blob/master/examples/promise/monkey.patch.js).
- [async patch used by promise](https://github.com/admc/wd/blob/master/examples/promise/monkey.patch-with-async.js).
- [promise no-chain](https://github.com/admc/wd/blob/master/examples/promise/monkey.patch-no-chain.js).
- [full async](https://github.com/admc/wd/blob/master/examples/async/monkey.patch.js).
- [promise chain](https://github.com/admc/wd/blob/master/examples/promise/add-method.js).
- [async method used by promise chain](https://github.com/admc/wd/blob/master/examples/promise/add-method-async.js).
- [promise no-chain](https://github.com/admc/wd/blob/master/examples/promise/add-method-no-chain.js).
- [async](https://github.com/admc/wd/blob/master/examples/async/add-method.js).
Caveat: You now need to call `wd.rewrap()` to propagate async monkey patching to the
promise wrapper. This will ovewrite the promise wrapper prototype, so you need to do
your monkey patching in order, async first, call `wd.rewrap()` , and only then promise.
Note: No need to call rewrap anymore.
### Promise helpers
This is a clean alternative to monkey patching.
This is an alternative to adding custom methods.
See example [here](https://github.com/admc/wd/blob/master/examples/promise/helper.js).
### Starting the promise chain
The `browser` and `element` object are not themselves promises (cause that would lead to chaos), so you
cannot call Q core methods on them. However you may call one of the method below to initiate the promise
chain:
- `browser.chain()`
- `browser.noop()`
- `browser.resolve(promise)`
- `element.chain()`
- `element.noop()`
- `element.resolve(promise)`
The `resolve` methods work like `Q` `thenResolve`.
### Working with external promise libraries
`wd` uses `Q` internally, but you may use promises from other libraries with the following methods:
- `browser.resolve(externalPromise)`
- `wd.addPromiseChainMethod(name, externalPromise)`
- `wd.addPromiseMethod(name, externalPromise)`
The external promise will be automatically wrapped within a Q promise using `new Q(externalPromise)`.
See example [here](https://github.com/admc/wd/blob/master/examples/promise/external-promise.js).
### Http configuration / base url
Http behaviour and base url may be configured via the `configureHttp` method as
in the code below:
```js
// global config
wd.configureHttp({
timeout: 60000,
retries: 3,
retryDelay: 100,
baseUrl = 'http://example.com/'
});
// per browser config
browser.configureHttp({
timeout: 60000,
retries: 3,
retryDelay: 100,
baseUrl = 'http://example.com/'
});
```
- timeout: http timeout in ms, default is `undefined` (uses the server timeout,
usually 60 seconds). Use `'default'` or `undefined` for server default.
- retries: Number of reconnection attempts in case the connection is dropped.
Default is `3`. Pass `0` or `always` to keep trying. Pass `-1` or `never` to disable.
- retryDelay: the number of ms to wait before reconnecting. Default is `15`.
- baseUrl: the base url use by the `get` method. The destination url is computed using
`url.resolve`. Default is empty.
- If a field is not specified, the current configuration for this field is
unchanged.
### Environment variables for Saucelabs

@@ -395,3 +482,3 @@

```
make mapping > doc/jsonwire-mapping.md
make mapping > doc/api.md
make full_mapping > doc/jsonwire-full-mapping.md

@@ -405,3 +492,3 @@ make unsupported_mapping > doc/jsonwire-unsupported-mapping.md

npm version [patch|minor|major]
git push --tags
git push --tags origin master
npm publish

@@ -413,1 +500,2 @@ ```

[test coverage](http://admc.io/wd/istanbul/coverage/lcov-report/index.html)

@@ -13,2 +13,12 @@ var env = GLOBAL.env = {};

env.HTTP_CONFIG = {};
if(process.env.HTTP_TIMEOUT)
{ env.HTTP_CONFIG.timeout = S(process.env.HTTP_TIMEOUT).toInt(); }
if(process.env.HTTP_RETRIES)
{ env.HTTP_CONFIG.retries = S(process.env.HTTP_RETRIES).toInt(); }
if(process.env.HTTP_RETRY_DELAY)
{ env.HTTP_CONFIG.retryDelay = S(process.env.HTTP_RETRY_DELAY).toInt(); }
env.DEBUG_CONNECTION = process.env.DEBUG_CONNECTION;
env.REMOTE_CONFIG = process.env.REMOTE_CONFIG;

@@ -91,3 +101,3 @@ env.BROWSER = process.env.BROWSER || 'chrome';

if(env.SAUCE){
env.BASE_TIME_UNIT = S(process.env.BASE_TIME_UNIT || 1000).toInt();
env.BASE_TIME_UNIT = S(process.env.BASE_TIME_UNIT || 3000).toInt();
env.TIMEOUT = S(process.env.TIMEOUT || 600000).toInt();

@@ -127,3 +137,3 @@

env.DESIRED.browserName = 'internet explorer';
env.DESIRED.platform = 'Windows 7';
env.DESIRED.platform = 'Windows 8';
env.DESIRED.version = '10';

@@ -130,0 +140,0 @@ }

@@ -21,3 +21,3 @@ var express = require('express');

testSuite: req.query.ts,
testTitle: req.query.p,
testTitle: (req.query.c? req.query.c + ' - ': '') + req.query.p,
content: content

@@ -24,0 +24,0 @@ });

@@ -8,5 +8,7 @@ require('./env');

// monkey patching
wd.webdriver.prototype.configureLogging = function (done){
wd.addAsyncMethod(
'configureLogging',
function (done){
if(env.VERBOSE) {
//browser._debugPromise();
//this._debugPromise();
this.on('status', function(info) {

@@ -19,12 +21,22 @@ console.log(info);

}
if(env.DEBUG_CONNECTION) {
this.on('http', function(message) {
console.log('http > ' + message );
});
}
done();
};
}
);
wd.rewrap();
GLOBAL.midwayUrl = function(testSuite, title){
GLOBAL.midwayUrl = function(testSuite, cat, title){
if(!title) {
title = cat;
cat = undefined;
}
var cleanTitle = title.replace(/@[-\w]+/g, '').trim();
return env.MIDWAY_ROOT_URL + '/test-page' +
'?p=' + encodeURIComponent(cleanTitle) +
'&ts=' + encodeURIComponent(testSuite);
'&ts=' + encodeURIComponent(testSuite) +
(cat? '&c=' +encodeURIComponent(cat) : '');
};

@@ -60,2 +72,3 @@

chaiAsPromised.transferPromiseness = wd.transferPromiseness;
GLOBAL.AssertionError = chai.AssertionError;
GLOBAL.expect = chai.expect;

@@ -65,1 +78,3 @@ GLOBAL.should = chai.should();

GLOBAL.Express = require("./express-helper").Express;
wd.configureHttp(env.HTTP_CONFIG);

@@ -47,6 +47,9 @@ require('../helpers/setup');

return browser
.execute(
.executeAsync(
'var args = Array.prototype.slice.call( arguments, 0 );\n' +
'var done = args[args.length -1];\n' +
'setTimeout(function() {\n' +
' $("#theDiv").append("<div class=\\"child\\">a waitForElement child</div>");\n' +
'}, arguments[0]);\n',
'}, arguments[0]);\n' +
'done();\n',
[env.BASE_TIME_UNIT]

@@ -60,3 +63,3 @@ )

.waitForElement("css selector", "#wrongsel .child", 0.1 * env.BASE_TIME_UNIT)
.should.be.rejectedWith(/Element didn't appear/);
.should.be.rejectedWith('Element condition wasn\'t satisfied!');
});

@@ -69,3 +72,5 @@ });

return browser
.execute(
.executeAsync(
'var args = Array.prototype.slice.call( arguments, 0 );\n' +
'var done = args[args.length -1];\n' +
'$("#theDiv").append("<div class=\\"child\\">a waitForVisible child</div>");\n' +

@@ -75,3 +80,4 @@ '$("#theDiv .child").hide();\n' +

' $("#theDiv .child").show();\n' +
'}, arguments[0]);\n',
'}, arguments[0]);\n' +
'done();\n',
[env.BASE_TIME_UNIT]

@@ -78,0 +84,0 @@ )

@@ -6,3 +6,3 @@ // spliting the test cause it takes too long, list of possible suffixes below

exports.test = function function_name (suffixes, extraDesc) {
exports.test = function function_name (suffix, extraDesc, partials, criterias) {

@@ -18,225 +18,104 @@ require('../helpers/setup');

// get suffix specific fields
function getSuffixFields(suffix) {
var elementFuncName = 'element' + suffix;
var searchOne = elementFuncName;
if (searchOne.match(/ByLinkText/)) {
searchOne = "click " + searchOne;
}
if (searchOne.match(/ByCss/)) {
searchOne = "." + searchOne;
}
if (searchOne.match(/ByXPath/)) {
searchOne = "//div[@id='elementByXPath']/input";
}
if (searchOne.match(/ByTagName/)) {
searchOne = "span";
}
var searchOneInvalid = searchOne + '2';
if (searchOne.match(/ByXPath/)) {
searchOneInvalid = "//div[@id='elementByXPath2']/input";
}
if (searchOne.match(/ByTagName/)) {
searchOneInvalid = "span2";
}
var searchSeveral = searchOne.replace('element', 'elements');
var searchSeveralInvalid = searchOneInvalid.replace('element', 'elements');
var elementFuncName = 'element' + suffix;
express.partials['browser.' + elementFuncName] = partials.one;
it('browser.' + elementFuncName, function() {
return Q.all([
browser[elementFuncName](criterias.valid).should.eventually.exist,
browser[elementFuncName](criterias.invalid).should.be.rejectedWith(/status: 7/)
]);
});
var waitForElementFuncName = 'waitForElement' + suffix;
var childHtml = "<div class='child child_" + waitForElementFuncName + "'>a " + waitForElementFuncName + " child</div>";
if (suffix.match(/ById/)) {
childHtml = "<div class='child' id='child_" + waitForElementFuncName + "'>a " + waitForElementFuncName + " child</div>";
}
if (suffix.match(/ByName/)) {
childHtml = "<div class='child' name='child_" + waitForElementFuncName + "'>a " + waitForElementFuncName + " child</div>";
}
if (suffix.match(/ByLinkText/)) {
childHtml = "<a class='child'>child_" + waitForElementFuncName + "</a>";
}
if (suffix.match(/ByPartialLinkText/)) {
childHtml = "<a class='child'>hello child_" + waitForElementFuncName + "</a>";
}
if (suffix.match(/ByTagName/)) {
childHtml = "<hr class='child'>";
}
var searchChild = "child_" + waitForElementFuncName;
if (suffix.match(/ByCss/)) {
searchChild = "." + searchChild;
}
if (suffix.match(/ByTagName/)) {
searchChild = "hr";
}
if (suffix.match(/ByXPath/)) {
searchChild = "//div[@class='child child_" + waitForElementFuncName + "']";
}
return {
searchOne: searchOne,
searchOneInvalid: searchOneInvalid,
searchSeveral: searchSeveral,
searchSeveralInvalid: searchSeveralInvalid,
childHtml: childHtml,
searchChild: searchChild
};
}
var elementFuncNameOrNull = 'element' + suffix + 'OrNull';
express.partials['browser.' + elementFuncNameOrNull] = partials.one;
it('browser.' + elementFuncNameOrNull, function() {
return browser
[elementFuncNameOrNull](criterias.valid).should.eventually.exist
[elementFuncNameOrNull](criterias.invalid).should.eventually.be.a('null');
});
var allElementsPartial =
'<div>\n' +
' <div class="elementByClassName">Hello World!</div>\n' +
' <div class="elementByCssSelector">Hello World!</div>\n' +
' <div id="elementById">Hello World!</div>\n' +
' <div name="elementByName">Hello World!</div>\n' +
' <div id="elementByLinkText"><a>click elementByLinkText</a></div>\n' +
' <div id="elementByPartialLinkText"><a>click elementByPartialLinkText</a></div>\n' +
' <div id="elementByTagName"><span>Hello World!</span></div>\n' +
' <div id="elementByXPath"/><input></div>\n' +
' <div class="elementByCss">Hello World!</div>\n' +
'<div>\n';
var elementFuncNameIfExists = 'element' + suffix + 'IfExists';
express.partials['browser.' + elementFuncNameIfExists] = partials.one;
it('browser.' + elementFuncNameIfExists, function() {
return browser
[elementFuncNameIfExists](criterias.valid).should.eventually.exist
[elementFuncNameIfExists](criterias.invalid).should.eventually.be.a('undefined');
});
_(suffixes).each(function(suffix) {
var suffixFields = getSuffixFields(suffix);
var hasElementFuncName = 'hasElement' + suffix;
express.partials['browser.' + hasElementFuncName] = partials.one;
it('browser.' + hasElementFuncName, function() {
return browser
[hasElementFuncName](criterias.valid).should.eventually.be.ok
[hasElementFuncName](criterias.invalid).should.eventually.not.be.ok;
});
var elementFuncName = 'element' + suffix;
express.partials['browser.' + elementFuncName] = allElementsPartial;
it('browser.' + elementFuncName, function() {
return Q.all([
browser[elementFuncName](suffixFields.searchOne).should.eventually.exist,
browser[elementFuncName](suffixFields.searchOneInvalid).should.be.rejectedWith(/status: 7/)
]);
});
var waitForElementFuncName = 'waitForElement' + suffix;
express.partials['browser.' + waitForElementFuncName] =
'<div id="theDiv"></div>';
it('browser.' + waitForElementFuncName, function() {
return browser
.executeAsync(
'var args = Array.prototype.slice.call( arguments, 0 );\n' +
'var done = args[args.length -1];\n' +
'setTimeout(function() {\n' +
' $("#theDiv").append(args[0]);\n' +
'}, args[1]);\n' +
'done();\n',
[partials.child, env.BASE_TIME_UNIT]
)
[elementFuncName](criterias.child).should.be.rejectedWith(/status: 7/)
[waitForElementFuncName](criterias.child, 2 * env.BASE_TIME_UNIT)
.should.be.fulfilled
.then(function() {
return browser
[waitForElementFuncName]("__wrongsel", 0.1 * env.BASE_TIME_UNIT)
.should.be.rejectedWith('Element condition wasn\'t satisfied!');
});
});
var elementFuncNameOrNull = 'element' + suffix + 'OrNull';
express.partials['browser.' + elementFuncNameOrNull] = allElementsPartial;
it('browser.' + elementFuncNameOrNull, function() {
return browser
[elementFuncNameOrNull](suffixFields.searchOne).should.eventually.exist
[elementFuncNameOrNull](suffixFields.searchOneInvalid).should.eventually.be.a('null');
});
var waitForVisibleFuncName = 'waitForVisible' + suffix;
express.partials['browser.' + waitForVisibleFuncName] =
'<div id="theDiv"></div>';
it('browser.' + waitForVisibleFuncName, function() {
return browser
.executeAsync(
'var args = Array.prototype.slice.call( arguments, 0 );\n' +
'var done = args[args.length -1];\n' +
'$("#theDiv").append(args[0]);\n' +
'$("#theDiv .child").hide();\n' +
'setTimeout(function() {\n' +
' $("#theDiv .child").show();\n' +
'}, args[1]);\n' +
'done();\n',
[partials.child, env.BASE_TIME_UNIT]
)
[elementFuncName](criterias.child).should.eventually.exist
[waitForVisibleFuncName](criterias.child, 2 * env.BASE_TIME_UNIT)
.should.be.fulfilled
.then(function() {
return browser
[waitForVisibleFuncName]("__wrongsel", 0.1 * env.BASE_TIME_UNIT)
.should.be.rejectedWith(/Element didn\'t become visible/);
});
});
var elementFuncNameIfExists = 'element' + suffix + 'IfExists';
express.partials['browser.' + elementFuncNameIfExists] = allElementsPartial;
it('browser.' + elementFuncNameIfExists, function() {
return browser
[elementFuncNameIfExists](suffixFields.searchOne).should.eventually.exist
[elementFuncNameIfExists](suffixFields.searchOneInvalid).should.eventually.be.a('undefined');
});
var elementsFuncName = 'elements' + suffix;
express.partials['browser.' + elementsFuncName] = partials.several;
it('browser.' + elementsFuncName, function() {
return browser
[elementsFuncName](criterias.valid).then(function(res) {
if (elementsFuncName.match(/ById/)) {
res.should.have.length(1);
} else if (elementsFuncName.match(/ByTagName/)) {
(res.length > 1).should.be.true;
} else {
res.should.have.length(3);
}
})
[elementsFuncName](criterias.invalid)
.should.eventually.deep.equal([]);
});
var hasElementFuncName = 'hasElement' + suffix;
express.partials['browser.' + hasElementFuncName] = allElementsPartial;
it('browser.' + hasElementFuncName, function() {
return browser
[hasElementFuncName](suffixFields.searchOne).should.eventually.be.ok
[hasElementFuncName](suffixFields.searchOneInvalid).should.eventually.not.be.ok;
});
var waitForElementFuncName = 'waitForElement' + suffix;
express.partials['browser.' + waitForElementFuncName] =
'<div id="theDiv"></div>';
it('browser.' + waitForElementFuncName, function() {
return browser
.execute(
'var args = Array.prototype.slice.call( arguments, 0 );\n' +
'setTimeout(function() {\n' +
' $("#theDiv").append(args[0]);\n' +
'}, args[1]);\n',
[suffixFields.childHtml, env.BASE_TIME_UNIT]
)
[elementFuncName](suffixFields.searchChild).should.be.rejectedWith(/status: 7/)
[waitForElementFuncName](suffixFields.searchChild, 2 * env.BASE_TIME_UNIT)
.should.be.fulfilled
.then(function() {
return browser
[waitForElementFuncName]("__wrongsel", 0.1 * env.BASE_TIME_UNIT)
.should.be.rejectedWith(/Element didn\'t appear/);
});
});
var waitForVisibleFuncName = 'waitForVisible' + suffix;
express.partials['browser.' + waitForVisibleFuncName] =
'<div id="theDiv"></div>';
it('browser.' + waitForVisibleFuncName, function() {
return browser
.execute(
'var args = Array.prototype.slice.call( arguments, 0 );\n' +
'$("#theDiv").append(args[0]);\n' +
'$("#theDiv .child").hide();\n' +
'setTimeout(function() {\n' +
' $("#theDiv .child").show();\n' +
'}, args[1]);\n',
[suffixFields.childHtml, env.BASE_TIME_UNIT]
)
.elementByCss(".child").should.eventually.exist
[waitForVisibleFuncName](suffixFields.searchChild, 2 * env.BASE_TIME_UNIT)
.should.be.fulfilled
.then(function() {
return browser
[waitForVisibleFuncName]("__wrongsel", 0.1 * env.BASE_TIME_UNIT)
.should.be.rejectedWith(/Element didn\'t become visible/);
});
});
var elementsFuncName = 'elements' + suffix;
express.partials['browser.' + elementsFuncName] =
'<div>\n' +
' <div class="elementsByClassName">Hello World!</div>\n' +
' <div class="elementsByClassName">Hello World!</div>\n' +
' <div class="elementsByClassName">Hello World!</div>\n' +
'</div>\n' +
'<div>\n' +
' <div class="elementsByCssSelector">Hello World!</div>\n' +
' <div class="elementsByCssSelector">Hello World!</div>\n' +
' <div class="elementsByCssSelector">Hello World!</div>\n' +
'</div>\n' +
'<div>\n' +
' <div id="elementsById">Hello World!</div>\n' +
'</div>\n' +
'<div>\n' +
' <div name="elementsByName">Hello World!</div>\n' +
' <div name="elementsByName">Hello World!</div>\n' +
' <div name="elementsByName">Hello World!</div>\n' +
'</div>\n' +
'<div>\n' +
' <div class="elementsByLinkText"><a>click elementsByLinkText</a></div>\n' +
' <div class="elementsByLinkText"><a>click elementsByLinkText</a></div>\n' +
' <div class="elementsByLinkText"><a>click elementsByLinkText</a></div>\n' +
'</div>\n' +
'<div>\n' +
' <div class="elementsByPartialLinkText"><a>click elementsByPartialLinkText</a></div>\n' +
' <div class="elementsByPartialLinkText"><a>click elementsByPartialLinkText</a></div>\n' +
' <div class="elementsByPartialLinkText"><a>click elementsByPartialLinkText</a></div>\n' +
'</div>\n' +
'<div id="elementsByTagName">\n' +
' <span>Hello World!</span>\n' +
' <span>Hello World!</span>\n' +
' <span>Hello World!</span>\n' +
'</div>\n' +
'<div id="elementsByXPath"/>\n' +
' <input>\n' +
' <input>\n' +
' <input>\n' +
'</div>\n' +
'<div>\n' +
' <div class="elementsByCss">Hello World!</div>\n' +
' <div class="elementsByCss">Hello World!</div>\n' +
' <div class="elementsByCss">Hello World!</div>\n' +
'</div>\n';
it('browser.' + elementsFuncName, function() {
return browser
[elementsFuncName](suffixFields.searchSeveral).then(function(res) {
if (elementsFuncName.match(/ById/)) {
res.should.have.length(1);
} else if (elementsFuncName.match(/ByTagName/)) {
(res.length > 1).should.be.true;
} else {
res.should.have.length(3);
}
})
[elementsFuncName](suffixFields.searchSeveralInvalid)
.should.eventually.deep.equal([]);
});
}); // suffix loop ends
});
};

@@ -128,7 +128,9 @@ require('../helpers/setup');

return browser
.execute(
.executeAsync(
'var args = Array.prototype.slice.call( arguments, 0 );\n' +
'var done = args[args.length -1];\n' +
' setTimeout(function() {\n' +
' $("#theDiv").html("<div class=\\"child\\">a waitForCondition child</div>");\n' +
' }, arguments[0]);\n' //+
,
' }, arguments[0]);\n' +
'done();\n',
[env.BASE_TIME_UNIT]

@@ -150,7 +152,9 @@ )

return browser
.execute(
.executeAsync(
'var args = Array.prototype.slice.call( arguments, 0 );\n' +
'var done = args[args.length -1];\n' +
' setTimeout(function() {\n' +
' $("#theDiv").html("<div class=\\"child\\">a waitForCondition child</div>");\n' +
' }, arguments[0]);\n' //+
,
' }, arguments[0]);\n' +
'done();\n',
[env.BASE_TIME_UNIT]

@@ -157,0 +161,0 @@ )

require('../helpers/setup');
var imageinfo = require('imageinfo');
var path = require('path');
var fs = require('fs');
var tmp = require('tmp');

@@ -109,2 +112,33 @@ describe('api-various ' + env.ENV_DESC, function() {

it('browser.saveScreenshot', function() {
var mydir = path.join(tmp.tmpdir , 'myscreenshot');
console.log("mydir --> ", mydir);
try { fs.mkdirSync(mydir); } catch(ign) {}
return browser
.saveScreenshot( mydir + '/abc.png')
.should.become( mydir + '/abc.png')
.then(function() {
var res;
try{
res = fs.readFileSync(mydir + '/abc.png', {encoding: 'base64'});
}catch(err){
// for 0.8
res = fs.readFileSync(mydir + '/abc.png');
}
var data = new Buffer(res, 'base64');
var img = imageinfo(data);
img.should.not.be.false;
img.format.should.equal('PNG');
img.width.should.not.equal(0);
img.height.should.not.equal(0);
})
.saveScreenshot( mydir + '/aaa')
.should.become( mydir + '/aaa.png')
.saveScreenshot(mydir + '/')
.should.eventually.match(/\/myscreenshot\/screenshot-\w+\.png$/)
.saveScreenshot()
.should.eventually.match(/\/screenshot-\w+\.png$/);
});
it('browser.<cookie methods>', function() {

@@ -241,5 +275,43 @@ return browser

it('browser.sleep', function() {
return browser.sleep(100).should.be.fulfilled;
return browser
.sleep(100).should.be.fulfilled
.sleep(100).should.be.fulfilled;
});
it('browser.noop', function() {
return browser
.noop().should.be.fulfilled
.sleep(100).should.be.fulfilled
.noop().should.be.fulfilled;
});
it('browser.chain (promise chain)', function() {
return browser
.chain().should.be.fulfilled
.chain().sleep(0).should.be.fulfilled;
});
it('browser.resolve', function() {
var deferred = Q.defer();
setTimeout(function() {
deferred.resolve('123');
}, 250);
return browser
.resolve(deferred.promise)
.noop()
.resolve(deferred.promise)
.should.become('123');
});
it('browser.getSessionId', function() {
return browser.getSessionId(100).should.eventually.have.length.above(0);
});
it('browser.setHttpTimeout', function() {
return browser
.setHttpTimeout(env.HTTP_TIMEOUT || 60000).should.be.fulfilled
.setHTTPInactivityTimeout(env.HTTP_TIMEOUT || 60000).should.be.fulfilled
.setHttpTimeout(env.HTTP_TIMEOUT).should.be.fulfilled;
});
it('err.inspect', function() {

@@ -246,0 +318,0 @@ return browser

@@ -270,4 +270,57 @@ require('../helpers/setup');

// todo: add test for other suffixed methods
express.partials['element.sleep'] =
'<div id="theDiv"></div>\n' +
it('element.sleep', function() {
return browser
.setImplicitWaitTimeout(0)
.elementById("theDiv").then(function(el) {
return el
.sleep(100).should.be.fulfilled
.sleep(100).should.be.fulfilled;
});
});
express.partials['element.noop'] =
'<div id="theDiv"></div>\n' +
it('element.noop', function() {
return browser
.setImplicitWaitTimeout(0)
.elementById("theDiv").then(function(el) {
return el
.noop().should.be.fulfilled
.sleep(100).should.be.fulfilled
.noop().should.be.fulfilled;
});
});
express.partials['element.chain (promise)'] =
'<div id="theDiv"></div>\n' +
it('element.chain (promise)', function() {
return browser
.setImplicitWaitTimeout(0)
.elementById("theDiv").then(function(el) {
return el
.chain().should.be.fulfilled
.chain()
.sleep(100).should.be.fulfilled;
});
});
express.partials['element.resolve'] =
'<div id="theDiv"></div>\n' +
it('element.resolve', function() {
var deferred = Q.defer();
setTimeout(function() {
deferred.resolve('123');
}, 250);
return browser
.setImplicitWaitTimeout(0)
.elementById("theDiv").then(function(el) {
return el
.resolve(deferred.promise)
.noop()
.resolve(deferred.promise)
.should.become('123');
});
});
});

@@ -15,3 +15,3 @@ require('../helpers/setup');

var typingPartial =
var keyingPartial =
'<div id="theDiv">\n' +

@@ -22,4 +22,4 @@ '<input></input>\n' +

express.partials['typing nothing'] = typingPartial;
it('typing nothing', function() {
express.partials['keying nothing'] = keyingPartial;
it('keying nothing', function() {
return browser

@@ -30,4 +30,4 @@ .elementByCss("#theDiv input").type("").getValue().should.become("")

express.partials['typing []'] = typingPartial;
it('typing []', function() {
express.partials['keying []'] = keyingPartial;
it('keying []', function() {
return browser

@@ -38,4 +38,4 @@ .elementByCss("#theDiv input").type([]).getValue().should.become("")

express.partials['typing \'Hello\''] = typingPartial;
it('typing \'Hello\'', function() {
express.partials['keying \'Hello\''] = keyingPartial;
it('keying \'Hello\'', function() {
return browser

@@ -48,4 +48,4 @@ .elementByCss("#theDiv input").type('Hello')

express.partials['typing [\'Hello\']'] = typingPartial;
it('typing [\'Hello\']', function() {
express.partials['keying [\'Hello\']'] = keyingPartial;
it('keying [\'Hello\']', function() {
return browser

@@ -56,4 +56,4 @@ .elementByCss("#theDiv input").type(['Hello']).getValue().should.become('Hello')

express.partials['typing [\'Hello\',\' \',\'World\',\'!\']'] = typingPartial;
it('typing [\'Hello\',\' \',\'World\',\'!\']', function() {
express.partials['keying [\'Hello\',\' \',\'World\',\'!\']'] = keyingPartial;
it('keying [\'Hello\',\' \',\'World\',\'!\']', function() {
return browser

@@ -66,4 +66,4 @@ .elementByCss("#theDiv input").type(['Hello', ' ', 'World', '!'])

express.partials['typing \'Hello\\n\''] = typingPartial;
it('typing \'Hello\\n\'', function() {
express.partials['keying \'Hello\\n\''] = keyingPartial;
it('keying \'Hello\\n\'', function() {
return browser

@@ -76,4 +76,4 @@ .elementByCss("#theDiv input").type('Hello\n')

express.partials['typing \'\\r\''] = typingPartial;
it('typing \'\\r\'', function() {
express.partials['keying \'\\r\''] = keyingPartial;
it('keying \'\\r\'', function() {
return browser

@@ -87,4 +87,4 @@ .elementByCss("#theDiv input").type(['Hello','\r'])

express.partials['typing [returnKey]'] = typingPartial;
it('typing [returnKey]', function() {
express.partials['keying [returnKey]'] = keyingPartial;
it('keying [returnKey]', function() {
return browser

@@ -97,4 +97,4 @@ .elementByCss("#theDiv input").type(['Hello', returnKey])

express.partials['typing [enterKey]'] = typingPartial;
it('typing [enterKey]', function() {
express.partials['keying [enterKey]'] = keyingPartial;
it('keying [enterKey]', function() {
return browser

@@ -107,4 +107,4 @@ .elementByCss("#theDiv input").type(['Hello', enterKey])

express.partials['typing [nullKey]'] = typingPartial;
it('typing [nullKey]', function() {
express.partials['keying [nullKey]'] = keyingPartial;
it('keying [nullKey]', function() {
return browser

@@ -119,4 +119,4 @@ .elementByCss("#theDiv input").type(['Hello', nullKey])

if(!env.SAUCE) { // alt key seems to have no effect
express.partials['typing [altKey]'] = typingPartial;
it('typing [altKey]', function() {
express.partials['keying [altKey]'] = keyingPartial;
it('keying [altKey]', function() {
return browser

@@ -123,0 +123,0 @@ .elementByCss("#theDiv input").type([altKey, 'Hello', altKey])

@@ -13,2 +13,3 @@ /* global sauceJobTitle, mergeDesired */

browser = wd.promiseChainRemote(env.REMOTE_CONFIG);
var sauceExtra = {

@@ -15,0 +16,0 @@ name: sauceJobTitle(this.runnable().parent.title),

@@ -1,1 +0,18 @@

require('../api-el-suffix-base').test(['ByClassName'],'by-class');
var partials = {
one: '<div id="theDiv"><div class="theClass">Hello World!</div></div>\n',
child: '<div class="theChild">a child</div>',
several:
'<div id="theDiv">\n' +
' <div class="theClass">Hello World!</div>\n' +
' <div class="theClass">Hello World!</div>\n' +
' <div class="theClass">Hello World!</div>\n' +
'</div>\n'
};
var criterias = {
valid: 'theClass',
invalid: 'theWrongClass',
child: 'theChild'
};
require('../api-el-suffix-base').test('ByClassName','by-class', partials, criterias);

@@ -1,1 +0,18 @@

require('../api-el-suffix-base').test(['ByCssSelector'],'by-css-sel');
var partials = {
one: '<div id="theDiv" class="theClass">Hello World!</div>\n',
child: '<div class="theChild">a child</div>',
several:
'<div id="theDiv">\n' +
' <div class="theClass">Hello World!</div>\n' +
' <div class="theClass">Hello World!</div>\n' +
' <div class="theClass">Hello World!</div>\n' +
'</div>\n'
};
var criterias = {
valid: '.theClass',
invalid: '.theWrongClass',
child: '.theChild'
};
require('../api-el-suffix-base').test('ByCssSelector','by-css-sel', partials, criterias);

@@ -1,1 +0,18 @@

require('../api-el-suffix-base').test(['ByCss'],'by-css');
var partials = {
one: '<div id="theDiv" class="theClass">Hello World!</div>\n',
child: '<div class="theChild">a child</div>',
several:
'<div id="theDiv">\n' +
' <div class="theClass">Hello World!</div>\n' +
' <div class="theClass">Hello World!</div>\n' +
' <div class="theClass">Hello World!</div>\n' +
'</div>\n'
};
var criterias = {
valid: '.theClass',
invalid: '.theWrongClass',
child: '.theChild'
};
require('../api-el-suffix-base').test('ByCss','by-css', partials, criterias);

@@ -1,1 +0,13 @@

require('../api-el-suffix-base').test(['ById'],'by-id');
var partials = {
one: '<div id="theDiv">Hello World!</div>\n',
child: '<div id="theChild">a child</div>',
several: '<div id="theDiv">Hello World!</div>\n'
};
var criterias = {
valid: 'theDiv',
invalid: 'theWrongDiv',
child: 'theChild'
};
require('../api-el-suffix-base').test('ById','by-id', partials, criterias);

@@ -1,1 +0,18 @@

require('../api-el-suffix-base').test(['ByLinkText'],'by-link');
var partials = {
one: '<div id="theDiv"><a>the link</a></div>\n',
child: '<div class="theChild"><a>the child link</a></div>',
several:
'<div id="theDiv">\n' +
' <div><a>the link</a></div>\n' +
' <div><a>the link</a></div>\n' +
' <div><a>the link</a></div>\n' +
'</div>\n'
};
var criterias = {
valid: 'the link',
invalid: 'the wrong link',
child: 'the child link'
};
require('../api-el-suffix-base').test('ByLinkText','by-link', partials, criterias);

@@ -1,1 +0,18 @@

require('../api-el-suffix-base').test(['ByName'],'by-name');
var partials = {
one: '<div name="theName">Hello World!</div>\n',
child: '<div name="theChildName">a child</div>',
several:
'<div id="theDiv">\n' +
' <div name="theName">Hello World!</div>\n' +
' <div name="theName">Hello World!</div>\n' +
' <div name="theName">Hello World!</div>\n' +
'</div>\n'
};
var criterias = {
valid: 'theName',
invalid: 'theWrongName',
child: 'theChildName'
};
require('../api-el-suffix-base').test('ByName','by-name', partials, criterias);

@@ -1,1 +0,18 @@

require('../api-el-suffix-base').test(['ByPartialLinkText'],'by-partial-link');
var partials = {
one: '<div id="theDiv"><a>click the link now</a></div>\n',
child: '<div class="theChild"><a>click the child link now</a></div>',
several:
'<div id="theDiv">\n' +
' <div><a>click the link now</a></div>\n' +
' <div><a>click the link now</a></div>\n' +
' <div><a>click the link now</a></div>\n' +
'</div>\n'
};
var criterias = {
valid: 'the link',
invalid: 'the wrong link',
child: 'the child link'
};
require('../api-el-suffix-base').test('ByPartialLinkText','by-partial-link', partials, criterias);

@@ -1,1 +0,18 @@

require('../api-el-suffix-base').test(['ByTagName'],'by-tag-name');
var partials = {
one: '<div id="theDiv"><span>Hello World!</span></div>\n',
child: '<div><i>a child here</i></div>',
several:
'<div id="theDiv">\n' +
' <span>Hello World!</span>\n' +
' <span>Hello World!</span>\n' +
' <span>Hello World!</span>\n' +
'</div>\n'
};
var criterias = {
valid: 'span',
invalid: 'input',
child: 'i'
};
require('../api-el-suffix-base').test('ByTagName','by-tag-name', partials, criterias);

@@ -1,1 +0,18 @@

require('../api-el-suffix-base').test(['ByXPath'],'by-xpath');
var partials = {
one: '<div id="theDiv"/><input></div>\n',
child: '<div class="theChild"><a>a child</a></div>',
several:
'<div id="theDiv">\n' +
' <input>\n' +
' <input>\n' +
' <input>\n' +
'</div>\n'
};
var criterias = {
valid: "//div[@id='theDiv']/input",
invalid: "//div[@id='theInvalidDiv']/input",
child: "//div[@class='theChild']"
};
require('../api-el-suffix-base').test('ByXPath','by-xpath', partials, criterias);

@@ -5,113 +5,97 @@ var nock = require('nock');

describe("wd", function() {
describe("unit", function() {
describe("callback tests", function() {
var server;
server = null;
before(function(done) {
server = nock('http://127.0.0.1:5555').filteringRequestBody(/.*/, '*');
server.log(console.log);
server.post('/wd/hub/session', '*').reply(303, "OK", {
'Location': '/wd/hub/session/1234'
});
describe("async callback tests", function() {
var server, browser;
before(function(done) {
server = nock('http://127.0.0.1:5555').filteringRequestBody(/.*/, '*');
server.log(console.log);
server.post('/wd/hub/session', '*').reply(303, "OK", {
'Location': '/wd/hub/session/1234'
});
browser = wd.remote({
port: 5555
});
browser.init({}, function(err) {
should.not.exist(err);
done(null);
});
});
describe("simplecallback with empty return", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, "");
browser.get("www.google.com", function(err) {
should.not.exist(err);
done(null);
});
describe("simplecallback empty returns", function() {
var browser;
browser = null;
describe("browser initialization", function() {
it("should initialize browser", function(done) {
browser = wd.remote({
port: 5555
});
browser.init({}, function(err) {
should.not.exist(err);
done(null);
});
});
});
describe("simplecallback with empty return", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, "");
browser.get("www.google.com", function(err) {
should.not.exist(err);
done(null);
});
});
});
describe("simplecallback with 200 OK", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, "OK");
browser.get("www.google.com", function(err) {
should.not.exist(err);
done(null);
});
});
});
describe("simplecallback with empty JSON data", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, '{"sessionId":"1234","status":0,"value":{}}');
browser.get("www.google.com", function(err) {
should.not.exist(err);
done(null);
});
});
});
});
});
describe("simplecallback with 200 OK", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, "OK");
browser.get("www.google.com", function(err) {
should.not.exist(err);
done(null);
});
});
});
describe("promise tests", function() {
// all the tests below should be resolved, so the resolved handler
// calls done() to pass and the rejected handler calls done(err) to fail
var server;
server = null;
before(function(done) {
server = nock('http://127.0.0.1:5555').filteringRequestBody(/.*/, '*');
server.log(console.log);
server.post('/wd/hub/session', '*').reply(303, "OK", {
'Location': '/wd/hub/session/1234'
});
describe("simplecallback with empty JSON data", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, '{"sessionId":"1234","status":0,"value":{}}');
browser.get("www.google.com", function(err) {
should.not.exist(err);
done(null);
});
describe("simplepromise empty returns", function() {
var browser;
browser = null;
describe("browser initialization", function() {
it("should initialize browser", function(done) {
browser = wd.promiseChainRemote({
port: 5555
});
browser.init({}).then(
function() { done(null); },
function(err) { done(err); });
});
});
describe("simplepromsie with empty return", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, "");
browser.get("www.google.com").then(
function() { done(null); },
function(err) { done(err); });
});
});
describe("simplepromise with 200 OK", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, "OK");
browser.get("www.google.com").then(
function() { done(null); },
function(err) { done(err); });
});
});
describe("simplepromise with empty JSON data", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, '{"sessionId":"1234","status":0,"value":{}}');
browser.get("www.google.com").then(
function() { done(null); },
function(err) { done(err); });
});
});
});
});
});
describe("promise tests", function() {
// all the tests below should be resolved, so the resolved handler
// calls done() to pass and the rejected handler calls done(err) to fail
var server, browser;
before(function(done) {
server = nock('http://127.0.0.1:5555').filteringRequestBody(/.*/, '*');
server.log(console.log);
server.post('/wd/hub/session', '*').reply(303, "OK", {
'Location': '/wd/hub/session/1234'
});
browser = wd.promiseChainRemote({
port: 5555
});
browser.init({}).then(
function() { done(null); },
function(err) { done(err); });
});
describe("simplepromise empty returns", function() {
describe("simplepromsie with empty return", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, "");
browser.get("www.google.com").then(
function() { done(null); },
function(err) { done(err); });
});
});
describe("simplepromise with 200 OK", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, "OK");
browser.get("www.google.com").then(
function() { done(null); },
function(err) { done(err); });
});
});
describe("simplepromise with empty JSON data", function() {
it("should get url", function(done) {
server.post('/wd/hub/session/1234/url', '*').reply(200, '{"sessionId":"1234","status":0,"value":{}}');
browser.get("www.google.com").then(
function() { done(null); },
function(err) { done(err); });
});
});
});
});
var url = require('url');
require('../helpers/setup');
describe("wd", function() {
describe("local", function() {
describe("wd remote tests", function() {
describe("default", function() {
it("browser should be initialized with default parameters", function(done) {
var browser;
browser = wd.remote();
browser.configUrl.hostname.should.equal('127.0.0.1');
browser.configUrl.port.should.equal('4444');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done();
});
});
describe("url string", function() {
it("browser should be initialized with: http url", function(done) {
var browser;
browser = wd.remote('http://localhost:8888/wd/hub');
browser.configUrl.protocol.should.equal('http:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: https url", function(done) {
var browser;
browser = wd.remote('https://localhost:8888/wd/hub');
browser.configUrl.protocol.should.equal('https:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: http url, auth", function(done) {
var browser;
browser = wd.remote('http://mickey:mouse@localhost:8888/wd/hub');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
});
describe("url object", function() {
it("browser should be initialized with: http url", function(done) {
var browser;
browser = wd.remote(url.parse('http://localhost:8888/wd/hub'));
browser.configUrl.protocol.should.equal('http:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: https url", function(done) {
var browser;
browser = wd.remote(url.parse('https://localhost:8888/wd/hub'));
browser.configUrl.protocol.should.equal('https:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: http url, auth", function(done) {
var browser;
browser = wd.remote(url.parse('http://mickey:mouse@localhost:8888/wd/hub'));
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
});
describe("params", function() {
it("browser should be initialized with: host, port", function(done) {
var browser;
browser = wd.remote('localhost', 8888);
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: host, port, user, pwd", function(done) {
var browser;
browser = wd.remote('localhost', '8888', 'mickey', 'mouse');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
});
describe("wd remote tests", function() {
describe("default", function() {
it("browser should be initialized with default parameters", function(done) {
var browser;
browser = wd.remote();
browser.configUrl.hostname.should.equal('127.0.0.1');
browser.configUrl.port.should.equal('4444');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done();
});
describe("options", function() {
it("browser should be initialized with default", function(done) {
var browser;
browser = wd.remote({});
browser.configUrl.hostname.should.equal('127.0.0.1');
browser.configUrl.port.should.equal('4444');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: hostname, port", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888
});
browser.configUrl.protocol.should.equal('http:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: protocol, hostname, port", function(done) {
var browser;
browser = wd.remote({
protocol: 'https:',
hostname: 'localhost',
port: '8888'
});
browser.configUrl.protocol.should.equal('https:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: host", function(done) {
var browser;
browser = wd.remote({
host: 'localhost:8888',
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: hostname, port, user, pwd", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888,
user: 'mickey',
pwd: 'mouse'
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
it("browser should be initialized with: hostname, port, user, pwd", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888,
auth: 'mickey:mouse',
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
it("browser should be initialized with: path", function(done) {
var browser;
browser = wd.remote({
pathname: '/taiwan'
});
browser.configUrl.hostname.should.equal('127.0.0.1');
browser.configUrl.port.should.equal('4444');
browser.configUrl.pathname.should.equal('/taiwan');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: hostname, port, path", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888,
pathname: '/'
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: hostname, port, username, user, pwd", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888,
user: 'mickey',
pwd: 'mouse',
pathname: '/asia/taiwan'
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/asia/taiwan');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
});
describe("url string", function() {
it("browser should be initialized with: http url", function(done) {
var browser;
browser = wd.remote('http://localhost:8888/wd/hub');
browser.configUrl.protocol.should.equal('http:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
describe("automatic Saucelabs config", function() {
before(function() {
process.env.SAUCE_USERNAME = 'zorro';
process.env.SAUCE_ACCESS_KEY = '1234-5678';
});
after(function() {
delete process.env.SAUCE_USERNAME;
delete process.env.SAUCE_ACCESS_KEY;
});
it("browser should be initialized with indexed parameters", function(done) {
var browser;
browser = wd.remote('ondemand.saucelabs.com', 80);
browser.configUrl.hostname.should.equal('ondemand.saucelabs.com');
browser.configUrl.port.should.equal('80');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('zorro:1234-5678');
done();
});
it("browser should be initialized with named parameters", function(done) {
var browser;
browser = wd.remote({
hostname: 'ondemand.saucelabs.com',
port:80 });
browser.configUrl.hostname.should.equal('ondemand.saucelabs.com');
browser.configUrl.port.should.equal('80');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('zorro:1234-5678');
done();
});
it("browser should be initialized with url string", function(done) {
var browser;
browser = wd.remote('http://ondemand.saucelabs.com/wd/hub');
browser.configUrl.hostname.should.equal('ondemand.saucelabs.com');
(browser.configUrl.port || '80').should.equal('80');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('zorro:1234-5678');
done();
});
it("browser should be initialized with url object", function(done) {
var browser;
browser = wd.remote(url.parse('http://ondemand.saucelabs.com/wd/hub'));
browser.configUrl.hostname.should.equal('ondemand.saucelabs.com');
(browser.configUrl.port || '80').should.equal('80');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('zorro:1234-5678');
done();
});
it("browser should be initialized with: https url", function(done) {
var browser;
browser = wd.remote('https://localhost:8888/wd/hub');
browser.configUrl.protocol.should.equal('https:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
describe("backward compatibility", function() {
it("browser should be initialized with: host, port", function(done) {
var browser;
browser = wd.remote({
host: 'localhost',
port: 8888
});
browser.configUrl.protocol.should.equal('http:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: https, host, port", function(done) {
var browser;
browser = wd.remote({
https: true,
host: 'localhost',
port: 8888
});
browser.configUrl.protocol.should.equal('https:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: host, port, username, accesskey", function(done) {
var browser;
browser = wd.remote({
host: 'localhost',
port: 8888,
username: 'mickey',
accessKey: 'mouse'
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
it("browser should be initialized with: path", function(done) {
var browser;
browser = wd.remote({
path: '/taiwan'
});
browser.configUrl.hostname.should.equal('127.0.0.1');
browser.configUrl.port.should.equal('4444');
browser.configUrl.pathname.should.equal('/taiwan');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: http url, auth", function(done) {
var browser;
browser = wd.remote('http://mickey:mouse@localhost:8888/wd/hub');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
});
describe("url object", function() {
it("browser should be initialized with: http url", function(done) {
var browser;
browser = wd.remote(url.parse('http://localhost:8888/wd/hub'));
browser.configUrl.protocol.should.equal('http:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: https url", function(done) {
var browser;
browser = wd.remote(url.parse('https://localhost:8888/wd/hub'));
browser.configUrl.protocol.should.equal('https:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: http url, auth", function(done) {
var browser;
browser = wd.remote(url.parse('http://mickey:mouse@localhost:8888/wd/hub'));
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
});
describe("params", function() {
it("browser should be initialized with: host, port", function(done) {
var browser;
browser = wd.remote('localhost', 8888);
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: host, port, user, pwd", function(done) {
var browser;
browser = wd.remote('localhost', '8888', 'mickey', 'mouse');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
});
});
describe("options", function() {
it("browser should be initialized with default", function(done) {
var browser;
browser = wd.remote({});
browser.configUrl.hostname.should.equal('127.0.0.1');
browser.configUrl.port.should.equal('4444');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: hostname, port", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888
});
browser.configUrl.protocol.should.equal('http:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: protocol, hostname, port", function(done) {
var browser;
browser = wd.remote({
protocol: 'https:',
hostname: 'localhost',
port: '8888'
});
browser.configUrl.protocol.should.equal('https:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: host", function(done) {
var browser;
browser = wd.remote({
host: 'localhost:8888',
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: hostname, port, user, pwd", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888,
user: 'mickey',
pwd: 'mouse'
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
it("browser should be initialized with: hostname, port, user, pwd", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888,
auth: 'mickey:mouse',
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
it("browser should be initialized with: path", function(done) {
var browser;
browser = wd.remote({
pathname: '/taiwan'
});
browser.configUrl.hostname.should.equal('127.0.0.1');
browser.configUrl.port.should.equal('4444');
browser.configUrl.pathname.should.equal('/taiwan');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: hostname, port, path", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888,
pathname: '/'
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: hostname, port, username, user, pwd", function(done) {
var browser;
browser = wd.remote({
hostname: 'localhost',
port: 8888,
user: 'mickey',
pwd: 'mouse',
pathname: '/asia/taiwan'
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/asia/taiwan');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
});
describe("automatic Saucelabs config", function() {
before(function() {
process.env.SAUCE_USERNAME = 'zorro';
process.env.SAUCE_ACCESS_KEY = '1234-5678';
});
after(function() {
delete process.env.SAUCE_USERNAME;
delete process.env.SAUCE_ACCESS_KEY;
});
it("browser should be initialized with indexed parameters", function(done) {
var browser;
browser = wd.remote('ondemand.saucelabs.com', 80);
browser.configUrl.hostname.should.equal('ondemand.saucelabs.com');
browser.configUrl.port.should.equal('80');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('zorro:1234-5678');
done();
});
it("browser should be initialized with named parameters", function(done) {
var browser;
browser = wd.remote({
hostname: 'ondemand.saucelabs.com',
port:80 });
browser.configUrl.hostname.should.equal('ondemand.saucelabs.com');
browser.configUrl.port.should.equal('80');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('zorro:1234-5678');
done();
});
it("browser should be initialized with url string", function(done) {
var browser;
browser = wd.remote('http://ondemand.saucelabs.com/wd/hub');
browser.configUrl.hostname.should.equal('ondemand.saucelabs.com');
(browser.configUrl.port || '80').should.equal('80');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('zorro:1234-5678');
done();
});
it("browser should be initialized with url object", function(done) {
var browser;
browser = wd.remote(url.parse('http://ondemand.saucelabs.com/wd/hub'));
browser.configUrl.hostname.should.equal('ondemand.saucelabs.com');
(browser.configUrl.port || '80').should.equal('80');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('zorro:1234-5678');
done();
});
});
describe("backward compatibility", function() {
it("browser should be initialized with: host, port", function(done) {
var browser;
browser = wd.remote({
host: 'localhost',
port: 8888
});
browser.configUrl.protocol.should.equal('http:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: https, host, port", function(done) {
var browser;
browser = wd.remote({
https: true,
host: 'localhost',
port: 8888
});
browser.configUrl.protocol.should.equal('https:');
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
should.not.exist(browser.configUrl.auth);
done(null);
});
it("browser should be initialized with: host, port, username, accesskey", function(done) {
var browser;
browser = wd.remote({
host: 'localhost',
port: 8888,
username: 'mickey',
accessKey: 'mouse'
});
browser.configUrl.hostname.should.equal('localhost');
browser.configUrl.port.should.equal('8888');
browser.configUrl.pathname.should.equal('/wd/hub');
browser.configUrl.auth.should.equal('mickey:mouse');
done(null);
});
it("browser should be initialized with: path", function(done) {
var browser;
browser = wd.remote({
path: '/taiwan'
});
browser.configUrl.hostname.should.equal('127.0.0.1');
browser.configUrl.port.should.equal('4444');
browser.configUrl.pathname.should.equal('/taiwan');
should.not.exist(browser.configUrl.auth);
done(null);
});
});

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 too big to display

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