General purpose user code

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

General purpose user code

Post by rastek » Fri Jun 19, 2015 8:08 am

I have s standart project, test suite, do not have a code library in my solution.

I have user codes in my some of recordings, I want a general-purpose user code and I want to access ıt from other recording modules. How can I achieve it ?

instead of putting it inside a recording module and call module under test cases,I want to call it from recording modules. How can I access my public Sub code inside from another user code ?

Thanks,
Rastek.
Last edited by rastek on Sat Oct 22, 2016 11:24 pm, edited 1 time in total.

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

Re: General purpose user code

Post by odklizec » Fri Jun 19, 2015 8:27 am

Hi,

All you need to do is to use inheritance as described in this blog post:
http://www.ranorex.com/blog/custom-smart-actions
Scroll down to this paragraph (don't use the link at start of the article, it has an incorrectly placed anchor;)):
Spread your Custom Action by Inheriting from a Base Class

Basically, you need to create a new "base" class, where you put methods you would like tho access from other modules. Then in each module (its user code), in which you would like to access the base class, add the base class name. Like this...
public partial class Recording1:BaseClass
From now on, you should be able to access the methods stored in base class, both from recording or its User Code. Hope this helps.
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: 185
Joined: Wed Aug 06, 2014 12:00 pm

Re: General purpose user code

Post by rastek » Mon Jun 22, 2015 7:11 am

Hi Odklizec

Thanks for the link. I tried it out but my project is written in vb net but the example is in C#. Code below gives decleration error. I could find exact code for vb.net on thw web, can you help me on this also ?

Public Partial Class AcceptCall : baseClass1

Thanks,
Rastek.

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

Re: General purpose user code

Post by odklizec » Mon Jun 22, 2015 7:55 am

Hi,

What you are looking for is "Inherits" statement...
https://msdn.microsoft.com/en-us/library/1yk8s7sk.aspx

So your code should be:
Public Partial Class AcceptCall 
Inherits baseClass1
BTW, just in case you missed it, there is an option in Ranorex to convert the C# code to VB.Net code (and vice versa). You can find it under menu Tools >> Convert code to...
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: 185
Joined: Wed Aug 06, 2014 12:00 pm

Re: General purpose user code

Post by rastek » Mon Jun 22, 2015 9:22 am

Hi

It only works if I put : character such as

Public Partial Class AcceptCall : Inherits BaseClass

When I run it it runs as success but I can not see the msgbox I put inside the function in my baseclass..

also gives a warning as
sub 'waitOnCall' shadows an overloadable member declared in the base class BaseClass'. If you want to overload the base method, this method must be declared 'Overloads'. (BC40003) - D:\Users\rastek\Documents\Ranorex\RanorexStudio Projects\Net\Net\AcceptCall.UserCode.vb:123,20

so I declared my function in my baseclass as
Public Overloads Sub waitOnCall()

but still gives the same warning and no msgbox box pop up ?

On the other hand if I put my real function with all imports in my baseclass. repo. gives error ?

Can you help for these please ?

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

Re: General purpose user code

Post by odklizec » Mon Jun 22, 2015 9:34 am

I see no way how to help you without seeing your actual code? It would be helpful if you post your solution (or at least a test one) here for review. I'm afraid, I can't help you with VB code, but maybe someone else can?
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: 185
Joined: Wed Aug 06, 2014 12:00 pm

Re: General purpose user code

Post by rastek » Mon Jun 22, 2015 9:41 am

Hi
I have solved the problem, it was calling old method written in same recording which I was commented out.

Now I can call my method in baseclass but I can not use my old recording functionality, it gives error for the repo object as below

'repo' is not declared. It may be inaccessible due to its protection level. (BC30451)

Then I added import line below that was missing, but still gives same error.

Imports Ranorex.Core.Repository

and also I added creation line for the repor object just under the class
Public Shared repo as MyRepository = MyRepository.Instance
but this time it gives this error

Type 'MyRepository' is not defined. (BC30002)

If you can help for this, it will be fine.

Thanks,
Rastek.

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

Re: General purpose user code

Post by odklizec » Mon Jun 22, 2015 1:11 pm

Hi,

Try to instantiate repository as Private, instead of Public Shared
Private repo as MyRepository = MyRepository.Instance
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: 185
Joined: Wed Aug 06, 2014 12:00 pm

Re: General purpose user code

Post by rastek » Wed Jun 24, 2015 8:28 am

Hi odklizec

I have changed public to Private but time gives error for MyRepository says it is not defined.

So far so good, anybody did not use repository in a base class before ? That shouldn't be hard like this,


Thanks,
Rastek.

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

Re: General purpose user code

Post by odklizec » Wed Jun 24, 2015 8:42 am

Too bad. I'm afraid, I can't help you with this. It works for me in C#.
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