How can I use my app methods for automation?

Best practices, code snippets for common functionality, examples, and guidelines.
Ivg
Posts: 6
Joined: Mon Feb 01, 2016 2:29 pm

How can I use my app methods for automation?

Post by Ivg » Mon Feb 01, 2016 2:33 pm

Hi,

I'm testing Java Swing app.

I'm writing the auto tests with visual studio.

There is some functionality that isn't available throw Ranorex's adapters.

How can I access my app's methods? (with reflection I guess)

Thanks

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: How can I use my app methods for automation?

Post by RobinHood42 » Tue Feb 02, 2016 4:31 pm

Hi Ivg,

I've seen that there was already a similar question asked here: http://www.ranorex.com/forum/how-to-inv ... t2320.html

Hope this helps.

Cheers,
Robin
Last edited by RobinHood42 on Wed Feb 03, 2016 1:26 pm, edited 1 time in total.

Ivg
Posts: 6
Joined: Mon Feb 01, 2016 2:29 pm

Re: How can I use my app methods for automation?

Post by Ivg » Tue Feb 02, 2016 6:32 pm

Hi,

I think there is a mistake with the link, it doesn't lead to other post.

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: How can I use my app methods for automation?

Post by RobinHood42 » Wed Feb 03, 2016 1:27 pm

Hi,

I'm sorry. The link should now be correct :)

Cheers,
Robin

Ivg
Posts: 6
Joined: Mon Feb 01, 2016 2:29 pm

Re: How can I use my app methods for automation?

Post by Ivg » Wed Feb 03, 2016 4:18 pm

Thanks!

On ranorex site there is a page with code examples (I can't post links because my account is new), I noticed a specific example : "Create Adapters to Access More Properties and Methods".

Will it work with Java methods too?

I can't test it, I need the class 'Ranorex.Control' but I can't find it, was it deprecated?
I've add to my project the reference and using of "Ranorex" assembly

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How can I use my app methods for automation?

Post by krstcs » Wed Feb 03, 2016 5:28 pm

The Ranorex API will help you: http://www.ranorex.com/Documentation/Ranorex/

Ranorex.Control : Adapter

It's under the Ranorex (very first) tree item.
Shortcuts usually aren't...

Ivg
Posts: 6
Joined: Mon Feb 01, 2016 2:29 pm

Re: How can I use my app methods for automation?

Post by Ivg » Wed Feb 03, 2016 5:59 pm

Thanks, but I still can't find it while working on my visual studio project, very strange.

I have 2 issues now:

1. I've searched and found that two options are available for using java methods with the Ranorex.JavaElement type.

public virtual void InvokeMethod(string name);
public object InvokeMethod(string methodName, params object[] args);

This overloading doesn't allow to invoke method without parameters, but WITH return value.
Is there any other option to do it? can you add this option please?


2. I've tried to invoke simple java method of the JComboBox type, but I always get "ActionFailedException". What am I doing wrong? What should I check?
I noticed when I'm running the program I always get this warning from Ranorex: "[Java AWT/Swing]: Failed to instrument Java process. Please make sure you have enough privileges to access the process."
I am Administrator on the computer.
So far I used only Ranorex's adapters and this warning wasn't affected me.
Is it related to the fact I can't invoke Java methods? How to solve this warning?

Thanks a lot!

log
Certified Professional
Certified Professional
Posts: 14
Joined: Tue Mar 24, 2015 6:28 am
Location: Sydney, Australia

Re: How can I use my app methods for automation?

Post by log » Thu Feb 04, 2016 3:49 am

Hi Ivg,

Just thought I'd comment on a couple of things here.

1. Regarding invoking a method without parameters, but WITH a return value, you can use the second overload,
public object InvokeMethod(string methodName, params object[] args);

The params keyword is for a variable number of arguments, include zero, which means that you can use
public object InvokeMethod(string methodName). See MSDN documentation about the params keyword at https://msdn.microsoft.com/en-us/library/w5zay9db.aspx

2.If you are receiving a warning from Ranorex about a failure to instrument the Java process, can you check if you have set up instrumentation Java applications by Ranorex? There are some directions at http://www.ranorex.com/support/user-gui ... swing.html, though that page of the User Guide does say that Java instrumentation is enabled automatically with Ranorex 5.0.0 and up.

Hope that helps,
Gabriel

Ivg
Posts: 6
Joined: Mon Feb 01, 2016 2:29 pm

Re: How can I use my app methods for automation?

Post by Ivg » Thu Feb 04, 2016 9:51 am

Hi log,

Thanks for your answers!

1. The overloading mechanism doesn't take in consideration the return value, so what I have is:

InvokeMethod(string)
InvokeMethod(string, params object[]);

It always takes the first option when I'm calling a method without parameters, because it's not making any sense making another method and call it without parameters, you already have it in the first method.

2. I have the latest Ranorex version (I'm using the trial version, testing it for my company)
So this link is not relavant for me.

Ivg
Posts: 6
Joined: Mon Feb 01, 2016 2:29 pm

Re: How can I use my app methods for automation?

Post by Ivg » Thu Feb 04, 2016 10:53 am

The ActionFailedException I got is my mistake: I've tried to use "InvokeMethod(string)" with a method that returns a value, that's what cause it.

So my only (and significant) problem is that for now I can't find the option to invoke java method that gets no parameters but returns a value.

This will really affect the decision if my company will purchase Ranorex, so if this option exists please let me know as soon as possible (:

Thanks!

log
Certified Professional
Certified Professional
Posts: 14
Joined: Tue Mar 24, 2015 6:28 am
Location: Sydney, Australia

Re: How can I use my app methods for automation?

Post by log » Fri Feb 05, 2016 1:57 am

Hi Ivg,

Ah yes, my mistake, resolution of overloaded methods doesn't take the return type into account. Sorry!

With regards to invoking a Java method with no parameters and a return value, I hope the Support Team can come up with something.

Thanks,
Gabriel

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How can I use my app methods for automation?

Post by Support Team » Thu Feb 11, 2016 4:47 pm

Hello Ivg,

You should be able to work around the issue with the following lines of code:

Code: Select all

Object[] param = new Object[0];     
JavaElement myElement =  repo.Java.Self.As<JavaElement>();
var returnVal = myElement.InvokeMethod("myMethodToInvoke", param);
Please let me know if this solves the issue.

Sincerely,
Johannes