Question

I am having problems using any dojo modules with my functional test, I keep seeing window not defined errors or document not defined.

I am currently trying to use the dijit/registry like so (only importing its module so far)..

define([
    'intern!object',
    'intern/chai!assert',
    'require',
    'dijit/registry'
], function (registerSuite, assert, require, registry) {
    registerSuite({

        name: 'login',

        'load and login': function () {
            return this.remote.get(require.toUrl('http://application.co.uk/'))
                .elementById('input1')
                    .click()
                    .type("username")
                    .end()
                .elementById('input2')
                    .click()
                    .type("password")
                    .end()
                .elementById('rememberMe')
                    .click()
                    .end()
                .elementByName('Login.Submit')
                    .click()
                    .end()
                .wait(5000)
                .title()
                .then(function (title) {
                    assert.strictEqual(title, 'Application title');
                });
        }
    });
});

...and am getting the following error from node...

$ ./libs/intern/bin/intern-runner.js config=test/intern
Defaulting to "runner" reporter
Listening on 0.0.0.0:9000

c:/.../libs/dojo/_base/unload.js:6
var win = window;
          ^
ReferenceError: window is not defined
    at c:/.../libs/dojo/_base/unload.js:6:11
    at execModule (c:\...\libs\intern\node_modules\dojo\dojo.js:512:54)
    at c:\...\libs\intern\node_modules\dojo\dojo.js:501:12
    at Array.map (native)
    at execModule (c:\...\libs\intern\node_modules\dojo\dojo.js:496:17)
    at c:\...\libs\intern\node_modules\dojo\dojo.js:501:12
    at Array.map (native)
    at execModule (c:\...\libs\intern\node_modules\dojo\dojo.js:496:17)
    at c:\...\libs\intern\node_modules\dojo\dojo.js:501:12
    at Array.map (native)

I have read a previous question about using dojo/text! in a similar way which seemed to indicate the geezer version of Intern could handle this maybe?

The test runs fine without the registry module.

UPDATE

Ok so based on C Snover's response, you cant leverage anything like dijit/registry outside of a webdriver execute() method as the code needs to be within the context of the web browser not the functional test.

Était-ce utile?

La solution

Functional tests run from within Node.js, not the browser environment. If you want to access the dijit/registry instance that was loaded in the page you are testing, you need to use execute to run a function within the remote environment:

return this.remote
  .get('http://application.co.uk')
  .execute(function () {
    // this function runs in the browser!

    var registry = require('dijit/registry');
    // ... do things with registry

    return something;
  })
  .then(function (something) {
    // this function runs inside the test runner!

    assert.isTrue(something);
  });

You won’t be able to define dependencies that have DOM requirements (like dijit/registry) from functional test modules. Only browser-based unit test modules will be able to load such dependencies.

Autres conseils

There's also the dijit-intern-helper -> https://github.com/SitePen/dijit-intern-helper

so this

executeAsync(function (done) {
    require(['dijit/registry'], function (registry) {
        done(registry.byId('titlePane').titleBarNode);
    });
})
.then(function (node, setContext) {
    setContext(node);
})
.click()

becomes

.then(dijit.nodeById('titlePane', 'titleBarNode'))
.click()

A blog post about it -> https://www.sitepen.com/blog/simplified-dijit-functional-testing/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top