webdriverio: Promise chain error

Promise chain error:

client
            .url(sid.url)
            .then(client.waitFor('.result', 5000))
            .then(client.getValue('#SSID'))
            .then(function(sid){
                 console.log('resolved', sid);  // here gets resolved ass [].length =4
                 return sid;                          // should be a SINGLE element     
             })

i guess in this last promise if the would be 10 calls to webdriverio the resolved promise would have array of 10 elements.

right now i workaround this by flattening an array.

respSid = _.isArray(respSid) ? _.first(respSid) : respSid;

help is very much appreciated

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 44 (14 by maintainers)

Most upvoted comments

WebdriverIO is based on ChainIt which takes care of the execution flow. If you execute a command it will put the request into a queue and executes it once all previous commands are done.

See this would’ve been very handy to have documented and clearly visible because it changes the way you build the tests completely. Since reading this it’s been much easier to work around the problems I was having.

Honestly I don’t know! I made some progress over the last couple of days. The new monadic structure is awesome. It returns a new webdriverio object after each call.

This sounds awesome, but it does look a lot like how the selenium-webdriver is doing it. What are the advantages in your way of doing things?

The Problem with the current solution is that promises get overwritten each time you call a new command because we are working on the same object over the whole session. Even if I would fix the issues on the PromiseHandler we would never be able to assign promises to an variable like in the example above.

Honestly, your monadic way looks very cool, but promises are amazing as well (when they work properly). You don’t usually assign promises to a variable like that, so I’m not sure that would be a problem. With promises you simply chain all the actions you want, using intermediate steps when necessary (using a .then statement for example).

All in all I’m looking forward to your progress, would be nice to be able to help you out on this. Do you have any plans on open sourcing this during development? Or will you wait until it’s finished?

I know it’s ugly but in these cases please make use of callbacks:

driver
    .getAttribute('.draggable-object', 'data-special', function(err, specialId){
        driver.dragAndDrop('.draggable-object[data-special="' + specialId + '"]', '.droppable-object[data-special2="' + specialModel[specialId] + "]');
    })
    .continueWithWhatever();