Wednesday, June 16, 2010

Invoke Java methods from QTP

Last time we learned how to run QTP from Java. Today I'll show you how to invoke java methods from QTP.



We use the "JavaObject" to make a call back to Java. In this example I use the following statement

JavaObject.invoke "greeting", Array()

to call the "greeting" method in java and pass in empty Array because this method do not take in any parameters.



Last time we learn how to invoke QTP from java by using QTPUtil.callQTPTest method. The QTPUtil.callQTPTest take in an optional third parameter which take in a java object that QTP can invoke it methods.

QTPUtil.callQTPTest(true, "resources/QTP_Scripts/Hello", this);

I pass the Hello object which have the "greeting" method to QTPUtil.callQTPTest. So from QTP we can invoke any methods available in this Java "Hello" object.



When running in debug mode we can put in a break point in the greeting method and see that method invoked by QTP.



From this greeting method we can debug like any normal Java program.



2 comments:

  1. Hi.Can you provide more details on how to Invoke Java methods from QTP ?

    ReplyDelete
  2. Hi.. Java method invoking is supported in qtp 9.5 and above ?

    ReplyDelete