Question

I have a single page application that uses Dojo to navigate between pages. I am writing some functional tests using intern and there are some niggly issues I am trying to weed out. Specifically I am having trouble getting intern to behave with timeouts. None of the timeouts seem to have any effect for me. I am trying to set the initial load timeout using "setPageLoadTimeout(30000)" but this seems to get ignored. I also call "setImplicitWaitTimeout(10000)" but again this seems to have no effect.

The main problem I have is that it may take a couple of seconds in my test environment for the request to be sent and the response parsed and injected into the DOM. The only way I have been able to get around this is by explicitly calling "sleep(3000)" for example but this can be a bit hit & miss and sometimes the DOM elements are not ready by the time I query them. (as mentioned setImplicitWaitTimeout(10000) doesn't seem to have an effect for me)

With the application I fire an event when the DOM has been updated. I use dojo.subscribe to hook into this in the applictaion. Is it possible to use dojo.subscribe within intern to control the execution of my tests?

Heres a sample of my code. I should have also mentioned that I use Dijit so there is also a slight delay when the response comes back and the widgets are being created (via data-dojo-type declarations)...

    define([
    'intern!object',
    'intern/chai!assert',
    'require',
    'intern/node_modules/dojo/topic'
], function (registerSuite, assert, require, topic) {
    registerSuite({
        name: 'Flow1',  
        // login to the application
        'Login': function(remote) {
            return remote
                .setPageLoadTimeout(30000)
                .setImplicitWaitTimeout(10000)
                .get(require.toUrl('https://localhost:8080/'))
                .elementById('username').clickElement().type('user').end()
                .elementById('password').clickElement().type('password').end()
                .elementByCssSelector('submit_button').clickElement().end();
        },
        // check the first page
        'Page1':function() {
            return this.remote
                .setPageLoadTimeout(300000)      // i've tried these calls in various places...
                .setImplicitWaitTimeout(10000)   // i've tried these calls in various places...         
                .title()
                    .then(function (text) {
                        assert.strictEqual(text, 'Page Title');})
                    .end()              
                .active().type('test').end()
                .elementByCssSelector("[title='Click Here for Help']").clickElement().end()             
                .elementById('next_button').clickElement().end()
                .elementByCssSelector("[title='First Name']").clear().type('test').end()
                .elementByCssSelector("[title='Gender']").clear().type('Female').end()
                .elementByCssSelector("[title='Date Of Birth']").type('1/1/1980').end()             
                .elementById('next_button').clickElement().end();
        },
        // check the second page
        'Page2':function() {            
            return this.remote
                .setImplicitWaitTimeout(10000)              
                .sleep(2000) // need to sleep here to wait for request & response injection and DOM parsing etc...
                .source().then(function(source){
                    assert.isTrue(source.indexOf('test') > -1, 'Should contain First Name: "test"');
                    }).end()
                // more tests etc...
        }
    });
});

I'm importing the relevant Dojo module from the intern dojo node module but I'm unsure of how to use it.

Thanks

Était-ce utile?

La solution

Your test is timing out, because Intern tests have an explicit timeout set to 30s that is not accessible through their API. It can be changed by adding 'intern/lib/Test' to your define array, and then overwriting the timeout from the Test's object, e.g. Test.prototype.timeout = 60000;.

For example:

define([
    'intern!object',
    'intern/chai!assert',
    'require',
    'intern/node_modules/dojo/topic',
    'intern/lib/Test'
], function (registerSuite, assert, require, topic, Test) {
  Test.prototype.timeout = 60000;
  ...
}

This should change the timeout to one minute instead of 30s, to prevent your test timing out.

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