Skip to content

Commit

Permalink
enhance: wait for element
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed May 4, 2021
1 parent 89fccdd commit fdd280f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
14 changes: 0 additions & 14 deletions .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
sudo: false
node_js:
- 8
- 12
script:
- npm i
- npm run build:doc
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "macaca-wd",
"version": "3.3.2",
"version": "3.3.3",
"description": "Macaca wd client",
"keywords": [
"macaca",
"webdriver",
"wd"
],
"files": [
"lib/**/*.js",
"wd/lib/**/*.js"
],
"main": "./lib/macaca-wd.js",
"repository": {
"type": "git",
Expand Down
17 changes: 9 additions & 8 deletions wd/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,15 +844,14 @@ commands.hasElement = function(using, value){
* opts with the following fields: timeout, pollFreq, asserter.
* asserter like: function(browser , cb) -> cb(err, satisfied, return_value)
*/
commands.waitFor = function(){
commands.waitFor = function() {
var cb = findCallback(arguments);
var fargs = utils.varargs(arguments);
var opts;
// retrieving options
if(typeof fargs.all[0] === 'object' && !(fargs.all[0] instanceof Asserter)){
if (typeof fargs.all[0] === 'object' && !(fargs.all[0] instanceof Asserter)) {
opts = fargs.all[0];
} else
{
} else {
opts = {
asserter: fargs.all[0],
timeout: fargs.all[1],
Expand All @@ -864,15 +863,17 @@ commands.waitFor = function(){
opts.timeout = opts.timeout || 1000;
opts.pollFreq = opts.pollFreq || 200;

if(!opts.asserter) { throw new Error('Missing asserter!'); }
if(!opts.asserter) {
throw new Error('Missing asserter!');
}

var _this = this;
var endTime = Date.now() + opts.timeout;

var unpromisedAsserter = new Asserter(
function(browser, cb) {
var promise = opts.asserter.assert(browser, cb);
if(promise && promise.then && typeof promise.then === 'function'){
if (promise && promise.then && typeof promise.then === 'function') {
promise.then(
function(res) { cb(null, true, res); },
function(err) {
Expand Down Expand Up @@ -913,7 +914,7 @@ commands.waitFor = function(){
* opts with the following fields: timeout, pollFreq, asserter.
* asserter like: function(element , cb) -> cb(err, satisfied, el)
*/
commands.waitForElement = function(){
commands.waitForElement = function() {

var cb = findCallback(arguments);
var fargs = utils.varargs(arguments);
Expand All @@ -922,7 +923,7 @@ commands.waitForElement = function(){
var opts;

// retrieving options
if(typeof fargs.all[2] === 'object' && !(fargs.all[2] instanceof Asserter)){
if (typeof fargs.all[2] === 'object' && !(fargs.all[2] instanceof Asserter)) {
opts = fargs.all[2];
} else if(fargs.all[2] instanceof Asserter) {
opts = {
Expand Down

0 comments on commit fdd280f

Please sign in to comment.