Comparing version 0.0.20 to 0.0.21
@@ -42,3 +42,3 @@ var EventEmitter = require('events').EventEmitter; | ||
}); | ||
return ((jsonwireError.length>0) ? jsonwireError[0] : null); | ||
return ((jsonwireError.length>0) ? jsonwireError[0] : null); | ||
}; | ||
@@ -51,3 +51,3 @@ | ||
err[k] = opts[k] | ||
} | ||
} | ||
// nicer error output | ||
@@ -63,3 +63,3 @@ err.inspect = function() { | ||
if ((v["class"] != null) && v["class"].match(/org.openqa.selenium.remote.Response/)) { | ||
// for selenium classes, hidding long fields or field with | ||
// for selenium classes, hidding long fields or field with | ||
// duplicate information | ||
@@ -77,4 +77,4 @@ var vAsStr = JSON.stringify(v, function(key, value) { | ||
} | ||
}, " "); | ||
res += k + ": " + vAsStr + "\n"; | ||
}, " "); | ||
res += k + ": " + vAsStr + "\n"; | ||
} else { | ||
@@ -87,3 +87,3 @@ // for other objects making sure output is not too long | ||
} | ||
res += k + ": " + vAsStr + "\n"; | ||
res += k + ": " + vAsStr + "\n"; | ||
} | ||
@@ -98,6 +98,6 @@ } else if (typeof v != 'function') | ||
if(browserError != null){ | ||
res += "browser-error: " + browserError + "\n"; | ||
res += "browser-error: " + browserError + "\n"; | ||
} | ||
return res; | ||
}; | ||
}; | ||
return err; | ||
@@ -108,7 +108,7 @@ }; | ||
var _ref; | ||
if ((typeof res !== "undefined" && res !== null ? | ||
(_ref = res["class"]) != null ? _ref.indexOf('WebDriverException') : | ||
if ((typeof res !== "undefined" && res !== null ? | ||
(_ref = res["class"]) != null ? _ref.indexOf('WebDriverException') : | ||
void 0 : void 0) > 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
@@ -129,7 +129,7 @@ } | ||
if(data == '') { | ||
// expected behaviour | ||
// expected behaviour | ||
return cb() | ||
} else { | ||
// something wrong | ||
if(cb!=null){ | ||
if(cb!=null){ | ||
return cb(new Error( | ||
@@ -170,6 +170,6 @@ {message:'Unexpected data in simpleCallback.', data:data}) ); | ||
var err = _this._newError( | ||
{message:'Error response status.',status:obj.status,cause:obj}); | ||
{message:'Error response status.',status:obj.status,cause:obj}); | ||
var jsonwireError = _this._getJsonwireError(obj.status); | ||
if(jsonwireError != null){ err['jsonwire-error'] = jsonwireError; } | ||
cb(err); | ||
cb(err); | ||
} else { | ||
@@ -217,3 +217,3 @@ cb(null, obj); | ||
if(_this._isWebDriverException(obj.value)) {return cb(_this._newError( | ||
{message:obj.value.message,cause:obj.value}));} | ||
{message:obj.value.message,cause:obj.value}));} | ||
if (!(obj.value instanceof Array)) {return cb(_this._newError( | ||
@@ -314,3 +314,3 @@ {message:"Response value field is not an Array.", cause:obj.value}));} | ||
var _this = this; | ||
// http options init | ||
@@ -380,3 +380,3 @@ var httpOpts = _this._newHttpOpts.apply(_this, [opts.method]); | ||
} | ||
webdriver.prototype.chain = function(){ | ||
@@ -470,3 +470,3 @@ var _this = this; | ||
code = "return " + code + ";" | ||
this.execute.apply( this, [code, function(err, res) { | ||
this.execute.apply( this, [code, function(err, res) { | ||
if(err!=null) {return cb(err);} | ||
@@ -478,3 +478,3 @@ cb(null, res); | ||
webdriver.prototype.safeEval = function(code, cb) { | ||
this.safeExecute.apply( this, [code, function(err, res) { | ||
this.safeExecute.apply( this, [code, function(err, res) { | ||
if(err!=null) {return cb(err);} | ||
@@ -488,7 +488,7 @@ cb(null, res); | ||
var _args, _i; | ||
_args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_i = arguments.length - 1) : (_i = 0, []), cb = arguments[_i++]; | ||
code = _args[0], args = _args[1]; | ||
//args default | ||
//args default | ||
if (typeof args === "undefined" || args === null) { | ||
@@ -501,4 +501,4 @@ args = []; | ||
, relPath: '/execute' | ||
, cb: this._callbackWithData(cb) | ||
, data: {script: code, args: args} | ||
, cb: this._callbackWithData(cb) | ||
, data: {script: code, args: args} | ||
}); | ||
@@ -513,7 +513,7 @@ } | ||
var _args, _i; | ||
_args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_i = arguments.length - 1) : (_i = 0, []), cb = arguments[_i++]; | ||
code = _args[0], args = _args[1]; | ||
//args default | ||
//args default | ||
if (typeof args === "undefined" || args === null) { | ||
@@ -534,7 +534,7 @@ args = []; | ||
var _args, _i; | ||
_args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_i = arguments.length - 1) : (_i = 0, []), cb = arguments[_i++]; | ||
code = _args[0], args = _args[1]; | ||
//args default | ||
//args default | ||
if (typeof args === "undefined" || args === null) { | ||
@@ -558,7 +558,7 @@ args = []; | ||
var _args, _i; | ||
_args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_i = arguments.length - 1) : (_i = 0, []), cb = arguments[_i++]; | ||
code = _args[0], args = _args[1]; | ||
//args default | ||
//args default | ||
if (typeof args === "undefined" || args === null) { | ||
@@ -633,3 +633,3 @@ args = []; | ||
method: 'POST' | ||
, relPath: '/timeouts/timeouts' | ||
, relPath: '/timeouts' | ||
, data: {type: 'page load', ms: ms} | ||
@@ -651,3 +651,3 @@ , cb: this._simpleCallback(cb) | ||
webdriver.prototype.elementOrNull = function(using, value, cb) { | ||
this.elements.apply(this, [using, value, | ||
this.elements.apply(this, [using, value, | ||
function(err, elements) { | ||
@@ -664,3 +664,3 @@ if(err == null) | ||
webdriver.prototype.elementIfExists = function(using, value, cb) { | ||
this.elements.apply(this, [using, value, | ||
this.elements.apply(this, [using, value, | ||
function(err, elements) { | ||
@@ -693,5 +693,13 @@ if(err == null) | ||
webdriver.prototype.takeScreenshot = function(cb) { | ||
this._jsonWireCall({ | ||
method: 'GET' | ||
, relPath: '/screenshot' | ||
, cb: this._callbackWithData(cb) | ||
}); | ||
} | ||
// convert to type to something like ById, ByCssSelector, etc... | ||
var elFuncSuffix = function(type){ | ||
var res = (' by ' + type).replace(/(\s[a-z])/g, | ||
var res = (' by ' + type).replace(/(\s[a-z])/g, | ||
function($1){return $1.toUpperCase().replace(' ','');}); | ||
@@ -708,3 +716,3 @@ return res.replace('Xpath', 'XPath'); | ||
// from JsonWire spec + shortcuts | ||
var elementFuncTypes = ['class name', 'css selector','id','name','link text', | ||
var elementFuncTypes = ['class name', 'css selector','id','name','link text', | ||
'partial link text','tag name', 'xpath', 'css' ]; | ||
@@ -714,3 +722,3 @@ | ||
for (var i = 0; i < elementFuncTypes.length; i++) { | ||
for (var i = 0; i < elementFuncTypes.length; i++) { | ||
@@ -723,6 +731,6 @@ (function() { | ||
}; | ||
// avoid not found exception and return null instead | ||
webdriver.prototype['element' + elFuncSuffix(type)+ 'OrNull'] = function(value, cb) { | ||
webdriver.prototype.elements.apply(this, [elFuncFullType(type), value, | ||
webdriver.prototype.elements.apply(this, [elFuncFullType(type), value, | ||
function(err, elements) { | ||
@@ -739,3 +747,3 @@ if(err == null) | ||
webdriver.prototype['element' + elFuncSuffix(type)+ 'IfExists'] = function(value, cb) { | ||
webdriver.prototype.elements.apply(this, [elFuncFullType(type), value, | ||
webdriver.prototype.elements.apply(this, [elFuncFullType(type), value, | ||
function(err, elements) { | ||
@@ -757,5 +765,5 @@ if(err == null) | ||
}; | ||
})(); | ||
} | ||
@@ -779,3 +787,3 @@ | ||
, relPath: '/element/' + element + '/click' | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -795,7 +803,7 @@ } | ||
var args, _i; | ||
element = arguments[0], args = 3 <= arguments.length ? | ||
__slice.call(arguments, 1, _i = arguments.length - 1) : | ||
(_i = 1, []), cb = arguments[_i++]; | ||
element = arguments[0], args = 3 <= arguments.length ? | ||
__slice.call(arguments, 1, _i = arguments.length - 1) : | ||
(_i = 1, []), cb = arguments[_i++]; | ||
xoffset = args[0], yoffset = args[1], args; | ||
this._jsonWireCall({ | ||
@@ -805,3 +813,3 @@ method: 'POST' | ||
, data: { element: element.toString(), xoffset: xoffset, yoffset: yoffset } | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -814,3 +822,3 @@ } | ||
, relPath: '/buttondown' | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -823,3 +831,3 @@ } | ||
, relPath: '/buttonup' | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -839,3 +847,3 @@ } | ||
, data: {button: button} | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -848,3 +856,3 @@ } | ||
, relPath: '/doubleclick' | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -860,3 +868,3 @@ } | ||
, data: {value: keys} | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -871,3 +879,3 @@ } | ||
, data: {value: keys} | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -880,3 +888,3 @@ } | ||
, relPath: '/element/' + element + '/clear' | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -929,3 +937,3 @@ } | ||
, relPath: '/accept_alert' | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -938,8 +946,8 @@ } | ||
, relPath: '/dismiss_alert' | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
} | ||
webdriver.prototype.active = function(cb) { | ||
var _this = this; | ||
webdriver.prototype.active = function(cb) { | ||
var _this = this; | ||
var cbWrap = function(e, o) { | ||
@@ -989,3 +997,3 @@ var el = new element(o['ELEMENT'], _this); | ||
, data: { cookie: cookie } | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -998,3 +1006,3 @@ } | ||
, relPath: '/cookie' | ||
, cb: this._simpleCallback(cb) | ||
, cb: this._simpleCallback(cb) | ||
}); | ||
@@ -1056,2 +1064,27 @@ } | ||
webdriver.prototype.waitForVisible = function(queryType, querySelector, timeout, callback) { | ||
var _this = this; | ||
var endTime = Date.now() + timeout; | ||
var poll = function(){ | ||
_this.isVisible(queryType, querySelector, function(err, visible) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (visible) { | ||
callback(); | ||
} else { | ||
if (Date.now() > endTime) { | ||
callback(new Error("Element didn't become visible")); | ||
} else { | ||
setTimeout(poll, 200); | ||
} | ||
} | ||
}); | ||
} | ||
poll(); | ||
} | ||
// waitForCondition recursive implementation | ||
@@ -1069,8 +1102,8 @@ webdriver.prototype._waitForConditionImpl = function(conditionExpr, limit, poll, cb) { | ||
return cb(null, true); | ||
} else { | ||
} else { | ||
// wait for poll and try again | ||
setTimeout(function() { | ||
_this._waitForConditionImpl.apply(_this, [conditionExpr, limit, poll, cb]); | ||
}, poll); | ||
} | ||
}, poll); | ||
} | ||
}]); | ||
@@ -1085,4 +1118,4 @@ } else { | ||
// condition nok within timeout | ||
return cb("waitForCondition failure for: " + conditionExpr); | ||
} | ||
return cb("waitForCondition failure for: " + conditionExpr); | ||
} | ||
}]); | ||
@@ -1099,4 +1132,4 @@ } | ||
var args, cb, conditionExpr, limit, poll, timeout, _i; | ||
args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_i = arguments.length - 1) : (_i = 0, []), | ||
args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_i = arguments.length - 1) : (_i = 0, []), | ||
cb = arguments[_i++]; | ||
@@ -1123,4 +1156,4 @@ conditionExpr = args[0], timeout = args[1], poll = args[2]; | ||
var args, cb, conditionExpr, limit, poll, timeout, _i; | ||
args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_i = arguments.length - 1) : (_i = 0, []), | ||
args = 2 <= arguments.length ? __slice.call(arguments, 0, | ||
_i = arguments.length - 1) : (_i = 0, []), | ||
cb = arguments[_i++]; | ||
@@ -1132,11 +1165,11 @@ conditionExpr = args[0], timeout = args[1], poll = args[2]; | ||
poll = poll || 100; | ||
// calling script | ||
_this.safeExecuteAsync.apply( _this, [_this._waitForConditionInBrowserJsScript, | ||
[conditionExpr,timeout,poll], function(err,res) { | ||
_this.safeExecuteAsync.apply( _this, [_this._waitForConditionInBrowserJsScript, | ||
[conditionExpr,timeout,poll], function(err,res) { | ||
if(err != null) {return cb(err);} | ||
if(res != true) {return cb("waitForConditionInBrowser failure for: " + conditionExpr);} | ||
cb(null, res); | ||
if(res != true) {return cb("waitForConditionInBrowser failure for: " + conditionExpr);} | ||
cb(null, res); | ||
} | ||
]); | ||
}; |
@@ -1,6 +0,6 @@ | ||
{ | ||
{ | ||
"name" : "wd" | ||
, "description" : "WebDriver/Selenium 2 node.js client" | ||
, "tags" : ["web", "automation", "browser", "javascript"] | ||
, "version" : "0.0.20" | ||
, "version" : "0.0.21" | ||
, "author" : "Adam Christian <adam.christian@gmail.com>" | ||
@@ -23,6 +23,9 @@ , "repository" : | ||
,"should": "latest" | ||
,"coffee-script": "latest" | ||
,"express": "latest" | ||
,"gleak": "latest" | ||
,"coffee-script": "latest" | ||
,"express": "latest" | ||
,"gleak": "latest" | ||
} | ||
, "scripts" : { | ||
"test": "make test_saucelabs" | ||
} | ||
} |
# WD.js -- A light weight WebDriver/Se2 client for node.js | ||
[![Build Status](https://secure.travis-ci.org/admc/wd.png?branch=master)](http://travis-ci.org/admc/wd) | ||
## Update node to latest | ||
@@ -22,2 +24,3 @@ | ||
- Phil Sarin ([pdsarin](https://github.com/pdsarin)) | ||
- Mathieu Sabourin ([OniOni](https://github.com/OniOni)) | ||
@@ -24,0 +27,0 @@ ## License |
// Generated by CoffeeScript 1.3.3 | ||
(function() { | ||
var CoffeeScript, app, async, elementByCss, evalShouldEqual, executeCoffee, express, leakDetector, runTestWith, safeEvalShouldEqual, should, textShouldEqual, valueShouldEqual, wd; | ||
var CoffeeScript, app, async, elementByCss, evalShouldEqual, executeCoffee, express, imageinfo, leakDetector, runTestWith, safeEvalShouldEqual, should, textShouldEqual, valueShouldEqual, wd; | ||
@@ -13,2 +13,4 @@ should = require('should'); | ||
imageinfo = require('imageinfo'); | ||
leakDetector = (require('../common/leak-detector'))(); | ||
@@ -1160,2 +1162,15 @@ | ||
}, | ||
"takeScreenshot": function(test) { | ||
return browser.takeScreenshot(function(err, res) { | ||
var data, img; | ||
should.not.exist(err); | ||
data = new Buffer(res, 'base64'); | ||
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); | ||
return test.done(); | ||
}); | ||
}, | ||
"allCookies / setCookies / deleteAllCookies / deleteCookie": function(test) { | ||
@@ -1162,0 +1177,0 @@ return async.series([ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
277318
48
3463
619
1