1

In the acceptance test suite that I'm developing (featuring mocha, sinon and chai at the top of the stack), I am able to load a page in phantomjs and perform all sorts of operations according to the examples available around the web.

The only thing that eludes me is the retrieval of JS variables produced during the startup of the page. I am enclosing a complete example here that shows how the variable app cannot be tested, whereas jQuery can.

The only difference between the two is that app is produced by the run of a $(document).ready(function() {... create var app ...})

The error I get is maximum call stack exceeded (?!?!?!?)

What could I do to perform the check of app when this is available? Maybe something using promises? I can't see all this clearly(**).

Here is the error stack:

19:29:02.918 INFO [14] org.openqa.selenium.remote.server.DriverServlet - Executing: [execute script: return app, []] at URL: /session/73437950-3c14-4392-81ed-c6bd83c3f3fb/execute)
19:29:06.481 WARN [14] org.openqa.selenium.remote.server.DriverServlet - Exception thrown
org.openqa.selenium.WebDriverException: {"errorMessage":"Maximum call stack size exceeded.","request":{"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"33","Content-Type":"application/json; charset=utf-8","Host":"localhost:1693"},"httpVersion":"1.1","method":"POST","post":"{\"args\":[],\"script\":\"return app\"}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","queryKey":{},"chunks":["execute"]},"urlOriginal":"/session/9ca480b0-3c34-11e4-b1c7-0d43d6ab90ff/execute"}}
Command duration or timeout: 3.56 seconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'vagrant-xxx-yyyy', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-60-generic', java.version: '1.7.0_65'
Session ID: 9ca480b0-3c34-11e4-b1c7-0d43d6ab90ff
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{platform=LINUX, acceptSslCerts=false, javascriptEnabled=true, browserName=phantomjs, rotatable=false, driverVersion=1.1.0, locationContextEnabled=false, version=1.9.7, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=false, browserConnectionEnabled=false, webStorageEnabled=false, nativeEvents=true, proxy={proxyType=direct}, applicationCacheEnabled=false, driverName=ghostdriver, takesScreenshot=true}]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

Here is the test: getTitle, getTagName, getElementSize and execute('return jQuery') succeed; execute('return app')fails.

describe('AAA Test acceptance XXXXX', function(){
  var client = {}

  before(function(done) {
    client = webdriverjs.remote({
      desiredCapabilities: {
        browserName: 'phantomjs'
      },
    });
    client.init(done) // starts session and opens the browser
  });

  it('The merchant button',function(done){
    client.url('http://www.dev.xxxx.com/api/purchase/index.html')
    .getTitle(function(err,title){
      expect(err).to.be.null
      expect(title).to.have.string('Mobile Payment');
    })
    .getTagName('.merchant-div',function(err,tagName){
      expect(err).to.be.null
      expect(tagName).to.be.equal('div')
    })
    .getElementSize('#ms-input',function(err,size){
      expect(err).to.be.null
      expect(size.width).to.be.equal(184)
    })
    .execute('return jQuery', function(err,jquery) {
      expect(err).to.be.null
      expect(jquery).not.to.be.undefined
      expect(jquery).not.to.be.null
    })
    .execute('return app', function(err,appInstance) {
      expect(err).to.be.null
      expect(appInstance).not.to.be.undefined
      expect(appInstance).not.to.be.null
    })
    .call(done);
  })

  after(function(done) {
    client.end(done); // ends session and closes the browser
  })
});

(**) I already followed the instructions in Selenium WebDriver JS - Explicit Wait, but the error is Object #<WebdriverIO> has no method 'wait' (which makes perfect sense...)

Community
  • 1
  • 1
Marco Faustinelli
  • 3,734
  • 5
  • 30
  • 49
  • WebdriverIO wait commands are called differently - if you just want to wait an x amount of time use the [pause](http://webdriver.io/api/utility/pause.html) command, if you want to wait on some conditions check out the [waitFor](http://webdriver.io/api/utility/waitFor.html) commands – ChristianB Sep 22 '14 at 20:55
  • My take (am I right?) is that all those commands wait for something related to the DOM, whereas I only need to wait for a JS global variable to be set. I guess I'll put a createElement at the end of my init routine and wait for the appearance of that element from the test. – Marco Faustinelli Sep 23 '14 at 11:03

0 Answers0