Really use ranorex with visual studio for desktop .net apps?

Best practices, code snippets for common functionality, examples, and guidelines.
zonic
Posts: 4
Joined: Thu Feb 22, 2018 10:05 am

Really use ranorex with visual studio for desktop .net apps?

Post by zonic » Thu Feb 22, 2018 1:41 pm

Is someone really use Ranorex with Visual Studio for testing desktop .net apps? Maybe some examples?

We've been trying Ranorex in our desktop wpf software company and faced issues with Visual Studio integration.

We've checked your user guide and tried proposed example - it works fine. But when we tried to write manually test code for our apps we stuck at the first button. At calc.exe buttons are simple default buttons and at our project it's some object with icon+text. So when we asked ranorex to click such button - nothing happens(it seems ranorex trying to click between icon and text). Next we tried to move mouse over button's text and emulate left mouse click - but it seems impossible using ranorex. We googled such case and didn't find an answer.

In other hand recorded cases are working fine, but we need to manage code at VS only - cause apps are being changed very often and recorder use sometimes buttons name or even offsets/coordinates - such test won't be working after even a slight app changes.

We examined recorded test cases and there another syntax - not the same as at VS integration guide. Is there some way to use generated by recorder code, edit it and then use in VS?

Trial is ending but still we can't decide to buy it or not, please help.

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Really use ranorex with visual studio for desktop .net apps?

Post by McTurtle » Fri Feb 23, 2018 2:20 pm

Hello zonic,

Yes, absolutely, many people use VS in order to write their tests.

I quickly looked over the blog now... I think that you are missing two key pieces of information:

1. You can still use Ranorex Spy in order to find your RanoreXPaths and then copy them into your VS code.

2. I guess you were checking the code generated by Ranorex by right clicking on an action and then clicking "View Code"? Please click on "Convert to user code". You will see that this code is much more similar to the code that you see in the blog about VS integration. Maybe you can copy and edit this code?

Does this help?

Regards,
McTurtle

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Really use ranorex with visual studio for desktop .net apps?

Post by odklizec » Mon Feb 26, 2018 8:51 am

Hi,
zonic wrote: In other hand recorded cases are working fine, but we need to manage code at VS only
Why? The problem of using VS-only approach is, that you are loosing Ranorex element repository (and some other things). And repository is, in my opinion, a crucial element for test maintainability and successful long-term usage. Without repository, you need to generate all xpaths manually (with spy) and edit them in code. And this is what makes the tests difficult to maintain.

With repo, you can do UI changes pretty easily. For example, multiple elements could be changed by editing single root folder, while in code you will have to edit every single xpath. I think it's much harder to keep the things organized and working with increasing number of xpaths handled in code? All in all, I personally can't find a good reason why to drop repository (and other Ranorex Studio specific things) in favor of using VS? Of course, for experienced VS users, it may feel "easier" to jump into coding. But I'm pretty sure, that from the long term perspective, using Ranorex Studio is not only faster but also much more reliable, because UI mapping is easier, more reliable and secure.
zonic wrote:apps are being changed very often and recorder use sometimes buttons name or even offsets/coordinates - such test won't be working after even a slight app changes.
This is exactly where nicely constructed and maintained repository should help you. Of course, it always depends on the quality of xpaths behind the mapped elements. If the xpaths are easy to break with a lot of indexes and unstable attributes, then yes, the test could fail. Could you please post an example of xpaths you are using?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

zonic
Posts: 4
Joined: Thu Feb 22, 2018 10:05 am

Re: Really use ranorex with visual studio for desktop .net apps?

Post by zonic » Mon Feb 26, 2018 3:59 pm

First of all, thanks for response!
McTurtle wrote:Could you please post an example of xpaths you are using?
Button object:
/form[@name='MyApp']/?/?/button[@automationid='btnQuickBuy']
Button icon:
/form[@name='MyApp']/?/?/button[@automationid='btnQuickMount']/picture[@automationid='ButtonImage']
Button label:
/form[@name='MyApp']/?/?/button[@automationid='btnQuickMount']/text[@name='Quick Buy']
McTurtle wrote: Maybe you can copy and edit this code?
Click at 'Quick buy' button doesn't work after recording steps by recorder cause it's trying to use button object, so I use text label and then stets are run ok.
After converting to 'user code' I get = 'textInfo.FindAdapter<Text>().MoveTo();' - and this I can't use at VS.

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Really use ranorex with visual studio for desktop .net apps?

