Common function to call from different recording modules

Ask general questions here.
rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Common function to call from different recording modules

Post by rastek » Thu Oct 20, 2016 5:48 pm

Hi,
I need a common Sub how can I do that ?
Lets I have function in user code and I want to call it from different modules, how can I do that ? Currently I can only call functions from its recording module.

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

Re: Common function to call from different recording modules

Post by odklizec » Thu Oct 20, 2016 6:06 pm

Hi,

You can achieve this by 'inheritance'. You can find a very nice tutorial with description in this blog post...
http://www.ranorex.com/blog/custom-smar ... readAction
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

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Common function to call from different recording modules

Post by rastek » Fri Oct 21, 2016 8:54 am

Isn there any other way instead of creating a class ? Does has to be object oriented ?

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

Re: Common function to call from different recording modules

Post by odklizec » Fri Oct 21, 2016 9:03 am

Hi,

What's the problem with suggested "common" class and inheritance? It's pretty easy to setup and use. I don't know about any other way to achieve what you've requested.
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

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Common function to call from different recording modules

Post by Vaughan.Douglas » Tue Oct 25, 2016 2:09 pm

I agree that using class inheritance is overkill for something so simple as a common module, but Ranorex doesn't seem to allow you to import from modules.

A potential work around is to add a module.
sharedSub.png
sharedSub.png (32.24 KiB) Viewed 911 times
Added your sub to the module you just created. We'll call the sub "EatCheese".

Code: Select all

Public Module Module1
	Public Sub EatCheese
		'Do stuff
	End Sub
End Module
Then in the recorded module, you'll add a new usercode step called "PointsToEatCheese"
pointsto.png
pointsto.png (22.44 KiB) Viewed 911 times
Then in the usercode file you'll call "EatCheese" directly

Code: Select all

	Public Partial Class Recording1
		
		''' <summary>
		''' This method gets called right after the recording has been started.
		''' It can be used to execute recording specific initialization code.
		''' </summary>
		Private Sub Init()
			' Your recording specific initialization code goes here.
		End Sub
		
		Public Sub PointsToEatCheese()
			EatCheese()
		End Sub
		
	End Class
The IDE is smart enough that the EatCheese sub in the shared module will appear in the IntelliSense.
IntelliSense.png
IntelliSense.png (35.19 KiB) Viewed 911 times
You'll just want to make sure your signatures match in both cases so you can appropriately pass arguments between the usercode step and the shared module sub.

Unfortunately I don't know of a way to get "EatCheese" to be listed in the available coded steps when you try to add a coded step from the recorded module UI directly. If that is a requirement, you'll probably need to stick to the inheritance method or submit a feature request to the powers that be.
Doug Vaughan

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Common function to call from different recording modules

Post by rastek » Sat Nov 05, 2016 3:44 am

Tans Vaughan, that really helped !

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Common function to call from different recording modules

Post by Vaughan.Douglas » Tue Nov 08, 2016 1:12 pm

No problem. Glad I could help.
Doug Vaughan

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Common function to call from different recording modules

Post by Vaughan.Douglas » Mon Dec 05, 2016 3:07 pm

Updating this thread with new information. Ranorex 6.2 has incorporated this functionality into the tool.
Doug Vaughan