Forum Discussion

murugans1011's avatar
murugans1011
Regular Contributor
10 years ago
Solved

Running Project test item

Hi,



I have a scenario where i need to run the same project test item several times(say for 10).  so i just increased count to 10.  in some situation if there is an error posted in to the test log , then i need stop the current project test item. So i have used



                Runner.Stop(True)   'To stop only current testitem and move to the next item



in the Onlogerror event. So tc just stops current test item and moves to the next item even through the count is 10.. in my scenario i need to run same testitem again with different arguments till the count is reached...i cant able to find any method to this. now i m simply adding the same project test item several times.

 

 is there anything can be done with "onstop test" event to run same testitem again. Pls provide any suggestion to achieve my scenario.



Thanks,
  • There is another approach you can try:

    1. Get the name of the currently run test item:




    var test = Project.TestItems.Current.ElementToBeRun.Caption;




     


    It returns the name in the following format: Script\Unit1 - Main. So:


    2. You need to parse the string and obtain the name of the test and the name of the script unit:




    var arr = test.split("\\")[1].split("-");


    var unitName = aqString.Trim(arr[0]);


    var name = aqString.Trim(arr[1]);




     


    3. Now, you can call the function:




    Runner.CallMethod(unitName + "." + name);



9 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    There is another approach you can try:

    1. Get the name of the currently run test item:




    var test = Project.TestItems.Current.ElementToBeRun.Caption;




     


    It returns the name in the following format: Script\Unit1 - Main. So:


    2. You need to parse the string and obtain the name of the test and the name of the script unit:




    var arr = test.split("\\")[1].split("-");


    var unitName = aqString.Trim(arr[0]);


    var name = aqString.Trim(arr[1]);




     


    3. Now, you can call the function:




    Runner.CallMethod(unitName + "." + name);



  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I wouldn't use the OnStopTest event handler in this case.  I'd use the OnLogError handler.  In that handler, keep track of the iteration of the test item.  If an error is logged and it is not in the last iteration (iteration < 10), execute scripts or keyword tests that "clean up" the test so you can start the next iteration.  You might need to include code in your Test Item that indicates whether or not the iteration is successful.  A "try/except" wrapped around the entire test would help with that.



    I don't think this is something that you're going to be able to do with just a bult-in command but something that you're going to have to do some architecture work around your test items in order to make them self-aware of their state (iteration, error condition, success, etc).
  • murugans1011's avatar
    murugans1011
    Regular Contributor


    //[VBScript] for above function





    Sub ProjectTestRun



       test = Project.TestItems.Current.ElementToBeRun.Caption

       

        arr = split(test,"\")



        tempArr=split(Arr(1),"-")



        unitName = aqString.Trim(tempArr(0))



        name = aqString.Trim(tempArr(1))



        Runner.CallMethod(unitName + "." + name)



    End sub



  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Murugan,

     


     


    Something like this should work:


    IntegrationObj.RunProjectItem(<ProjectName>", "<ProjectItemName>")


     

  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Hi,





    Thanks for ur reply.





    I have implemented something like this in onlogerror event





    Sub GeneralEvents_OnLogError(Sender, LogParams)

     

      if RunErrorFlag=1 then  'Flag will be set if error is posted with high priority

     

        testCount=Project.TestItems.Current.Count

     

         if Project.TestItems.Current.Iteration<testCount then

           Call Tc_Add_PRN_Categorywise  'function call

         End if

        End if

        

    End Sub

     

    but instead of calling a function if iteration<count ,i need somthing like



       Project.testitem.Current.Run



    but there is no method to run testitem from script. i need something lik  current running testitem's function should be called automatically till testitem count.
  • murugans1011's avatar
    murugans1011
    Regular Contributor
    is there any alternative way instead of 

       

     Runner.Stop  'to stop current testitem and execute it from beginning somthing lik 'exit function' from  On LogError event
  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Hi when i try this i got " cannot launch another instace of application".. I think that Interagtion object is to run project item from external application.

    I've contacted support team regarding this and found that this feature is not implemented yet. So i've added my vote.
  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Hi Tanya,



    Thanks for ur reply. This is what i m exactly looking for.



    I had spend lot of time because of this problem



    Now it works fine.



    Thank you so much:)