The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:




Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> AutomatedQA / SmartBear TestComplete

Pages: 1 | 2 | >> (show all)
MrVersion
Member


Reged: 04/14/08
Posts: 190
Launching Applications with Script - Not TesteApps
      #697147 - 01/31/12 07:35 AM

I've figured out how to launch a java application using TestedApps. All you need to do is provide the path to the .jnlp as a paramter to the javaws.exe.

However, how could I launch a java application with a script/function? I'd want to pass it a paramter (jnlp name) to do that. I've searched but could't find anything in the help. Doesn't mean that it's not there, I just didn't see it.

I'd think the advantage of doing it this way would be that the application could be launched at any time, in any script without having to add it to TestedApps for every test or suite.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Robert MartinModerator
Super Member


Reged: 03/22/06
Posts: 1836
Loc: Pennsylvania, USA
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697152 - 01/31/12 08:17 AM

I don't know if it would work for Java apps, but I know what I did for Delphi apps to do the same sort of thing. I don't know much at all about launching Java apps so I may be revealing some of my ignorance but, if it can be launched at a command line, you can implement the WScript.Shell object and use the "Exec" method to run any command line text. I do this for executing SQL queries and other minor script things.

--------------------
-Robert Martin
Automated Testing Evangelists
TestComplete "expert"
Definition expert - noun - Unknown drip under pressure


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: Robert Martin]
      #697162 - 01/31/12 09:57 AM

I'll give that a try Robert, thanks. If it works, I'll post it here for others.

BTW, you mentioned that you use this for some SQL queries. I thought TC had a way to directly access the DB. True?


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697170 - 01/31/12 10:31 AM

Hmm. No such luck as of yet. In case anyone else wants to take a whack at it, here's the parameters in TestedApps:

File Name: javaws.exe
File Path: ..\..\..\..\Program Files\Java\jre6\bin\
Parameters: Command line: "\\home\apps\health.jnlp"


and here's the code that doesn't work:

function launchJavaApp() {
var shell = new ActiveXObject("WScript.shell");
Log.Message(aqConvert.VarToStr(shell));
shell.run("\\home\apps\health.jnlp");
}

Error: An exception occurred in the "Defaults" unit at line 98:
The system cannot find the path specified


Post Extras: Print Post   Remind Me!   Notify Moderator  
Robert MartinModerator
Super Member


Reged: 03/22/06
Posts: 1836
Loc: Pennsylvania, USA
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697173 - 01/31/12 10:43 AM

Try something else..

Code:
var shell = Sys.OleObject("WScript.Shell")



You might, also, want to do it like so

Code:
shell.run("..\\..\\..\\..\\Program Files\\Java\\jre6\\bin\\javaws.exe \\\\home\\apps\\health.jnlp")



Again, my ignorance at doing java apps may be showing but, essentially, in the Run command, you want to note exactly what you would type in at a command line to run your app. Note, also, when working with JScript, the backslash character is a special character so, to actually send a backslash, you need to double it up....

--------------------
-Robert Martin
Automated Testing Evangelists
TestComplete "expert"
Definition expert - noun - Unknown drip under pressure


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: Robert Martin]
      #697187 - 01/31/12 01:08 PM

OK, I've tried 8 ways to Sunday to get it to work commandline. No luck with that, but I did find a solution. It still uses TestedApps, but it's pretty dynamic. I'll finish it up and post the function along with my reasoning tomorrow.

Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697297 - 02/01/12 10:59 AM

OK, here's my solution - so far. It works fine, but there's error handling that needs to be done, it probably needs to become a script extension, and based on the error handling that I need/want to do, questions are raised. Here's the code so far:

Code:
  
