How to invoke java method : How To …

How to invoke java method

Best practices, code snippets for common functionality, examples, and guidelines.

How to invoke java method

Postby dimabs » Fri Jun 17, 2011 7:45 pm

Hi,

I’m trying to automate some Java Applet functionality. I have an object within the applet, for which developers created couple APIs. How can I call those APIs against the object?

Thank you in advance
dimabs
 
Posts: 7
Joined: Thu Mar 24, 2011 6:49 pm

Re: How to invoke java method

Postby Support Team » Mon Jun 20, 2011 3:52 pm

You can call the API using following code snippet:

var result = <yourJavaElement>.Element.InvokeAction
             (“invokemethod”, <methodname>, <parameters>,...);

You can use following data types as parameters:
  • long
  • int
  • string
  • bool
  • null
With this method you should be able to invoke all public methods provided by your API.
Please make sure, that you are working with our latest Java plug in to make sure that everything works as expected from our blog:
http://www.ranorex.com/blog/automation- ... plications
WARNING: Since Ranorex 3.1 the Java plugin is already delivered with the Ranorex setup. See the User Guide on how to instrument your Java application for automation.

Regards,
Tobias
Support Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to invoke java method

Postby dimabs » Tue Jun 21, 2011 1:47 am

Thank you. I will try it

Dima
dimabs
 
Posts: 7
Joined: Thu Mar 24, 2011 6:49 pm

Re: How to invoke java method

Postby dimabs » Thu Oct 13, 2011 7:22 pm

Here is the problem. I have a method to invoke, which was provided by developers as public. However, method's input parameter is object type of java.awt.Rectangle. Based on your explanation above, I can only use primitive variables to invoke the methods. So what is the possible solution for me?

Thank you,
Dima
dimabs
 
Posts: 7
Joined: Thu Mar 24, 2011 6:49 pm

Re: How to invoke java method

Postby Support Team » Fri Oct 14, 2011 1:24 pm

dimabs wrote:So what is the possible solution for me?

Sorry but currently you can only use the primitive ones as mentioned above. I will add a feature request to our internal bug tracking system to allow more objects.

Regards,
Peter
Ranorex Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to invoke java method

Postby dimabs » Fri Oct 14, 2011 11:38 pm

Thanks. Hopefully, in the near future, it will be implemented, as it is a key for Java Applet UI based automation

Thank you,
Dima
dimabs
 
Posts: 7
Joined: Thu Mar 24, 2011 6:49 pm

Re: How to invoke java method

Postby dimabs » Wed Oct 19, 2011 2:16 am

What about a case scenario when involved java method returns an object, for instance Java Table?

Thank you,
Dima
dimabs
 
Posts: 7
Joined: Thu Mar 24, 2011 6:49 pm

Re: How to invoke java method

Postby Support Team » Fri Oct 21, 2011 2:14 pm

Hi,

This is not possible at the moment, you can just handle data types like int, string, bool, or null.
Peter has already added a feature request to support more data types.

Regards,
Markus
Ranorex Support Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to invoke java method

Postby Prad » Thu Apr 26, 2012 5:46 pm

Hi ,

Could you please provide some additional examples / sample code

on how exactly to use this ,
since based on the example / outline provided

the codes does not compile at all.

for eg.

how do i use this to call the IsPrinting function for the JideTable object ?

http://www.jidesoft.com/javadoc/com/jid ... ePrinting()


Regards,
Prad
Prad
 
Posts: 8
Joined: Wed Feb 22, 2012 12:50 am

Re: How to invoke java method

Postby Support Team » Fri Apr 27, 2012 4:17 pm

Hi,

Are you sure you sent us the right link, because I can't find the specific isPrinting method?
You can also try to use the InvokeMethod of the specific java control, for additional information please take a look at our .Net Api Documentation, just click, in Ranorex Studio, on Help->Api .Net Documentation.

Regards,
Markus
Ranorex Support Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to invoke java method

Postby Prad » Fri Apr 27, 2012 9:01 pm

The link is fine ,

its just that when you click on the link , it misses the closing parenthesis

http://www.jidesoft.com/javadoc/com/jid ... ePrinting()

that function was just for a reference as a test function

It would be of help if you can send me an example of how to use the InvokeMethod ,

since even when all the references are included , i am unable to resolve the InvokeMethod API ,
and get an error stating Ranonrex.Core.element does not contain a definition for "InvokeMethod"

Thanks & Regards,
Prad
Prad
 
Posts: 8
Joined: Wed Feb 22, 2012 12:50 am

Re: How to invoke java method

Postby Support Team » Mon Apr 30, 2012 11:29 am

Hi,

I created a small sample solution where you can see how to invoke a Java method. The files are attached.
Please also note that the API had changed, so the method Tobias mentioned had also changed, for additional information take a look at our online .Net Api.

Regards,
Markus
Ranorex Support Team
Attachments
JavaInvokeExample.zip
(369.81 KiB) Downloaded 11 times
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to invoke java method

Postby Prad » Thu May 17, 2012 9:42 pm

Hi Markus ,

Thanks for the update , was able to use your example as reference and use this function .

but if the return value is an internal java object ,
is there an example on how to use /case that java object and call functions in that object .

should the definition of the returned object be loaded / created in the project ,

if yes ,
how to define or inherit java objects in ranorex ?


Thanks & Regards,
Pradeep
Prad
 
Posts: 8
Joined: Wed Feb 22, 2012 12:50 am

Re: How to invoke java method

Postby Support Team » Fri May 18, 2012 4:32 pm

If the returned object is a java class instance,
the returned value is a JavaObjectWrapper (in Ranorex.Plugin namespace)

You can call the same methods (GetProperty, InvokeMethod, ...) on JavaObjectWrapper.
But this object has no representation in the Ranorex Element tree (like the JavaElement has)

For example:

var javaObj = (JavaObjectWrapper)javaElement.GetPropertyValue("YourComplexProperty");
var name = (string)javaObject.GetPropertyValue("SomeStringProperty");
//or, for example:
javaObject.InvokeMethod("DoSomething", 1, true);


Michael,
Ranorex Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to invoke java method

Postby Prad » Wed May 23, 2012 4:52 pm

Hi ,

Thanks for the response , it helps ,

but how would this work when the return value is just not one class instance
but an array of class instances ,

could you please provide some info/examples on how to loop on each object
and execute an invokeMethod/Invoke on each of the elements in the array

Thanks & Regards,
Pradeep
Prad
 
Posts: 8
Joined: Wed Feb 22, 2012 12:50 am

Next

Return to How To …

Who is online

Users browsing this forum: No registered users and 0 guests