Friday, June 25, 2010

Invoke QTP from Java


Last time we learned how to invoke java method from
QTP by using the "JavaObject.invoke" function from QTP.
Today we'll learn how to invoke QTP from Java. Thus
we can achieve two ways commnunications between
Java and QTP.


By using QTPClient.exec method we can execute any
QTP statements from Java.

QTPClient.exec("Msgbox(\"hello QTP\")");
will display "hello QTP" message in QTP's message box






In this example we saw two way communication between
Java and QTP.

QTPClient.runQtpTest(true, "resources/QTP/Hello", new Object()
{
  public void greeting(String name)throws Exception
  {
    QTPClient.exec("Msgbox(\"hello QTP\")");
  }
});

When we run above code from Java, Java will run the QTP's
"Hello" test. In the "Hello" test we invoke the "greeting"
method in java. In Java's "greeting" method, we execute
a QTP stament to bring up the message box.



No comments:

Post a Comment