Page 1 of 1

How to take random names for in an registration application

Posted: Mon Oct 26, 2015 3:54 pm
by ejji09
Hi,

I am testing a java application where I have i do enter the patient details and register the patinet, but when ever i run the test case i have to give the names diffrenetly again and again.

Is there any possibility to overcome this, where ranorex takes random names from the database when ever we run the test case.

Re: How to take random names for in an registration application

Posted: Mon Oct 26, 2015 4:04 pm
by krstcs
The best thing to do would be to implement a random name generator of your own in a code module. You would link a module variable in the code to a global/test-case parameter.

This is the class I use:

Code: Select all

public static class RandomFactory {
        private static Random r = new Random();
        
        public static int getNextRandomNumber() {
        	return r.Next();
        }
        public static int getNextRandomNumber(int maxValue) {
        	return r.Next(maxValue);
        }
        public static int getNextRandomNumber(int minValue, int maxValue) {
        	return r.Next(minValue, maxValue);
        }
        
        public static string getRandomString(int minLength, int maxLength, bool isInitialCaps) {
        	Random r = new Random();
        	
        	int length = getNextRandomNumber(minLength, maxLength);
        	
        	char[] characters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        	
        	StringBuilder sb = new StringBuilder();
        	
        	for (int i = 0; i < length; i++) {
        		sb.Append(characters[r.Next(26)]);
        	}
        	
        	return isInitialCaps ? sb.ToString().Substring(0,1).ToUpper() + sb.ToString().Substring(1) : sb.ToString();
        }
}
Just call it like this:

Code: Select all

string firstName = RandomFactory.getRandomString(5, 10, true);
string lastName = RandomFactory.getRandomString(5, 10, true);

Re: How to take random names for in an registration application

Posted: Mon Oct 26, 2015 4:19 pm
by ejji09
Am using repsitory within code module. So here how can I use the random names.

my code:

Code: Select all

             public REGISTRATION()
        {
            // Do not delete - a parameterless constructor is required!
        }

        
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
            var firstname = repo.CentricityRISI50NotForPatientU.Firstname;
            firstname.Click();
            firstname.PressKeys("qwe");
            var surname = repo.CentricityRISI50NotForPatientU.Surname;
            surname.PressKeys("asd");

Re: How to take random names for in an registration application

Posted: Mon Oct 26, 2015 6:00 pm
by krstcs
I'm not sure I understand your second post. Was there another question about the information I gave you? If so, please phrase it so that your question is clear and specific, and include as much information as possible.

Re: How to take random names in an registration application

Posted: Mon Nov 02, 2015 2:35 pm
by ejji09
Hi,

In the below mentioned code i want to give random names at Fname and Surname

And i have no idea how to implement it!

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;

namespace RIS_i
{
    /// <summary>
    /// Description of REGISTRATION.
    /// </summary>
    [TestModule("0A9EF928-D246-47F7-BE71-A31A89065428", ModuleType.UserCode, 1)]
    public class REGISTRATION : ITestModule
    {
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public REGISTRATION()
        {
            // Do not delete - a parameterless constructor is required!
        }

        /// <summary>
        /// Performs the playback of actions in this module.
        /// </summary>
        /// <remarks>You should not call this method directly, instead pass the module
        /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
        /// that will in turn invoke this method.</remarks>
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
            
            var repo = RIS_iRepository.Instance;
            var newPatient = repo.CentricityRISI50NotForPatientU.NewPatient;
            newPatient.Click();
            var firstname = repo.CentricityRISI50NotForPatientU.Firstname;
            firstname.Click();
            firstname.PressKeys("Fname");
            var surname = repo.CentricityRISI50NotForPatientU.Surname;
            surname.Click();
            surname.PressKeys("Sname);
}
}
}
Thank you.

Re: How to take random names for in an registration application

Posted: Mon Nov 02, 2015 8:54 pm
by krstcs
Then just replace "Fname" and "Sname" with my random string generator.