///////////////////////////////////////////////////////////////////////////////
// This function will simply launch a java application via a .jnlp file. //
// You must pass it in the prefixed name for the .jnlp file. For example, //
// if your filename is health.jnlp, you should pass in just health as the //
// paramter. //
// //
// Example call: launchJavaApp("health"); //
///////////////////////////////////////////////////////////////////////////////
function launchJavaApp(jnlpName) {
var javaBinDir = "C:\\Program Files\\Java\\jre6\\bin";
var jnlpDir = "\\\\<your path>" + jnlpName + ".jnlp";
var testApp = jnlpName + "App";

//First thing to do is remove the TestedApp if it already exists.
//Somebody forgot to clean up.
deleteTestedApp(testApp);

try{
//All java applications will be using the javaws executable.
TestedApps.Add("javaws");

//Set the FileName (executable) value
TestedApps.javaws.FileName = "javaws.exe";

//Since it's a java application, we must pass the executable the full
//path of the .jnlp file that we are trying to launch.
TestedApps.javaws.Params.SimpleParams.CommandLineParameters = jnlpDir;

//Provide the path to where the java executable is.
TestedApps.javaws.Path = javaBinDir;

//Launch the application.
TestedApps.javaws.Run();

//It's important to change the Item name, as this is the TestedApps
//name that you'll see in the TC GUI. You can use name this to access
//the methods for the TestedApp.
TestedApps.javaws.ItemName = testApp
}
catch(err){
Log.Error(testApp + " application did not launch. Error: " + err);
}
}



And here is the delete code:

Code:
 
////////////////////////////////////////////////////////////////////////////////
// This function will simply remove a TestedApp from TestedApps in TC. This //
// function can be called on it's own or wrapped into another fucntion. //
// At the very least, it should be one of the last functions called at the //
// end of any test that has created a TestedApp. //
// //
// Example call: deleteTestedApp("HealthApp"); //
////////////////////////////////////////////////////////////////////////////////
function deleteTestedApp(testedAppName){
appNum = TestedApps.Find(testedAppName);
TestedApps.Delete(testedAppName);
}



It would be great if we could make this sort of a "case study" of sorts to help folks out and start to understand a few things regarding TC. I know I need the help, so I'm guessing that others do too.

The reasoning behind this code is that I can now launch any java application (via a .jnlp) from within any of my test scripts. The only thing I have to remember to do is remove the TestedApp when the test is done. If I forget, the delete handles it for me.

