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.
General purpose user code
General purpose user code
Last edited by rastek on Sat Oct 22, 2016 11:24 pm, edited 1 time in total.
Re: General purpose user code
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...
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:BaseClassFrom 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 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
Re: General purpose user code
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.
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.
Re: General purpose user code
Hi,
What you are looking for is "Inherits" statement...
https://msdn.microsoft.com/en-us/library/1yk8s7sk.aspx
So your code should be:
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 baseClass1BTW, 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 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
Re: General purpose user code
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 ?
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 ?
Re: General purpose user code
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 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
Re: General purpose user code
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.
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.
Re: General purpose user code
Hi,
Try to instantiate repository as Private, instead of Public Shared
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 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
Re: General purpose user code
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.
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.
Re: General purpose user code
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 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