How to add user functions

Ranorex Studio, Spy, Recorder, and Driver.
ohm
Posts: 27
Joined: Thu Dec 03, 2009 7:27 pm

How to add user functions

Post by ohm » Fri Dec 11, 2009 4:18 pm

I am new to this tool.

I am doing a browser testing. I recorded recording1.rxrec. I recored it to go to http://www.cnn.com and then it verifys if it really goes to cnn.com. In 'Key Sequence' I have http://www.cnn.com.

Then I have some gibberish string in Key Sequence (i.e. EIERUIEIFJIEIRE #*$&^#) and it verifys if browser is saying no address found.

Now instead of using one Key Sequence, I would like to use a randomURLgenerator and randomSTRINGgenerator. I have found the following two functions but when I add them in Recording1.cs and close the program, I lose everything.

This code is for randomURLgenerator (uses one of the 10 URLs):

Code: Select all

 
public static string RandomString_URL_Array () //Generate random value from the array validURL
        {
        // Create array with valid URL links
        string [] validURL = {"www.google.com", "www.yahoo.com", "www.ebay.com", "www.wikipedia.org", "www.att.com", "www.dice.com", "seleniumhq.org", "www.microsoft.com", "www.hulu.com", "www.java.com", "www.facebook.com"};
               
        Random RandString = new Random();
        string result = validURL[RandString.Next(0, validURL.Length)]; 
        return result;
        }


This is the code for randomSTRINGgenerator:

Code: Select all

 
public static string randomString (int numChars )
        {
        string[] chars = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "S",
                        "T", "U", "V", "W", "X", "Y", "Z","0","1", "2", "3", "4", "5", "6", "7", "8", "9" };

        Random rnd = new Random();
        string random = string.Empty;
        for (int i = 0; i < numChars; i++)
        {
            random += chars[rnd.Next(0, chars.Length)];
        }
        return random;
How can I add these functions to my scrips and call them from Recording.rxrec? BTW, I am not an experienced programmer.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to add user functions

Post by Support Team » Fri Dec 11, 2009 5:28 pm

Please, read the following section in the Ranorex User Guide covering how to create User Code Actions:
http://www.ranorex.com/support/user-gui ... tions.html

For new Ranorex users I recommend reading the Ranorex Tutorial (http://www.ranorex.com/Documentation/Ra ... torial.pdf). Some more advanced topics are also available as screencasts: http://www.ranorex.com/support/screencasts.html

Basically, most of the questions should already be answered by the Ranorex User Guide (http://www.ranorex.com/support/user-guide-20.html) or in these forums.

Regards,
Alex
Ranorex Support Team

ohm
Posts: 27
Joined: Thu Dec 03, 2009 7:27 pm

Re: How to add user functions

Post by ohm » Fri Dec 11, 2009 10:26 pm

Thanks Alex.
Found my answer.