Page 2 of 2

Re: Test data from .csv file

Posted: Mon Dec 12, 2011 9:21 am
by Support Team
Hi,

that's because in CSVConnector.cs the ";" is taken as separator and in your .CSV file you've chosen the "," as separator.
You have to either change the separator in your .CSV file or in the code file:

If you'd like to change the code, open CVSConnector.cs go to line 73 and alter it from
...
row = csvData[j].Split(';');
...

to
...
row = csvData[j].Split(',');
...


Do it in the same way at line 60.

Regards,
Tobias
Ranorex Support Team

Re: Test data from .csv file

Posted: Thu Dec 15, 2011 10:20 am
by Hermch
Does this way to access data in a datasource also work with excel files?

I tried it this way:

Code: Select all

ExcelConnector ExcelConn = New ExcelConnector(@"..\..\login.xlsx")
        	
        	system.Data.DataRow in ExcelConn.Rows
But I cant't access the data in login.xlsx. How can I get this data within my usercode?

Re: Test data from .csv file

Posted: Thu Dec 15, 2011 3:42 pm
by Support Team
Hi,

You can use this code to access the data from a excel file:
ExcelDataConnector connector = new ExcelDataConnector("ExcelConnector", @"C:\Users\mebner\Documents\Ranorex\RanorexStudio Projects\ExcelDataDrivenTesting\TestExcelFile.xlsx", "Tabelle1", "A:C", CheckState.Unchecked);

      Ranorex.Core.Data.ColumnCollection col;
      Ranorex.Core.Data.RowCollection row;
      connector.LoadData(out col, out row);
      
      foreach(Ranorex.Core.Data.Row dataRow in row){
        Report.Info(""+dataRow["FirstName"].ToString());
        Report.Info(""+dataRow["LastName"].ToString());
        Report.Info(""+dataRow["Age"].ToString());
      }
I have used the attached excel file.

Regards,
Markus
Ranorex Support Team

Re: Test data from .csv file

Posted: Thu Dec 15, 2011 4:09 pm
by omayer
now it reminds me to ask how to retrieve data from sql or oracle database and write it back to the database
Thanks You,
Omayer

Re: Test data from .csv file

Posted: Thu Dec 15, 2011 4:27 pm
by omayer
Here is the code i am using to process the data but its breaks when the data contains comma and () and "" ...question is how to parse data in .csv that contains ,""()..like "firstname, lastname -(company name)" ,

public void ParseTempJoborderTestData(string filePath)
{

CSVConnector csvConnector = new CSVConnector(filePath);

int i = 0; //countRow

foreach(System.Data.DataRow row in csvConnector.Rows) //reading all the rows

{
string TempJobOrderInputFile = row[0].ToString(); //reading the row from 2 to end

int countRow = i++; // loop count
tempJobOrderInfo[countRow] = TempJobOrderInputFile; //holding each row data into an array

string entireRow = tempJobOrderInfo[countRow];
string [] separate = entireRow.Split(','); //separate the field by comma
soldToCustID[countRow] = separate[0];
contactID[countRow] = separate[1];

Re: Test data from .csv file

Posted: Fri Dec 16, 2011 11:11 am
by Support Team
Hi!

I have created an example for you - use the following code in combination with a csv file with the contend i wrote within this post.

Please update to 3.2 to use this code.

Note, if you want to have " within your data, you have to escape this character by writing it 2 times. e.g. "test""test" for test"test.
The code:

Code: Select all

Ranorex.Core.Data.CsvDataConnector csvConnector = new Ranorex.Core.Data.CsvDataConnector("myconnector","c:\\test.csv",true);
csvConnector.SeparatorChar = ',';
Ranorex.Core.Data.ColumnCollection col;  
Ranorex.Core.Data.RowCollection row;  
csvConnector.LoadData(out col, out row);  
			
foreach(Ranorex.Core.Data.Row dataRow in row)
{ 
  Report.Info(""+dataRow["FirstName"].ToString());  
  Report.Info(""+dataRow["LastName"].ToString());  
  Report.Info(""+dataRow["Age"].ToString());  
}
The csv file:

Code: Select all

FirstName,LastName,Age
1,"""()..like ""firstname, lastname -(company name)", 3
Regards,
Martin
Ranorex Support Team