STAF does  not provide a specific interface to run a QTP test.  But STAF's 
PROCESS service has a START request that lets you run most any command on 
a local or remote machine (that's also running STAF).  So, if you know how 
to run your QTP script from the command line, then you can use the STAF 
PROCESS service's START request to submit the command that runs your QTP 
script.  For example:

  STAF <local or remote machine> PROCESS START SHELL COMMAND <QTP command> 
RETURNSTDOUT STDERRTOSTDOUT WAIT

If you don't know why to run a QTP script from the command line google for 
this info.  For example, I googled and found that you can run a QTP script 
from the command line as follows using the QTP-Plus pack for "QuickTest 
Command Line Utility" as talked about at 
http://www.sqaforums.com/showflat.php?Number=377374:

  QuickTestLauncher /t <testname> /r <resultdirectory> /log /close

Or, you can create a .vbs file which launches QTP and runs a test so you 
can run a .vbs file as your command instead .  For example:  cscript <.vbs 
file name>

Once you've figured out how to run your QTP script via the command line, 
you should be able to run your QTP test command via STAF and return the 
results:

  STAF <machine> PROCESS START SHELL COMMAND "<QTP command>" RETURNSTDOUT 
STDERRTOSTDOUT WAIT

Depending on where your QTP scripts logs data, you could also use the 
RETURNFILE <FileName> option, specifying the name of your QTP log file as 
an option in the PROCESS START request.  See section "8.12 Process 
Service" in the STAF User's Guide at 
http://staf.sourceforge.net/current/STAFUG.htm#HDRPROCSRV for more 
information on running a command on a remote machine using STAF's PROCESS 
service.

Once you've figured out the PROCESS START request that you want to use, 
then you can submit the PROCESS START request via a Java program.  The 
STAF Java User's Guide at http://staf.sourceforge.net/current/STAFJava.htm 
provides examples on how to submit any STAF service request, such as a 
PROCESS START request and get its result.  See the 4th example in section 
"3.1.1 Class STAFHandle", sub-section "Examples":

This is an example of creating a new STAFHandle and using the submit2() 
method to submit requests to STAF. Note that since auto-unmarshalling is 
enabled by default when creating a new STAFHandle, the STAFResult object 
returned by the submit2() method will contain the result's marshalling 
context and root object so that you don't have to call the unmarshall() 
method to unmarshall results that contain multiple values. 

import com.ibm.staf.*;
import java.util.*;
 
public class STAFTest
{
    public static void main(String argv[])
    {
        try
        {
            // Create a STAFHandle

            STAFHandle handle = new STAFHandle("MyApplication");
            System.out.println("My handle is: " + handle.getHandle());

            try
            {
                // Submit a request to the PROCESS service to run a 
command on
                // a machine and wait for it to complete and returns its 
stdout
                // and stderr.  Note that the result from this request 
returns
                // a marshalled map so we'll use STAFResult's resultObj 
variable
                // to access the map root object

                String machine = "local";

                // Specify your QTP command information here
                String qtpDir = "C:\\Program Files\\Mercury 
Interactive\\QuickTest Professional";
                String qtpTest = qtpDir + "\\Tests\\YourTestName";
                String qtpResultDir = "C:\\Tests\\results";
                String command = "QuickTestLauncher.exe /t \"" + qtpTest +
                    " /r \"" + qtpResultDir + "\" /close";
                String service = "PROCESS";
                String request = "START SHELL COMMAND " + 
STAFUtil.wrapData(command) +
                    " WORKDIR " + STAFUtil.wrapData(qtpDir) +
                    " WAIT RETURNSTDOUT STDERRTOSTDOUT";

                STAFResult result = handle.submit2(machine, service, 
request);
 
                if (result.rc != 0)
                {
                    System.out.println(
                        "ERROR: STAF " + machine + " " + service + " " + 
request +
                        " RC: " + result.rc + ", Result: " + 
result.result);
                    System.exit(1);
                }
 
                // The command was started successfully. Check the process
                // return code and if non-zero, also print an error 
message

                Map resultMap = (Map)result.resultObj;
                String processRC = (String)resultMap.get("rc");

                if (!processRC.equals("0"))
                {
                    System.out.println(
                        "ERROR: Process RC is not 0.\n" + 
result.resultContext);
                    System.exit(1);
                }

                // Print the stdout/stderr data for the command

                List returnedFileList = (List)resultMap.get("fileList");
                Map stdoutMap = (Map)returnedFileList.get(0);
                String stdoutData = (String)stdoutMap.get("data");

                System.out.println("Process Stdout:\n" + stdoutData);
            }
            finally
            {
                handle.unRegister();
            }
        }
        catch (STAFException e)
        {
            System.out.println(
                "Error (un)registering with STAF, RC:" + e.rc);
            System.exit(1);
        }
 
    }   // End of main()
 
}  // End of STAFTest


--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




"Martin, Eladio \(GMI Debt Markets\)" <eladio_mar...@ml.com> 
06/17/2009 04:20 PM

To
<staf-users@lists.sourceforge.net>
cc

Subject
[staf-users] Staf & QTP






Hello folks? 
Any sample java code to call out/remote to QTP and return results?
I would like to able to have Staf remote QTP, QTP does its automation and 
return the results?
Thoughts?
Thanks,
Eladio

This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. Unless specifically 
indicated, this message is not an offer to sell or a solicitation of any 
investment products or other financial product or service, an official 
confirmation of any transaction, or an official statement of Merrill 
Lynch.  Subject to applicable law, Merrill Lynch may monitor, review and 
retain e-communications (EC) traveling through its networks/systems. The 
laws of the country of each sender/recipient may impact the handling of 
EC, and EC may be archived, supervised and produced in countries other 
than the country in which you are located. This message cannot be 
guaranteed to be secure or error-free.  References to "Merrill Lynch" are 
references to any company in the Merrill Lynch & Co., Inc. group of 
companies, which are wholly-owned by Bank of America Corporation. 
Securities and Insurance Products: * Are Not FDIC Insured  * Are Not Bank 
Guaranteed  *  May Lose Value  *  Are Not a Bank Deposit * Are Not a 
Condition to Any Banking Service or Activity * Are Not Insured by Any 
Federal Government Agency.  Attachments that are part of this 
E-communication may have additional important disclosures and disclaimers, 
which you should read. This message is subject to terms available at the 
following link: http://www.ml.com/e-communications_terms/.  By messaging 
with Merrill Lynch you consent to the foregoing.

 
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to