Forum Discussion

JonoW's avatar
JonoW
Occasional Contributor
14 years ago

While Loop in Keyword Test/Script

Hello,



I'm trying to implement a while loop in one of my tests that will hopefully execute the commands within the loop until the condition it's testing for is no longer met.



However, it doesn't seem to want to work. Here's what I have (below), converted to a script (from a keyword test).

It doesn't matter if the ActiveAlarmsList has any items in it - whether it's visible on screen or not when an entry is added to it; the test just runs as normal, as if there were no WHILE clause present.



However, if there's an entry in the list when this function is called/run, then it will exit straight away.



How can I do some kind of monitoring of this list, and if there is > 0 or !=0 items in it at some point, quit out of the current test/function?



There must be a way, surely ?



Thanks,



Jono.








function Test3()


Test3()

{


while(Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["AlarmsTabs"]["AlarmsTabControl"]["Alarms_ActiveAlarmsTab"]["ActiveAlarmsPage"]["ActiveAlarmsSplitContainer"]["AlarmsListSplitterPanel"]["ActiveAlarmsList"]["wItemCount"] == 0)


{


//Clicks the 'JobsButton_Button' button.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["NavigationToolbar"]["JobsButton"]["JobsButton_Button"]["ClickButton"]();


//Selects the 'Job Editor' tab of the 'JobsTabControl' tab control.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["JobsTabs"]["JobsTabControl"]["ClickTab"]("Job Editor");


//Clicks the 'wButtonsRight(0)' editor button.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["JobsTabs"]["JobsTabControl"]["Jobs_JobEditorTab"]["QuickJobEditorPage"]["JobEditor_LoadPortComboBox"]["JobEditor_LPText"]["wButtonsRight"](0)["Click"]();


//Clicks at point (60, 19) of the 'WinFormsObject("ValueListDropDownUnsafe", "")' object.


Aliases["Nano_UI"]["WinFormsObject"]("DropDownForm", "")["WinFormsObject"]("ValueListDropDownUnsafe", "")["Click"](60, 19);


//Clicks the 'JobEditor_LoadButton' button.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["CommandToolbar"]["CMDButton1"]["JobEditor_LoadButton"]["ClickButton"]();


//Delays the script execution until the specified property equals the specified value or until the specified time limit elapses.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["JobsTabs"]["JobsTabControl"]["Jobs_JobEditorTab"]["QuickJobEditorPage"]["JobEditor_RecipeTabControl"]["WaitProperty"]("Enabled", true, 5000);


//Selects the 'Cluster Recipes' tab of the 'JobEditor_RecipeTabControl' tab control.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["JobsTabs"]["JobsTabControl"]["Jobs_JobEditorTab"]["QuickJobEditorPage"]["JobEditor_RecipeTabControl"]["ClickTab"]("Cluster Recipes");


//Clicks at point (94, 11) of the 'HappyPath1.xml' item of the 'JobEditor_ClusterRecipesTab_Treeview' tree.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["JobsTabs"]["JobsTabControl"]["Jobs_JobEditorTab"]["QuickJobEditorPage"]["JobEditor_RecipeTabControl"]["JobEditor_ClusterRecipeTabPage"]["JobEditor_FilteredClusterRecipeTreeView"]["JobEditor_ClusterRecipesTabControl"]["JobEditor_AllRecipesTab"]["AllRecipesTreeView"]["JobEditor_ClusterRecipesTab_Treeview"]["ClickItemXY"]("HappyPath1.xml", 94, 11);


//Drags from point (90, 267) of the 'JobEditor_SlotMapUltraGrid' object to offset (4, 40).


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["JobsTabs"]["JobsTabControl"]["Jobs_JobEditorTab"]["QuickJobEditorPage"]["JobEditor_SlotMapUltraGrid"]["Drag"](90, 267, 4, 40);


//Clicks the 'JobEditor_ToggleRecipeButton' button.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["JobsTabs"]["JobsTabControl"]["Jobs_JobEditorTab"]["QuickJobEditorPage"]["JobEditor_GridButtonPanel"]["JobEditor_ToggleRecipeButton"]["ClickButton"]();


//Clicks the 'JobEditor_QueueJobButton' button.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["CommandToolbar"]["CMDButton2"]["JobEditor_QueueJobButton"]["ClickButton"]();


//Clicks the 'Button' button.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["NavigationToolbar"]["SystemButton"]["Button"]["ClickButton"]();


//Selects the 'Process Jobs' tab of the 'SystemTabsControl' tab control.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["SystemTabs"]["SystemTabsControl"]["ClickTab"]("Process Jobs");


//Checks whether the 'wItemCount' property of the Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["SystemTabs"]["SystemTabsControl"]["System_PJsTab"]["ProcessJobsPage"]["SYS_processJobsSplitContainer"]["SYS_PJsSplitterPanel1"]["ProcessJobListView"] object equals 1.


aqObject["CheckProperty"](Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["SystemTabs"]["SystemTabsControl"]["System_PJsTab"]["ProcessJobsPage"]["SYS_processJobsSplitContainer"]["SYS_PJsSplitterPanel1"]["ProcessJobListView"], "wItemCount", 0, 1);


//Delays the script execution until the specified property equals the specified value or until the specified time limit elapses.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["SystemTabs"]["SystemTabsControl"]["System_PJsTab"]["ProcessJobsPage"]["SYS_processJobsSplitContainer"]["SYS_PJsSplitterPanel1"]["ProcessJobListView"]["WaitProperty"]("wItemCount", 0, 600000);


//Clicks the 'JobsButton_Button' button.


Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["NavigationToolbar"]["JobsButton"]["JobsButton_Button"]["ClickButton"]();


}

}

  • JonoW's avatar
    JonoW
    Occasional Contributor
    Hmm, it seems that the above is blatantly not going to work. I was very ill when I wrote it, I went home to bed straight after.     



    But hopefully you can see what I was trying to achieve?



    I would like to monitor (or keep checking very often) the number of items in the listview and if there are any, stop execution of the test because something's gone wrong in the software.



    How can I do this?

  • Hello Jono,





    As far as I understand your task, you need to perform your code only if the wItemCount==0 condition is true. So, if this condition becomes false after any code line is performed, you want to exit the current test. In this case, the only solution I can suggest is to always check this condition where it is possible. That is, before every code line, add code that will check whether the wItemCount property is still equal to 0. 





    Since the solution looks quite clumsy, I suggest that you simplify it in the following way. 

    - Enclose the condition statement in a separate validation function. 

    - Within the validation function, throw an exception if the condition is not met. 

    - In the test function (renamed to Test3_inner for the description purposes), call the validation function before every code line. 

    - Enclose the call of the Test3_inner test function into the try...catch statement:





    The following code snippet illustrates the suggestion:







    function Test3()

    {

      try {

        Test3_inner();

      }

      catch(e) {

        if (e.number == 1000) {

          return false;

        }

        throw e;

      }

      return true;

    }





    function validateListCount()

    {

      if (0 != Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["AlarmsTabs"]["AlarmsTabControl"]["Alarms_ActiveAlarmsTab"]["ActiveAlarmsPage"]["ActiveAlarmsSplitContainer"]["AlarmsListSplitterPanel"]["ActiveAlarmsList"]["wItemCount"]) {

        throw new Error(1000, "There are some items in the list");

      }

    }





    function Test3_inner()

    {

        validateListCount();

        Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["NavigationToolbar"]["JobsButton"]["JobsButton_Button"]["ClickButton"]();

        validateListCount();

        Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["JobsTabs"]["JobsTabControl"]["ClickTab"]("Job Editor");

        validateListCount();

       ...

       // and so on

    }
  • JonoW's avatar
    JonoW
    Occasional Contributor
    Thank you David,

    That seems to be just what I was after...not an ideal solution, but a solution nevertheless :)



    Another sort of question that relates to this...

    See the waitProperty line:


    //Delays the script execution until the specified property equals the specified value or until the specified time limit elapses.

    Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["SystemTabs"]["SystemTabsControl"]["System_PJsTab"]["ProcessJobsPage"]["SYS_processJobsSplitContainer"]["SYS_PJsSplitterPanel1"]["ProcessJobListView"]["WaitProperty"]("wItemCount", 0, 600000);



    Is there any way at all to intercept things happening while this line is being processed? For example - some alarm might occur while a job is in progress... and I don't really want to be waiting until the 10 minutes is up to find out if something went wrong.



    In essence, I would like to/need to be able to wait for things to happen, so that the test doesn't time out, but have the ability to check other things in the meantime.



    Is this a possiblity, or something that could be added into TestComplete as a feature request at a later date?



    Cheers, and Happy New Year to everyone @ SmartBear etc.



    J.


    ["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["SystemTabs"]["SystemTabsControl"]["System_PJsTab"]["ProcessJobsPage"]["SYS_processJobsSplitContainer"]["SYS_PJsSplitterPanel1"]["ProcessJobListView"]["WaitProperty"]("wItemCount", 0, 600000);Is there any way at all to intercept things happening while this line is being processed? For example - some alarm might occur while a job is in progress... and I don't really want to be waiting until the 10 minutes is up to find out if something went wrong. In essence, I would like to/need to be able to wait for things to happen, so that the test doesn't time out, but have the ability to check other things in the meantime. Is this a possiblity, or something that could be added into TestComplete as a feature request at a later date? Cheers, and Happy New Year to everyone @ SmartBear etc.J.

  • Hello Jono,





    Instead of using a single line with a 10-minute timeout, you can organize a loop with a WaitProperty call in it. For example, you can call WaitProperty with a one-minute timeout, until the total waiting timeout is greater than 10 minutes. See the sample code below:







      var alarmList = Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["AlarmsTabs"]["AlarmsTabControl"]["Alarms_ActiveAlarmsTab"]["ActiveAlarmsPage"]["ActiveAlarmsSplitContainer"]["AlarmsListSplitterPanel"]["ActiveAlarmsList"];

      var totalTimeToWait  = 600000; 

      var result = false;

      var endTime = GetTickCount() + totalTimeToWait;





      while (GetTickCount() < endTime)

      {

        if( alarmList.wItemCount > 0)

        {

          //your code to process alarms

        } 

        result = Aliases["Nano_UI"]["NanoFrame"]["MainPanel"]["ModulePanel"]["SystemTabs"]["SystemTabsControl"]["System_PJsTab"]["ProcessJobsPage"]["SYS_processJobsSplitContainer"]["SYS_PJsSplitterPanel1"]["ProcessJobListView"]["WaitProperty"]("wItemCount", 0, 60000);

        if(result == true)

          break; 

      }







    In the sample, I used the Win32API.GetTickCount method to obtain the current number of milliseconds.