Use Incrementing variables that increment with each run

Ask general questions here.
lucas.crandle
Posts: 4
Joined: Tue Jun 09, 2015 2:04 pm

Use Incrementing variables that increment with each run

Post by lucas.crandle » Tue Jun 09, 2015 2:10 pm

Hello,

One of the tests I need to run adds a row to a database, and the identifier needs to be unique. Since I will be running this test many times I would like Ranorex to automatically increment a variable for me so that each run will enter a unique variable.

Could someone give me some insight as to the best way to implement this?

Thanks for the help!

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Use Incrementing variables that increment with each run

Post by krstcs » Tue Jun 09, 2015 4:34 pm

What database are you using?
What version of Ranorex?

You should not use external software to create unique database IDs. Almost every relational database currently in use has the ability to create unique ids for each row and you should use that mechanism. If you try to do it through Ranorex you will likely end up causing data integrity issues in the database.

You should change your DB table so that it automatically creates the IDs for you.
Shortcuts usually aren't...

lucas.crandle
Posts: 4
Joined: Tue Jun 09, 2015 2:04 pm

Re: Use Incrementing variables that increment with each run

Post by lucas.crandle » Tue Jun 09, 2015 4:39 pm

Hello,

We are testing entry into EBS application forms that are insert/update only. (I apologize I didn't phrase the original question very well)
So I'm not creating the actual row ID, but the form requires the name to be unique.
Also, this is in our test environment that is copied from a production instance frequently.

Thanks!

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Use Incrementing variables that increment with each run

Post by krstcs » Tue Jun 09, 2015 5:18 pm

Well, in that case you could just use Random.Next() to get a number to use to get each character. Give it a length as well so it creates names that are different lengths.

Code: Select all

Random r = new Random();
int minLength = 3;
int maxLength = 10;

StringBuilder name = new StringBuilder(char.ToString((char)r.Next(65, 90)));

for (int i = 0; i < r.Next(minLength - 1, maxLength - 1); i++) {
	name.Append(char.ToString((char)r.Next(97, 122)));
}

Report.Info("NAME", name.ToString());
Shortcuts usually aren't...

lucas.crandle
Posts: 4
Joined: Tue Jun 09, 2015 2:04 pm

Re: Use Incrementing variables that increment with each run

Post by lucas.crandle » Tue Jun 09, 2015 5:23 pm

I came up with a similar solution, I create a string from the system.date class that has the day of year and then a timestamp.
However, I was wondering if there was a UI way to do this that someone who is less comfortable writing code could use. Something like using a simple data table in the data sources.

Do you know of anything similar that doesn't involve code?

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Use Incrementing variables that increment with each run

Post by krstcs » Tue Jun 09, 2015 5:48 pm

Not if it needs to be random or unique between runs. You will need to code. Ranorex (unfortunately) doesn't have a way to do it without using user-code.
Shortcuts usually aren't...

lucas.crandle
Posts: 4
Joined: Tue Jun 09, 2015 2:04 pm

Re: Use Incrementing variables that increment with each run

Post by lucas.crandle » Tue Jun 09, 2015 5:50 pm

Ok, Thanks for the help krstcs!