Repeat a group of recordings for a dynamic number of times

Best practices, code snippets for common functionality, examples, and guidelines.
HansSchl
Posts: 93
Joined: Wed Sep 19, 2018 10:05 am

Repeat a group of recordings for a dynamic number of times

Post by HansSchl » Mon Mar 29, 2021 7:11 pm

Hi,

I saw a number of related questions in this forum but none seems to cover my scenario.

The AUT acesses a database, and I want the test to run some checks on all database entries which the AUT finds. I do not know the number beforehand, but I do know it is "reasonable", say between 4 and 50. The test is supposed to pass when the AUT does the correct thing, irrespective of the number of database entries it finds.

For a start, I placed the checks into a smart folder and created a data source with 6 rows in this folder. The AUT now inspects the first six database entries. But this will fail if the number of entries is smaller than 6, and it will be incomplete if new entries are added.

I tried using a CSV database and fill it with rows at runtime. The CSV file is updated, but the new content comes into effect only during the next test execution. It seems that the database is loaded at test startup, and then is disconnected from the file.

Any ideas?

Thanks
Hans

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

Re: Repeat a group of recordings for a dynamic number of times

Post by odklizec » Wed Apr 07, 2021 8:54 am

Hi Hans,

By the "database" you mean a normal SQL DB, which is used as a data connector?

Generally speaking, it may be possible to do what you want. Here is a sample code, which I'm using to generate data connector from CSV file with variable number or rows...
how-to-create-simple-data-connector-via ... tml#p60542
But I'm not quite sure if it's what you are looking for? Please describe your scenario with real scenario, ideally, with sample solution and some pics ;) Thanks.
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

HansSchl
Posts: 93
Joined: Wed Sep 19, 2018 10:05 am

Re: Repeat a group of recordings for a dynamic number of times

Post by HansSchl » Wed Apr 07, 2021 10:31 am

Hi odklizec, good to see you again. I had feared the forum might have been closed :-)

The database is not accessible to the test, it is only accessed through the AUT, and its content are displayed in a grid in the GUI of the AUT.

My test case loops through the data in this grid and does the same action for each entry: Open a dialog with entry's properties, extract data of a field, and append this data to a parameter of the test case for later use. Appending the string is a user action, but the rest are simple predefined actions like mouse clicks or GetData.

I created a smart folder which contains those actions, and added a simple data source with 6 lines so that this "loop" is executed 6 times, assuming the grid displays 6 entries (which, currently, is true). But I'd like this test to be flexible enough to process 7 or 8 entries if there are that many, like a loop 'for i=1 to n' (where n, the number of entries, is accessible in the AUT's GUI). As it is now, I must modify this simple data source when the number of entries changes.

I will try out the solution from your link, and report back. Creating the mentioned simple data source dynamically sounds like a good solution, provided the data source is only evaluated immediately before it is used.

Hans

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

Re: Repeat a group of recordings for a dynamic number of times

Post by odklizec » Wed Apr 07, 2021 10:48 am

Hi Hans,

Now I understand. I think the solution from the link should help. You may don't even need to use data connector with empty rows, but instead to set Iteration Count property for given SmartFolder. Of course, you must do this "before" the SmartFolder you want to repeat is accessed. I think it was discussed before?

PS: it seems the discussion was only about getting the iteration count, but not about setting it. And I don't see anything in API that could eventually set the iteration count? So maybe it's not public?
viewtopic.php?f=16&t=10027&p=50579#p47904
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

HansSchl
Posts: 93
Joined: Wed Sep 19, 2018 10:05 am

Re: Repeat a group of recordings for a dynamic number of times

Post by HansSchl » Thu Apr 08, 2021 8:56 am

Unfortunately I didn't manage to make it work. I am attaching a screenshot of the test project. Recording1 calls functions CreateDataSource and SetIterationCount. Recording2 and Recording3 perform a primitive action so that I can see how many times it is repeated.
The CreateDataSource function attempts to modify the data source of "SmartFolder". But however hard I try, the data used by the test project is always what I code into the data source, not what the code tries to put in it.
With the SetIterationCount function I was even less successful as I couldn't identify a function or property with which I could manipulate the count. Many posts in this forum ask about how to read the current index, but this is obviously not what I need.
This is the code of CreateDataSource. I know it has some redundancies and is lacking error checking. I'm trying to replace the content of the existing simple data source of "SmartFolder" (one column, one row) by five rows which contain the numbers 1 through 5.

