Get help with testing, discuss unit testing strategies etc.


Post by cwtuan »

I have two test script. They have similar behavior.

testA.t.js
StartTest(function(t) {
    { 
           // action 1
    },
   { 
           // action 2
    },
    { 
           // action A
    }
});
testB.t.js
StartTest(function(t) {
    { 
           // action 1
    },
   { 
           // action 2
    },
    { 
           // action B
    }
});
The first two actions (action1 and action2) are the same across test scripts.
I would like to make action1 and action2 into a action group and import the action group in each test scripts.

That is, is it possible to make the test scripts looks as following?
testA.t.js
StartTest(function(t) {
    { 
           // import action group
    }, 
    { 
           // action A
    }
});
testB.t.js
StartTest(function(t) {
    { 
             // import action group
    },
    { 
           // action B
    }
});

Post by mats »

Please read this guide on how to extend your TestClass, where you can add any extensions and do custom actions easily.

https://www.bryntum.com/docs/siesta/#!/g ... test_class

Post by cwtuan »

Thanks for the reply.
I have read that article one months ago. But I don't think it's something related to my question.
Could you give me more specific example?

My first two actions are
{
  action: "click",
  target: ">> viewport #project"
}, {
  action: "click",
  target: ">> mygrid #button"
}
And I have ExtendingTestClass:
Class('Test.ExtendingTestClass', {
  isa: Siesta.Test.ExtJS,
  methods: {
    clickMyButton: function () {
      var t = this;
      // how could I execute my first two actions here?
    }
  }
});
And how to apply clickMyButton() to test script?
StartTest(function (t) {
  // clickMyButton() is a method instead of action object.
  // So, how to apply clickMyButton() here?
});
Thank you for your precious time.

Post by cwtuan »

I have another idea.
There is a JS file containing the action group like:
Steps.js
var Steps = Steps || {};
Steps.actionGroup = [
  function(next){
      // action1
      console.log(foo); // I want to use the variable defined in *.t.js
      next();
  },{
   // action2
 }];
In Harness file, import Steps.js to *.t.js.
Harness.configure({
    // ...
    preload : ['Steps.js' ],
})
In my test.t.js file, it do start to run Steps.actionGroup.
But, the variable foo defined in test.t.js is not accessible by Steps.js.
How could I resolve it?
StartTest(function(t) {
        var  foo = 0;
        t.chain(
                Steps.actionGroup
        );
});

Post by nickolay »

Yes, you can use your approach with shared "preload" file. The recommended way is still to extend the test class:
    Class('Test.ExtendingTestClass', {
      isa: Siesta.Test.ExtJS,
      methods: {
        clickMyButton: function (param1, param2, callback) {
          var t = this;
          
          this.chain(
            {
                action : "click1"
            },
            {
                action : "click1"
            },
            callback
          )
          
        }
      }
    });
Then in the test file you can write:
t.chain(
  {
      clickMyButton : [ param1, param2 ]
  }
)
(callback will be appended as last argument automatically).

Read the docs for t.chain method and https://bryntum.com/docs/siesta/#!/api/S ... MethodCall action.

Post by cwtuan »

Thanks a a lot! It works fine.
I have another question, the example in the document shows that we can extend test class as following:
Harness.configure({
    testClass   : MyProject.MyTestClass
})
But, we have more than one developers, so we want to have multiple extended test classes for different modular testing.
Does testClass support an array of extended test classes?

Post by nickolay »

Yes, you can specify "testClass" option for a group of tests or only for single test and test classes can be different.

Post by cwtuan »

Thank you very much! It works!

Post Reply