mojotech / pioneer

Integration Testing
MIT License
527 stars 35 forks source link

pioneer this.driver.executeScript always returns an object {then: fn, cancel: fn, isPending: fn} instead of what is requested #294

Closed bitplanets closed 9 years ago

bitplanets commented 9 years ago

I have this script that looks like this:

this.When(/^I should be logged in$/, function(value){
    console.log('> ', this.driver.executeScript('return "test"'));
});

And the output of console.log is

>  { then: [Function: then],
  cancel: [Function: cancel],
  isPending: [Function: isPending] }

Instead of

"> test"

In the docs says that you receive a string for any other value. Why not?

bitplanets commented 9 years ago

Well this is the solution

    var result = this.driver.executeScript('return "test"');
    result.then(function(value){
        console.log(value)
    })

Because I think it uses async in order to communicate with the driver.

tomhicks-bsf commented 9 years ago

Almost everything the driver does is promise-based, and the promise object is what you're seeing when you console.log it. This is not something that pioneer can change as it's deferring to webdriver.

Also, you're looking at the wrong docs. You should be looking here: http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebDriver.html#executeScript

samccone commented 9 years ago

:+1: thats correct @tomhicks-bsf this is a proxy to webdriver

samccone commented 9 years ago

thanks for the help @tomhicks-bsf, appreciate it!

bitplanets commented 9 years ago

Thanks