Code: Select all

public void CreateDataSource()
{
	var tc = (SmartFolderNode)TestSuite.Current.GetTestContainer("SmartFolder");
	var ds = tc.DataContext.Source;
	var rows = ds.Rows;
	rows.Clear();
	for (int i = 1; i <= 5; i++)
	{
		string[] values = new string[1]{string.Format("{0}", i)};
		Ranorex.Core.Data.Row row = new Ranorex.Core.Data.Row(values);
		rows.Add(row);
	}
	
	tc.DataContext.ClearData();
	tc.DataContext.Source = ds;
	tc.DataContext.ReloadData();
	ds.Load();
	
	return;
}
Attachments
2021-04-08_09h48_05.png
2021-04-08_09h48_05.png (9.01 KiB) Viewed 78 times

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

Re: Repeat a group of recordings for a dynamic number of times

Post by odklizec » Thu Apr 08, 2021 9:08 am

Hi,

I believe you are trying to modify a simple data connector, right? Unfortunately, I've never tried that. My code is optimized for CSV data connector. So I'm not quite sure, if the mechanism of replacing/reloading data connector content is the same? Try the CSV connector and the code I provided.
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

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

Re: Repeat a group of recordings for a dynamic number of times

Post by odklizec » Thu Apr 08, 2021 9:50 am

OK, this code works with Simple Data connector...

Code: Select all

public void CreateDataSource()
{
	var tc = (SmartFolderNode)TestSuite.Current.GetTestContainer("SmartFolder");
	var ds = tc.DataContext.Source;
	var cols = ds.Columns;
	var rows = ds.Rows;

	rows.Clear();
	for (int i = 1; i <= 5; i++)
	{
		string[] values = new string[1]{string.Format("{0}", i)};
		Ranorex.Core.Data.Row row = new Ranorex.Core.Data.Row(values);
		rows.Add(row);
	}
	ds.Store();

	tc.DataContext.ClearData();
	tc.DataContext.Source = ds;
	tc.DataContext.ReloadData();
	ds.Load();
	
	return;
}
It seems you forgot ds.Store(); line in your code? Hope this helps? ;)
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

HansSchl
Posts: 93
Joined: Wed Sep 19, 2018 10:05 am

Re: Repeat a group of recordings for a dynamic number of times

Post by HansSchl » Thu Apr 08, 2021 11:50 am

Wow, that's it! :D Thanks a lot.

Hans

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

Re: Repeat a group of recordings for a dynamic number of times

Post by odklizec » Thu Apr 08, 2021 12:06 pm

You are welcome! ;)
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

HansSchl
Posts: 93
Joined: Wed Sep 19, 2018 10:05 am

Re: Repeat a group of recordings for a dynamic number of times

Post by HansSchl » Fri Apr 09, 2021 1:47 pm

I played with the code some more and found that I could remove the lines

Code: Select all

tc.DataContext.ClearData();
tc.DataContext.Source = ds;
tc.DataContext.ReloadData();
ds.Load();
without losing functionality. However, I am wondering how this line selects the correct container when there is more than one named "SmartFolder" (which seems to be no problem for Ranorex Studio).

Code: Select all

var tc = TestSuite.Current.GetTestContainer("SmartFolder");
I will do my best to avoid this situation...

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

Re: Repeat a group of recordings for a dynamic number of times

Post by odklizec » Fri Apr 09, 2021 1:54 pm

Hi,

Well, I think you will have to specify correct one. Eventually, it may be possible to use GUID string, instead of simple name? In case of multiple TestContainers called 'SmartFolder', it may pick the first one found? ;)
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

HansSchl
Posts: 93
Joined: Wed Sep 19, 2018 10:05 am

Re: Repeat a group of recordings for a dynamic number of times

Post by HansSchl » Fri Apr 09, 2021 3:07 pm

A funny side note. It is possible to add lines to the data source of the executing container and thus create an infinite loop 8)