Get help with testing, discuss unit testing strategies etc.


Post by sqatester123 »

Hello,

I am trying to pass a function from my testClass into a wait for, but it doesn't work.

Take the following chain for example.
StartTest(function(t) {
    t.chain(
         {
             waitFor: 
                 function() {
                     t.diag("wait for mask...");
                     var load_mask = t.global.Ext.ComponentQuery.query("loadmask[msg=Retrieving firmware information...]")[0];

                     if (load_mask == null || load_mask.hidden == true) {
                         return true;
                     }
                     return false;
                 }
         }
This code works as expected, it waits for the load mask to disappear before moving on.

What I would like to do is move the code that is in the chain into it's own function. When I do this I get the following exception.
TypeError: waitFor.replace is not a function
With the waitFor function moved to it's own function the chain looks like this.
StartTest(function(t) {
    t.chain(
         {
             waitFor: t.wait_for_load_mask()                
         }
My testClass looks like this.
Class('Utils', {
    isa         : Siesta.Test.ExtJS,

    methods : {
		wait_for_load_mask : function() {
			this.diag("wait for mask...");
			var load_mask = this.global.Ext.ComponentQuery.query("loadmask[msg=Retrieving firmware information...]")[0];

			if (load_mask == null || load_mask.hidden == true) {
				return true;
			}
			return false;
		}
	}
})

Post by nickolay »

Hi,

The thing is this call - `t.wait_for_load_mask()` actually returns true/false. Then this value is provided to the "waitFor" method, which is incorrect, as it expects a function in general case.

So if you want specialized version of "waitFor" it can look like:
waitForSomething : function (arg1, arg2, callback, scope) {

    return this.waitFor({
        method          : function() { return conditionFullfilled ? true : false },
        callback        : callback,
        scope           : scope,
        assertionName   : 'waitForSomething',
        description     : 'Waited for something to complete'
    });
}
Then it can be used in the chain as:
t.chain(
    { waitForSomething : [ arg1, arg2 ] },

    function (next) {
        t.waitForSomething(arg1, arg2, next)
    }
)
W/o arguments it will be:
waitForSomething : function (callback, scope) {
t.chain(
    { waitForSomething : [] },

    function (next) {
        t.waitForSomething(next)
    }
)

Post Reply