How to generalise User Code

Ask general questions here.
bygones
Posts: 31
Joined: Fri Nov 27, 2015 11:32 am

How to generalise User Code

Post by bygones » Mon Dec 05, 2016 11:40 am

Hi,

I have a recording module, where I added a step as "User Code". So this code is now part of the recording module and cannot be used in another recording module, right ?

Now another recording module requires this with a different repo item to work on.

My user code looks currently like this
public void Validate_ChatTextValue(string argument1)
{
    Report.Log(ReportLevel.Info, "Validation", "Validating", 
                         repo.project.ChatTextValueInfo);
    var cValue = repo.project.ChatTextValue.InnerText.Trim();
    for (int i = 0; i < 25; i++) {
        if (String.Equals(cValue, argument1))  {
            	return;
        }
        Delay.Milliseconds(1000);
        cValue = repo.project.ChatTextValue.InnerText.Trim();
     }
     Report.Log(ReportLevel.Failure, "Validation", "Chat element is wrong", 
                 repo.project.ChatTextValueInfo);
}
to check whether an element has a certain innerText.

Now I like to generalise this, in the way that

a) other recording modules can use this
b) the method takes also the repo item as argument

Can someone help me how to do this ?

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

Re: How to generalise User Code

Post by odklizec » Mon Dec 05, 2016 2:30 pm

Hi,

You can find answer on your question here (in section "Spread your Custom Action by Inheriting from a Base Class"):
http://www.ranorex.com/blog/custom-smart-actions/
Hope this helps? ;)

And as correctly suggested in another thread, there is now a built-in option in Ranorex 6.2, which allows to create a centralized place with custom user code methods. Please follow the steps in user guide - User Code Library chapter:
http://www.ranorex.com/support/user-gui ... brary.html
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