Edited by MrVersion (02/01/12 11:10 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697298 - 02/01/12 11:07 AM

OK, first error handling in my mind is to check that the application actually launched. Using some of Robert's code from yesterday, we could have something like this:

Code:

var myApp = Sys.Process("javaw").WaitSwingObject("ClinicGUI", "Client Health Clinic", 10000);
var appLaunched = myApp.VisibleOnScreen;
Log.Message(aqConvert.VarToStr(appLaunched));



This causes me to wonder about a few things. Since I'm using the functions previously written (see above), the process description will be different for every java application that's been launched. So, the first question is what to do about that? Do we take the process descriptions and create a list of them in a script? Do we somehow, someway find a link from the parameter that we pass launchJavaApp that will help us to identify the process description? Without that description, we don't know what to give WaitSwingObject. Hmm.

The other thing that I've noticed, is that right now for me, there really isn't a direct correlation between the TestedApp and the process. For example, I can do this with the TestedApp:

TestedApp.healthApp.Run();

and that's all fine and dandy. But to see if the TestedApp has actually launched, I must use the process. Hmm. In other words, I can't do this:

TestedApp.healthApp.VisibleOnScreen;

Edited by MrVersion (02/01/12 11:16 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Robert MartinModerator
Super Member


Reged: 03/22/06
Posts: 1836
Loc: Pennsylvania, USA
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697379 - 02/02/12 05:34 AM

Actually, yes you can. When you run an app via TestedApp, it returns the process object. So, you could do.

Code:
var myAppProcess = TestedApp.healthApp.Run()



--------------------
-Robert Martin
Automated Testing Evangelists
TestComplete "expert"
Definition expert - noun - Unknown drip under pressure


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: Robert Martin]
      #697382 - 02/02/12 05:48 AM

Thanks Robert, that will come in really handy. I was trying to see how I could get a handle on things, and there it is. Little confused about on thing though. If I can get a handle on the process object, I'm not seeing how I can implement that with WaitSwingObject.

Edited by MrVersion (02/02/12 05:52 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697388 - 02/02/12 06:14 AM

OK, I think I have it. I actually created a new function (addJavaTestedApp) that only creates the TestedApp, but does not run it. From there, this appears to be working:

Code:

addJavaTestedApp("health");
var healthProcess = TestedApps.health.Run();
Sys.Process("javaw").WaitSwingObject(healthProcess, 10000);



Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697390 - 02/02/12 06:23 AM

Oddly enough, this code doesn't work:
Code:

addJavaTestedApp("health");
var healthProcess = TestedApps.health.Run();
Sys.Process("javaw").WaitSwingObject(healthProcess, 20000);
var isVisible = healthProcess.VisibleOnScreen;
Log.Message(isVisible);



It throws this: "You are trying to call the "VisibleOnScreen" method or property of the "javaws.exe" object that does not exist."

WaitSwingOBject appears to work fine, and the application is visible.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Robert MartinModerator
Super Member


Reged: 03/22/06
Posts: 1836
Loc: Pennsylvania, USA
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697392 - 02/02/12 06:29 AM

That's because the process doesn't have a "VisibleOnScreen" property. The SwingObject does. Change your code to

Code:
addJavaTestedApp("health");
var javaProcess = TestedApps.health.Run();
var healthapp = javaProcess.WaitSwingObject(healthProcess, 20000);
var isVisible = healthapp.VisibleOnScreen;
Log.Message(isVisible);



See, the process in question that you have is the java process that is executed with a specific command line. What you want to detect is whether or not a particular form generated by that process is visible on screen, hence the VisibleOnScreen checked against the SwingObject, not against the process.

--------------------
-Robert Martin
Automated Testing Evangelists
TestComplete "expert"
Definition expert - noun - Unknown drip under pressure


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: Robert Martin]
      #697402 - 02/02/12 06:58 AM

Thanks Robert, I see the flow. There still is an issue in this line:

Code:

var healthapp = javaProcess.WaitSwingObject(healthProcess, 20000);



healthProcess no longer exists (it was what we now call javaProcess). healthProcess should actually be healthSwingObject. Given that we know what the TestedApp object process is, can we find the SwingObject? I think if I can get this figured out and understood, it will help with other things down the road. In this example, I'm trying to determine if the application launched and is visible on the screen. The attack method at this point is TestedApps. I have other tests that will launch a Java app, but with a link and not TestedApps, so I won't have a handle to the Process object at that point. I'm still going to need to test if it launched and it is visible, but there will not be a TestedApp object for it. I'm thinking that I'll have to search for the process, and from there get the SwingObject. So I suppose, the questions that I have are as follows:

1. Given the process object, can I find the SwingObject?
2. Given the TestedApp object, can I find the process and/or the SwingOBject?

I think I'm confusing myself, so I know I'm confusing you. Thanks for the help.

Edited by MrVersion (02/02/12 07:00 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Robert MartinModerator
Super Member


Reged: 03/22/06
Posts: 1836
Loc: Pennsylvania, USA
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697404 - 02/02/12 07:11 AM

Okay...

Quote:

1. Given the process object, can I find the SwingObject?




Yes. So, above, we have a process that is an instance, in windows, of Sys.Process("javaw"). No matter how you get to it, it's the same process essentially unless you've launched multiple java apps simultaneously in which case and index may be necessary.

So, when you launch it using TestedApps or using some other method, you'll still have an instance of Sys.Process("javaw") which will have child objects. Now, the assumption you are making and that I'm working off of is that the SwingObject you're looking for is an immediate child of the process. So, our code looks like this:

Code:
//This line runs the javaw process with the commandline parameters as discussed above to launch the specific java app.
//What is returned is the javaw process, not the java app.

var javawProcess = TestedApps.healthapp.Run();

//The problem before which I just caught is that you were passing in the process object
//to the WaitSwingObject method. This is incorrect. You need to pass in
//either the native object name or a combination of class and caption

var healthAppSwingObject = javawProcess.WaitSwingObject("SwingObjectClassName", "SwingObjectCaption", 20000);

//Now we have a swing object. It could be empty in which the Exists property returns false or it could
//be your actual object which will have all available properties.

if (healthAppSwingObject.Exists) then
{Log.Message("Found my app")}
else {Log.Warning("app not found")}



At this point, I think I've answered your second question as well. Have I clarified? Or are you still confused?

--------------------
-Robert Martin
Automated Testing Evangelists
TestComplete "expert"
Definition expert - noun - Unknown drip under pressure


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: Robert Martin]
      #697406 - 02/02/12 07:23 AM

Let me get into it and do some tweaking. You've been a great help so far, and I appreciate it.

Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697408 - 02/02/12 07:32 AM

OK, looked at it, and I'm not as cionfused as I thought I was, I think I was thinking what you explained. Of course, it prompts just a couple more questions!

1. Possible to get the SwingObjectClassName and SwingObjectCaption from the process?
2. Is it SMART to do that, or do we just make a bunch of constants for the SwingOBject description and put them in a library somewhere?

At this point in my novice TC career, all I know for sure that I have in a test is the TestedApp object, and if I run that object, I now have a handle to the process object for that TestedApp (see question 1 above).

Maybe I'm trying to be too "elegant" and maybe my QTP brain is taking over and I'm trying to force TC to do things "just like we did in QTP".


Post Extras: Print Post   Remind Me!   Notify Moderator  
Robert MartinModerator
Super Member


Reged: 03/22/06
Posts: 1836
Loc: Pennsylvania, USA
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697411 - 02/02/12 07:46 AM

Quote:

1. Possible to get the SwingObjectClassName and SwingObjectCaption from the process?




The WaitSwingObject method is for detecting, within the parent object (in this case, the process), whether or not a specified SwingObject exists based upon a set of previously known parameters. You need to first know what the class name and caption are before you can search the process to find it. So, no, you cannot do so.

Quote:

2. Is it SMART to do that, or do we just make a bunch of constants for the SwingOBject description and put them in a library somewhere?




As described above, no, you don't want to try and find the class name and caption of an object in order to find the object... that's kinda bootstrapping things. As for creating constants, that's one way...but honestly, at this point, we can start looking back at using NameMapping and aliases. I know you want to try and avoid that, but, honestly, it will make your life a lot easier because, essentially, that's what you're asking. You want to store off somewhere the specifics about the objects you want to interact with in order to make your automation code more intuitive. That is, in essence, the purpose of NameMapping and Aliases.

So... let's say that we've created, in NameMapping, a mapping to your swing object. In that mapping, you can specify the identification parameters as you want them ahead of time. So, be default, your object would show up in code like so.

Code:
Aliases.Sys.javaw.healthAppSwingObject



Now... in your Aliases editor (not the NameMapping panel), drag healthAppSwingObject to the root level and you can now reference that object everywhere as

Code:
Aliases.healthAppSwingObject



Built in to NameMapping is an auto-wait... but you can override that by using WaitAliasChild. So, you're code you've worked so diligently on could be reduced to the following

Code:
TestedApps.healthApp.Run();
if (Aliases.WaitAliasChild("healthAppSwingObject", 10000).Exists) then
{Log.Message("found it!")}
else {Log.Warning("nope")}



Six one way, half a dozen the other... but the key point in your above queries is that you need to know the name and caption ahead of time. However you decide to implement your code, this does not change. Whether you use constants, NameMapping, or hardcoded strings within your automation, there's no way to avoid this.

--------------------
-Robert Martin
Automated Testing Evangelists
TestComplete "expert"
Definition expert - noun - Unknown drip under pressure


Post Extras: Print Post   Remind Me!   Notify Moderator  
MrVersion
Member


Reged: 04/14/08
Posts: 190
Re: Launching Applications with Script - Not TesteApps [Re: Robert Martin]
      #697440 - 02/02/12 11:13 AM

I'm not opposed to NameMapping for the Java applications at all. There are some objects that I'm going to want to "wildcard", but I'll figure that out as I go. Using the NameMapping and Aliases, I can get it down to a few simple lines:
Code:

launchJavaApp("health");
var isVisible = Aliases.HealthApp.VisibleOnScreen;
Log.Message(isVisible);



Unfortunately, time is running low on the eval, so I need to move on to some other ideas/techniques. I really appreciate your help and opinion on TC, and I'll probably be posting quite a bit here with issues that I'm facing.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Robert MartinModerator
Super Member


Reged: 03/22/06
Posts: 1836
Loc: Pennsylvania, USA
Re: Launching Applications with Script - Not TesteApps [Re: MrVersion]
      #697443 - 02/02/12 11:24 AM

not a problem! Let me know if there's anything else I can help with.

--------------------
-Robert Martin
Automated Testing Evangelists
TestComplete "expert"
Definition expert - noun - Unknown drip under pressure


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1 | 2 | >> (show all)



Extra information
0 registered and 16 anonymous users are browsing this forum.

Moderator:  NickAQA, Robert Martin, martinh, brentpaine 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 13001

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5