How to create Simple Data Connector via user code

Ask general questions here.
msz
Posts: 4
Joined: Mon May 04, 2020 1:35 pm

How to create Simple Data Connector via user code

Post by msz » Wed Jun 03, 2020 3:01 pm

Hello,

is it possible to create a simple data connector (or table) with columns via user code?
I attached a screenshot how it could possibly looks like.

Kind regards,
msz
You do not have the required permissions to view the files attached to this post.

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

Re: How to create Simple Data Connector via user code

Post by odklizec » Wed Jun 03, 2020 6:06 pm

Hi,

As far as I know, there is no public API for creating and manipulating Simple data connectors. And if I may suggest you something, you should really drop the idea of using these connectors in your projecta. True, they are very easy to create. But they are a nightmare to maintain! Simple data connectors are stored directly in rxtst file, which makes them vary hard to compare and quickly increases the size of rxtst file. Check for example this post...
https://www.ranorex.com/forum/viewtopic ... 70&p=55871

If you want to create data connectors on the fly, use CSV data connector instead.
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

msz
Posts: 4
Joined: Mon May 04, 2020 1:35 pm

Re: How to create Simple Data Connector via user code

Post by msz » Thu Jun 04, 2020 12:27 pm

Thank you for your response.
At the moment my program (user code) load the testdata (without columns) from a csv-file dynamicly at the runtime into the simple data table wiches contains only columns like in the screenshot I have previously shared here. The simple data table with columns is for the binding of the variables in my ranorex project. Thats because I must have a blank data source table with only columns.
So maybe there is another possibility to do this with csv-data connectors instead of simple data connectors via user code or any other suggestions? I would be very grateful.

Kind regards,
msz

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

Re: How to create Simple Data Connector via user code

Post by odklizec » Thu Jun 04, 2020 1:37 pm

Hi,

Here is a sample code, which I'm using for dynamic generation of CSV data connector file. Basically, I have an empty data connector attached to smartfolder and below code is performed before accessing it. Hope this helps a bit?

Code: Select all

	string csvOutputPath = dataDirectory + "\\DataConnectors\\" + dataConnectorFile;
	string[] strArray = resourceKeyArray.Split(',',',');

	Report.Log(ReportLevel.Debug, "strArray: " + strArray);
	//create CSV data connector
	string connector = "CSVConnector";
	Ranorex.Core.Data.CsvDataConnector csvConnector = new Ranorex.Core.Data.CsvDataConnector(connector,csvOutputPath,true);
	csvConnector.SeparatorChar = ',';
	Ranorex.Core.Data.ColumnCollection propTableColumnsCSV = new Ranorex.Core.Data.ColumnCollection();
	Ranorex.Core.Data.RowCollection propTableRowsCSV = new Ranorex.Core.Data.RowCollection(propTableColumnsCSV);

	//create CSV column headers
	propTableRowsCSV.Add(new string[1]{"resourceKey"});

	int strArray_Length = strArray.Length;
	for (int i = 0; i < strArray_Length; i++)
	{
		if (!string.IsNullOrEmpty(strArray[i]))
		{
			propTableRowsCSV.Add(new string[1]{strArray[i]});
		}
	}
	// save CSV connector to file
	csvConnector.StoreData(propTableColumnsCSV, propTableRowsCSV);

	//reload data source
	var tc = (TestCaseNode) TestSuite.Current.GetTestContainer(testCaseName);
	var source = DataSources.Get(dataConnectorName);
	tc.DataContext.Source=source;
	tc.DataContext.Source.Load();
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

msz
Posts: 4
Joined: Mon May 04, 2020 1:35 pm

Re: How to create Simple Data Connector via user code

Post by msz » Thu Jun 04, 2020 3:07 pm

Hi,

thank you for youre response. I'm very appriciate it.
I wrote a similar code for the dynmaic load of my data rows. You wrote that you have already an empty data connector. But in my case I would like to create this data connector via user code and add new columns.

Is there a posibility to do that?
Something like this:

Code: Select all

DataSources.Create(dataConnectorName);

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: How to create Simple Data Connector via user code

Post by RobinHood42 » Mon Jun 08, 2020 7:55 am

Hi,

did you check the API documentation? There is no Create method defined in the DataSources class. Pavel's code is a good solution for your problem.
If you want to have more convenience, you can request this feature on the user voice.
https://www.ranorex.com/uservoice/

Cheers,
Robin