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 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.
Code:
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();
TestedApps.Delete(AppIndex);
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);
}
}