Get help with testing, discuss unit testing strategies etc.


Post by jeanphimccarthy »

Hi,

I added a custom method in my test class which goes off a server to check somthing in a DB. This does work.
But now I would like to create a specific action for that, something like that :
{uw_findLock : ['AnimalTypeIUO', [{column: 'action', value: 'D'}, {column: 'tableId', value: 'AnimalType'}]],failWhen:'present'},
I created a class called MainWeb.FindLock for that but I have 2 problems:
1) Where should I call
Siesta.Test.ActionRegistry().registerAction('uw_findLock', MainWeb.FindLock);
to have my new action registered, in the Test itself?
2) I get this error : Need to include `action` property or shortcut property in the step config: {"uw_findLock": ["AnimalTypeIUO", [..., ...]], "failWhen": "present"}

Here is my action class code:
Class('MainWeb.FindLock', {

    isa         : Siesta.Test.Action,

    //does        : Siesta.Test.Action.Role.HasTarget,

    has : {
        requiredTestMethod  : 'uw_findLock',
        options             : null,
       //present or absent
        failWhen       : 'absent'
    },


    methods : {

        process : function () {
            
            console.log('FINDLOCK');
            
            // additional "getTarget" to allow functions as "target" value
            
            //some custom code that goes off to the server etc... 
        }
    }
});
Thank you for your help!

Post by mats »

You should not need this:
Siesta.Test.ActionRegistry().registerAction('uw_findLock', MainWeb.FindLock);
Since Siesta can call any Test class method as part of a chain, as long as it has a 'next' continuation callback method as the last argument.
    Class('MainWeb.FindLock', {

        isa         : Siesta.Test.Action,

        //does        : Siesta.Test.Action.Role.HasTarget,

        has : {
            requiredTestMethod  : 'uw_findLock',
            options             : null,
           //present or absent
            failWhen       : 'absent'
        },


        methods : {

            process : function (next) {
               
                console.log('FINDLOCK');
               
                // additional "getTarget" to allow functions as "target" value
               
                //some custom code that goes off to the server etc...
               // ** when done call next() 
          
            }
        }
    });

Post by tech.support »

Still the same error.
But since this a test action class and Not a Test class, what magic would find this class if not registered somewhere?

Post by mats »

Right, I missed that you were making a real action class. Are you loading this class in your HTML page too? Any chance you can upload a small test case?

Post by tech.support »

I'm not, I just put a registerAction on startup of my test class.
Here is my test case but you'll probably need more info..
describe("Animal Type CRUD", function (t) {

   

    t.chain(

        //login
        {mainweb_login : "fast"},
        
        //Choose Animal Type
        {mainweb_openMenuAndSelectProgramFromFlatMenu : "Animal Type"},
            
        //Check the form is hidden
        {uw_isFieldHidden : '#ANIMAL_TYPE-ID'},
        {uw_isFieldHidden : '#ANIMAL_TYPE-NAME'},   
        {uw_isFieldHidden : '#ANIMAL_TYPE-SEARCH_NAME'},   
        {uw_isFieldHidden : '#ANIMAL_TYPE-SPECIES_ID'},   
        {uw_isFieldHidden : '#ANIMAL_TYPE-IS_ACTIVE'},   
        {uw_isFieldHidden : '#ANIMAL_TYPE-STOCK_TYPE_ID'},   
        {uw_isFieldHidden : '#ANIMAL_TYPE-SEX'},   
        {uw_isFieldHidden : '#ANIMAL_TYPE-FEEDING_PROGRAM_ID'},
        {uw_isFieldHidden : '#ANIMAL_TYPE-YIELD_PERCENTAGE'},   

      
        {uw_findLock : ['AnimalTypeIUO', [{column: 'action', value: 'D'}, {column: 'tableId', value: 'AnimalType'}]],failWhen:'present'},
        {uw_findLock : ['AnimalTypeIUO', [{column: 'action', value: 'L'}, {column: 'tableId', value: 'AnimalType'}]],failWhen:'present'},

 
        {waitFor: 2000}
                                                                                                         
    );
});

Post by nickolay »

The `Siesta.Test.ActionRegistry().registerAction` call should be done right below the action class declaration (usually in the same file with it). The array you give as the value of the "uw_findLock" property will be initialized as the "target" attribute of the action class, so you need to declare it in the "has" section of the test class, to get access to it (something like this should be enough):
has : {
    target : null
}

Post by tech.support »

Thanks Nickolay,

So this is my Action class now :
Class('MainWeb.FindLock', {

    isa         : Siesta.Test.Action,

    //does        : Siesta.Test.Action.Role.HasTarget,

    has : {
        requiredTestMethod  : 'uw_findLock',
        target: null,
        options             : null,
       //present or absent
        failWhen       : 'absent'
    },


    methods : {

        process : function () {
            
            console.log('FINDLOCK');
            console.log(this.target);
            console.log(this.options);
            console.log(this.failWhen);

           this.next()
        }
    }
});

Siesta.Test.ActionRegistry().registerAction('uw_findLock', MainWeb.FindLock);
And my test step is like that:
{uw_findLock : ['AnimalTypeIUO', [{column: 'action', value: 'D'}, {column: 'tableId', value: 'AnimalType'}]],failWhen:'present'}
And I still get
Need to include `action` property or shortcut property in the step config: {"uw_findLock": ["AnimalTypeIUO", [..., ...]], "failWhen": "present"}

Any other thing to do? I still do not pick up how Siesta can find my FindLock.js
Should I as Mats suggested load it from the index.html? Seems strange to me...

Thanks

Post by nickolay »

Right, it should be included right after the "siesta-all.js" and before your test class. What seems strange? The code just should be brought to the harness page somehow :)

Post by tech.support »

Thanks,
Yes you are right.
It seems we made good progress, I have an other issue:
Error: Action [MainWeb.FindLock] requires `uw_findLock` method in your test class

Any idea?

Post by nickolay »

Do you have this method in the test class? Probably need to tweak the "requiredTestMethod" attribute of the action class.

Post Reply