Forum Discussion

abrar22's avatar
Frequent Contributor
8 years ago

Change focus from One Process to another



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 batch file, inputs the user name, password and Login successfully. Then again I open the login screen again but it doesn't recognize the elements(Unable to find the object WPFObject("HwndSource: LogOnWindow", "A Login"). See Additional Information for details. 12:45:21 Normal) 


1st Login Screen :Sys.Process("A.Velocity.Bootstrapper", 2).WPFObject("HwndSource: LogOnWindow", "A Login").WPFObject("LogOnWindow", "A Login", 1))


2nd Login Screen: Sys.Process("A.Velocity.Bootstrapper", 3).WPFObject("HwndSource: LogOnWindow", "A Login").WPFObject("LogOnWindow", "A Login", 1)


I guess because i open the Application 1st time and its focus is still on opened application it doesn't recognize the Login Screen second time or it can be because Process increments everytime I login and in code I am using Sys.Process("A.Velocity.Bootstrapper", 2).


Can someone please recommend any work around for this so i can login several times ever if previous logged in app is open.




function Test()
var SCENARIO_LIST = GetDataGrid("Framework\\\DataRepository\\Users.xlsx", "Sheet1");
for (var i in SCENARIO_LIST){
var obj = Sys.OleObject("WScript.Shell")
var mypath = "C:\\TFS_QA\\QA\\VelocityTestAutomation-Annex\\Velocity2.0-Annex-Suite\\Velocity2.0-Annex\\Framework\\AUT\\Application\\Velocity.bat"
obj.Run("\"" + mypath + "\"");
var item = SCENARIO_LIST[i];
Setter.vSetText(Sys.Process("A.Velocity.Bootstrapper", 2).WPFObject("HwndSource: LogOnWindow", "A Login").WPFObject("LogOnWindow", "A Login", 1).WPFObject("_logOn").WPFObject("PrincipalField"),item.UserName)
Setter.vSetText(Sys.Process("A.Velocity.Bootstrapper", 2).WPFObject("HwndSource: LogOnWindow", "A Login").WPFObject("LogOnWindow", "A  Login", 1).WPFObject("_logOn").WPFObject("PasswordField"),item.Password)
Action.vClickButton(Sys.Process("A.Velocity.Bootstrapper", 2).WPFObject("HwndSource: LogOnWindow", "A Login").WPFObject("LogOnWindow", "A Login", 1).WPFObject("_logOn").WPFObject("LogOnButton"))


  • 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);


11 Replies

  • You answered your own question!


    "Process increments everytime I login and in code I am using Sys.Process("A.Velocity.Bootstrapper", 2)."


    The next instance has index 3. If you are still using index instance 2 hardcoded it's going to look for the login box on your first instance as this is the index number of the process you are referring to.


    Given they are the same application, you are going to have to do it using the index number of top level process.



    • tristaanogre's avatar
      Esteemed Contributor

      Possibly a better way would be, in whatever method you are running to launch the processes, assign the process object to a global or project level variable.  That way you can always reference the process directly by calling the variable rather than having to worry about the process instance number.

      • Colin_McCrae's avatar
        Community Hero

        ^^^ that sounds like a pretty reasonable suggestion.


        (But my point about your hard-coded instance number still stands .... that has to go regardless)