Post by McTurtle » Tue Feb 27, 2018 3:26 pm

Hello zonic

The FindAdapter<Text>().MoveTo() methods expect textInfo to be of a type RepoItemInfo, as you can see in the arguments section of the method after you have converted it.

In order to directly create elements form RanoreXPaths, you can look at the first example under this link: Advanced Code Examples

Does this help?

Regards,
McTurtle

zonic
Posts: 4
Joined: Thu Feb 22, 2018 10:05 am

Re: Really use ranorex with visual studio for desktop .net apps?

Post by zonic » Fri Mar 09, 2018 12:16 pm

McTurtle wrote:Hello zonic
Does this help?
Thanks for help, but I actually gave up idea to use VS. It seems my general skills at other languages and IDEs just not enough for setting things up.
I tried to use ranorex studio making recordings manually and it seems not bad.
The one thing that I still miss and why I wanted to use manually written tests it's that I can't use repository items as variables to make re-usable recordings. Or there is some way to do it?
It's the last issue that ranorex studio cannot resolve for me or I don't get how it's possible and that is why manual tests at VS using ranorex API is still looks much more powerfull for me.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Really use ranorex with visual studio for desktop .net apps?

Post by odklizec » Fri Mar 09, 2018 12:37 pm

zonic wrote: The one thing that I still miss and why I wanted to use manually written tests it's that I can't use repository items as variables to make re-usable recordings. Or there is some way to do it?
It's the last issue that ranorex studio cannot resolve for me or I don't get how it's possible and that is why manual tests at VS using ranorex API is still looks much more powerfull for me.
Could you please a bit elaborate what exactly you want to achieve (use case)?

It's possible to assign repo items as user code parameters. I'm using it frequently in my tests and it works quite well. Basically, I have come common methods, with repoiteminfo parameters, which, if needed, are converted to Ranorex Adapters (inside the method). So yes, it's possible to pass a repo elements to methods via method parameters. You can find more details about creating user code methods (with repo elements as method parameters) here:
https://www.ranorex.com/help/latest/les ... de-actions

In my opinion, using Ranorex Studio is way more powerful, just because of Repository and Test Suite management. Without repository, you must handle all elements in code (via their xpaths) and basically create your own element management. Using repository is much easier, faster and I believe also safer way of handling GUI elements.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

zonic
Posts: 4
Joined: Thu Feb 22, 2018 10:05 am

Re: Really use ranorex with visual studio for desktop .net apps?

Post by zonic » Fri Mar 09, 2018 3:04 pm

odklizec wrote: Could you please a bit elaborate what exactly you want to achieve (use case)?
The thing is to understand how to it's works - passing repoItems as args.
Currently I'm trying to make method with 2 args(2 buttons as args) - 1st button that opens list of new buttons and 2nd button that open needed window.
It's two steps would be needed many times for testing app, cause it has name sub-mini-tools that opens in 2 clicks mentioned above. So it would be good not to create a lot of recordings like: Open tool 1, Open tool 2, etc, but make OpenTool(ToolSubMenu, ToolName) - at use it many times at test cases just passing (ToolSubMenu, ToolName) as variables.

I tried to make such method using link to help you have provided - but I stuck at moment when repoItem should be changed to variable. It's shown at help but isn't said how it's done.
Attachments
method_with_args.png
method_with_args.png (33.54 KiB) Viewed 490 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Really use ranorex with visual studio for desktop .net apps?

Post by odklizec » Fri Mar 09, 2018 3:26 pm

OK, a repository item cannot be variabilized. However, depending of your UI, it could be possible to create a generic repo item, which would be identified by xpath containing a variable. And this variable could be filled either from binded Data Connector or parameter.

This is a generic repo item, which identifies 3 different tabs (truck, crew and trailer)...
RepoVar.png
RepoVar.png (37.96 KiB) Viewed 488 times
And this is a test case structure, where each smart folder pass correct assetName to generic repository item.
TestCaseParams.png
TestCaseParams.png (61.17 KiB) Viewed 488 times
So then I can use the same recordings in each smart folder.

The above test is unfinished, so there are not all required modules yet. Some modules will be different in each smart folder. In any case, I don't need variabilized repository items, because I'm using variable directly in repo xpath. But I agree that it would be useful to have an option to add repo item as string variable (e.g. using repo element name).
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration