Forum Discussion

abrar22's avatar
Frequent Contributor
9 years ago

Change focus from One Process to another

Hi,   I have to login to the application multiple time concurrently but I am having problem second time onwards as test complete is not recognizing the Login screen.    So 1st time i run the batc...
  • tristaanogre's avatar
    9 years ago

    So, question, are you closing and reopening your process multiple times, specifically the one previously indicated by ID 3?  Or are you using that same process repeatedly?  The reason I ask is that closing the process and re-opening it will not necessarily give you the next ID (4, 5, 6, etc). It will give you the next available ID based upon what's already open.  So, you COULD be using ID 3 again rather than always incrementing.


    As mentioned, you're going to want to assign your process object to a variable and then use that variable in your code to reference the process.  Here's a brief example of what I mean. The key routine is the "RunApplication" function. Simply pass in the path for your application and it will run it, returning the process you need.  What you would do then is use RunApplication where you want run your program and assign the result of the function to your global variable for the process you want.  In my example, I am calling RunApplication in a for loop and what I get in my log is the process name and index of each process running in Windows.

    function RunApplication(FullPath)
    var AppIndex, AppProcess;
    AppIndex = TestedApps.Add(FullPath);
    AppProcess = TestedApps.Items(AppIndex).Run();
    return AppProcess;

    function TestThis()
    var MyApp;
    for (i = 0; i <= 1; i++){
    MyApp = RunApplication("C:\\Windows\\System32\\notepad.exe");
    Log.Message("My app is " + MyApp.ProcessName + " with an index of " + MyApp.Index);