Get help with testing, discuss unit testing strategies etc.


Post by prb »

Hi,

for every test I am doing a login in setup and a logout in teardown.
It seems like the next test is started, while doing the logout for the test before. So the next setup is failing for the next test. The next whole test is also failing.
Do you know how to avoid this behavior?
Thank you and best regards,

Post by nickolay »

Hi,

Sorry for delay, can you post some code? You probably call the callback from the "tearDown" method too early.

Post by prb »

Hi,

no problem. I just moved my logout method to the end of the testfiles as long as I can't resolve it.
This is the code:
tearDown: function(callback, errback) {
            this.describe('Teardown', function(t) {
                t.it('Logout user', function(t) {
                    t.logoutUser();

                    t.waitForLoginWindow();
                });
            });
            callback();
        }
In the logoutUser() method I only click the logout button.

Post by nickolay »

Right, you call the `callback` in the "tearDown" immediately. Instead, the "callback" should be called after the "logoutUser" method (which is also asynchronous I suppose). Assuming your "waitForLoginWindow" method also accept the callback, code may look like:
    tearDown: function(callback, errback) {
                this.describe('Teardown', function(t) {
                    t.it('Logout user', function(t) {
                        t.logoutUser();

                        t.waitForLoginWindow(function () {
                            callback();
                        });
                    });
                });                
            }

Post by prb »

Thank you. But now I do not know how to call the callback correctly in the waitForLoginWindow method. :)
Code looks like this:
waitForLoginWindow: function() {
            this.it('Wait for login window', function(t) {
                t.chain(
                    {
                        waitForComponentVisible: loginWindow,
                        desc: 'Wait for login window is visble'
                    },
                    // some other waitFor actions
                );
            });
        }

Post by nickolay »

Call it as the last action in the chain (not right after the chain):

Wrong:
waitForLoginWindow: function(callback) {
            this.it('Wait for login window', function(t) {
                t.chain(
                    {
                        waitForComponentVisible: loginWindow,
                        desc: 'Wait for login window is visble'
                    },
                    // some other waitFor actions
                );
                callback() // called immediately, before the 1st action in the chain starts
            });
        }
Right:
waitForLoginWindow: function(callback) {
            this.it('Wait for login window', function(t) {
                t.chain(
                    {
                        waitForComponentVisible: loginWindow,
                        desc: 'Wait for login window is visble'
                    },
                    callback
                );

            });
        }

Post by prb »

yes, this is what I already tried. Starting tests in Siesta manually everything is running fine.
Starting tests with webdriver I am getting an exception:
TypeError: Cannot read property 'clearTimeout' of null

First I thought it is because of page redirect, but enablePageRedirect is true.

Post by nickolay »

If you can provide a reproducible test case, we'll investigate, hard to say anything otherwise.

Post Reply