Results 1 to 2 of 2

Thread: done causes test to fail

  1. #1

    Default done causes test to fail

    I have written a short test that fetches login credentials from a local file, logs in and simply accesses a page element.

    Code:
    describe("loginAndNavigate", function() {
        const fs = require('fs');
        
        // Reading the JSON config file and converting it to a JS object
        let configData = fs.readFileSync("C:\\Users\\JohnDoe\\SenchaTest\\Tests\\database_integration\\test\\basic_stuff\\lib\\config.json");
        configData = JSON.parse(configData);
    
    
        beforeAll(function (done) {        
            ST.navigate(configData.loginCredentials.url);
            // Initial login 
            stpo.loginPage.username()
                .focus()
                .type(configData.loginCredentials.username);
            stpo.loginPage.password()
                .focus()
                .type(configData.loginCredentials.password);
                
            stpo.loginPage.loginButton()
                .focus()
                .click()
                .and(done);
        });
        
        it("1: do stuff", function() {
            stpo.mainPage.maintenance().click();
            stpo.mainPage.carrierContact().click();
            ST.wait(1500);
        });
    });
    Now running this scenario works perfectly fine, it is clearly visible that the desired page accessed via the it-block gets reached, yet the test fails.

    Removing the done-parameter in the beforeAll-function as well as the .and(done) call at the end of the login results in a postive test and reaches the desired page as well.

    Writing this test I oriented myself using the answer of this thread https://www.sencha.com/forum/showthr...-then()-method suggesting the done call as the solution to this timing related problem. Why does this not work in this case?

  2. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    354
    Answers
    61

    Default

    The purpose of using "done" in Jasmine is to force the test suite to wait for an asynchronous action to complete, and only proceed when you tell it to, by calling "done()". For example, this would need to be leveraged when incorporating a callback (e.g. Ajax request), or a Promise being fulfilled/rejected within the test suite - those actions will have to tell the test suite to wait for the callback/promise to complete, and it does that through use of "done". See https://jasmine.github.io/2.4/introd...ronous_Support.

    In your case above, there is no need to use this, as you are just making use of the standard Sencha Test APIs - they will always wait for components/elements and their various states to be available, and there are no callbacks, so all the actions will be executed in the "beforeAll" automatically, before proceeding to the first test.

    If you are experiencing some other timing related issue without the use of "done", you may need to leverage a manual "wait" - for example, if a page navigation takes place and the subsequent page takes a while to render, you could add a wait after the page navigation occurs. You can also add a timeout parameter to Sencha Test APIs, if you know a component won't be available for a while, for example if a view takes a while to render:

    Code:
    // Wait up to 15 seconds for the component to be available.
    ST.component('mycomponent', 15000);
    Daniel Gallo
    Sales Engineer
    Sencha

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •