forked from webdriverio/webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added isEnabled and elementIdEnabled commands
- Loading branch information
1 parent
3b93c76
commit 4a2e660
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* | ||
* Return true or false if the selected DOM-element found by given selector is enabled. | ||
* | ||
* <example> | ||
:index.html | ||
<input type="text" name="inputField" class="input1"> | ||
<input type="text" name="inputField" class="input2" disabled> | ||
<input type="text" name="inputField" class="input3" disabled="disabled"> | ||
:isVisible.js | ||
client | ||
.isEnabled('.input1', function(err, isEnabled) { | ||
console.log(isEnabled); // outputs: true | ||
}) | ||
.isEnabled('#input2', function(err, isEnabled) { | ||
console.log(isEnabled); // outputs: false | ||
}) | ||
.isEnabled('#input3', function(err, isEnabled) { | ||
console.log(isEnabled); // outputs: false | ||
}) | ||
* </example> | ||
* | ||
* @param {String} selector DOM-element | ||
* @returns {Boolean|Boolean[]} true if element(s)* (is|are) visible | ||
* | ||
* @uses protocol/elements, protocol/elementIdEnabled | ||
* @type state | ||
* | ||
*/ | ||
|
||
var async = require('async'), | ||
ErrorHandler = require('../utils/ErrorHandler.js'); | ||
|
||
module.exports = function isEnabled (selector) { | ||
|
||
/*! | ||
* make sure that callback contains chainit callback | ||
*/ | ||
var callback = arguments[arguments.length - 1]; | ||
|
||
/*! | ||
* parameter check | ||
*/ | ||
if(typeof selector !== 'string') { | ||
return callback(new ErrorHandler.CommandError('number or type of arguments don\'t agree with isEnabled command')); | ||
} | ||
|
||
var self = this, | ||
response = {}; | ||
|
||
async.waterfall([ | ||
function(cb) { | ||
self.elements(selector, cb); | ||
}, | ||
function(res, cb) { | ||
response.elements = res; | ||
response.elementIdEnabled = []; | ||
|
||
if(res.value.length === 0) { | ||
// throw NoSuchElement error if no element was found | ||
return callback(new ErrorHandler(7)); | ||
} | ||
|
||
async.eachSeries(res.value, function(val, seriesCallback) { | ||
self.elementIdEnabled(val.ELEMENT, function(err,res) { | ||
if(res) { | ||
response.elementIdEnabled.push(res); | ||
} | ||
|
||
seriesCallback(err); | ||
}); | ||
}, cb); | ||
} | ||
], function(err) { | ||
|
||
var value = null; | ||
|
||
if(response.elementIdEnabled && response.elementIdEnabled.length === 1) { | ||
|
||
value = response.elementIdEnabled[0].value; | ||
|
||
} else if(response.elementIdEnabled && response.elementIdEnabled.length > 1) { | ||
|
||
value = response.elementIdEnabled.map(function(res) { | ||
return res.value; | ||
}); | ||
|
||
} | ||
|
||
callback(err, value || false, response); | ||
|
||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* | ||
* Determine if an element is currently enabled. | ||
* | ||
* @param {String} ID ID of a WebElement JSON object to route the command to | ||
* @returns {Boolean} true if the element is enabled | ||
* | ||
* @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/enabled | ||
* @type protocol | ||
* | ||
*/ | ||
|
||
var ErrorHandler = require('../utils/ErrorHandler.js'); | ||
|
||
module.exports = function elementIdEnabled (id) { | ||
|
||
/*! | ||
* make sure that callback contains chainit callback | ||
*/ | ||
var callback = arguments[arguments.length - 1]; | ||
|
||
if(typeof id !== 'string' && typeof id !== 'number') { | ||
return callback(new ErrorHandler.ProtocolError('number or type of arguments don\'t agree with elementIdEnabled protocol command')); | ||
} | ||
|
||
this.requestHandler.create( | ||
'/session/:sessionId/element/:id/enabled'.replace(/:id/gi, id), | ||
callback | ||
); | ||
|
||
}; |