Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute.then is not a function #1150

Closed
tswaters opened this issue Mar 6, 2016 · 6 comments
Closed

execute.then is not a function #1150

tswaters opened this issue Mar 6, 2016 · 6 comments

Comments

@tswaters
Copy link

tswaters commented Mar 6, 2016

I copied the example verbatim from here: http://webdriver.io/api/protocol/execute.html

I'm using mocha framework, firefox as the browser. baseUrl is a file:// reference pointing at a html file in my fixtures directory. This is an empty html page.

C:\Code\snip>node_modules\.bin\wdio wdio.conf.js


=======================================================================================
Selenium 2.0 / webdriver protocol bindings implementation with helper commands in nodejs.
For a complete list of commands, visit http://webdriver.io/docs.html.
=======================================================================================

[23:19:12]  COMMAND     POST     "/wd/hub/session"
[23:19:12]  DATA                {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"browserName":"firefox","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.0.3","name":"webdriverio"}}}
[23:19:17]  SET SESSION ID 5b7e7fc0-9715-4132-a10c-16f91ce7562f
[23:19:17]  RESULT              {"applicationCacheEnabled":true,"rotatable":false,"handlesAlerts":true,"databaseEnabled":true,"version":"44.0.2","platform":"WINDOWS","nativeEvents":false,"acceptSslCerts":true,"webdriver.remote.sessionid":"5b7e7fc0-9715-4132-a10c-16f91ce7562f","webStorageEnabled":true,"locationContextEnabled":true,"browserName":"firefox","takesScreenshot":true,"javascriptEnabled":true,"cssSelectorsEnabled":true}
[23:19:17]  COMMAND     POST     "/wd/hub/session/5b7e7fc0-9715-4132-a10c-16f91ce7562f/url"
[23:19:17]  DATA                {"url":"file:///C:\\Code\\snip\\test\\fixtures/index.html"}
[23:19:17]  RESULT              null
[23:19:17]  COMMAND     POST     "/wd/hub/session/5b7e7fc0-9715-4132-a10c-16f91ce7562f/execute"
[23:19:17]  DATA                {"script":"return (function (a, b, c, d) {\r\n      // browser context - you may not access neither client nor console\r\n      return a + b + c + d;\r\n    }).apply(null, arguments)","args":[1,2,3,4]}
[23:19:18]  RESULT              10
.[23:19:18]  COMMAND    DELETE   "/wd/hub/session/5b7e7fc0-9715-4132-a10c-16f91ce7562f"
[23:19:18]  DATA                {}
[23:19:18]  RESULT              null

0 passing (12.10s)
1 failing

1) should run execute properly:
browser.execute(...).then is not a function
running firefox
TypeError: browser.execute(...).then is not a function
    at Context.<anonymous> (C:\Code\snip\test\integration\qq.test.js:16:20)
    at C:\Code\snip\node_modules\wdio-sync\build\index.js:569:24

Here is the wdio.conf.js

'use strict'

const path = require('path')

exports.config = {
  specs: [
    'test/integration/**/*.test.js'
  ],
  exclude: [
  ],
  capabilities: [
    {browserName: 'firefox'}
    //{browserName: 'chrome'}
  ],
  logLevel: 'verbose',
  coloredLogs: true,
  screenshotPath: './errorShots/',
  baseUrl: `file:///${path.resolve(process.cwd(), 'test/fixtures')}`,
  waitforTimeout: 10000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  framework: 'mocha',
  mochaOpts: {
    ui: 'bdd'
  }
}

And the test:

describe('webdriver.io page', () => {

  it('should run execute properly', () => {
    browser.execute(function(a, b, c, d) {
      // browser context - you may not access neither client nor console
      return a + b + c + d;
    }, 1, 2, 3, 4).then(function(ret) {
      // node.js context - client and console are available
      console.log(ret.value); // outputs: 10
    })
  })
})

I was able to retrieve the value by reworking it to:

describe('webdriver.io page', () => {

  it('should run execute properly', () => {
    const executeResult = browser.execute(function(a, b, c, d) {
      // browser context - you may not access neither client nor console
      return a + b + c + d;
    }, 1, 2, 3, 4)
    console.log(executeResult.value) // 10
  })
})

Are the docs out of date for this?

@christian-bromann
Copy link
Member

@tswaters yeah we are working on getting the website updated. In v4 all commands are synchronous if you are using wdio.

@daemon1981
Copy link

You need to set the property sync to false in your config file wdio.conf.js

exports.config = {
    ...
    sync: false,
    ...
}

@ltdangle
Copy link

Any timeframe estimate on documentation? It is really frustrating as the code from the current docs simply doesn't work.

@christian-bromann
Copy link
Member

We still have examples for standalone and wdio mode. It should be obvious which examples showing async and which is showing sync code. But we will get rid of all the async examples as we want that people use the wdio testrunner.

@ghost
Copy link

ghost commented Sep 20, 2017

Hi there,

I have an example like this.

console.log( "a" );
setTimeout(function() {
console.log( "b" )
}, 500 );
console.log( "c" );

I use mocha runner.
In the beginning, I used node v4.8.4. Console prints "a, b, c".
When I use node v6.4.0, console only prints "a, b". It seems that wdio doesn't execute the async part.

Is it a normal situation?
I should not have any async function in wdio v4.

@miggutie
Copy link

miggutie commented Dec 8, 2020

I am facing same issue, is there a solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants