Test data from .csv file : Automation API - Page 2

Test data from .csv file

Class library usage, coding and language questions.

Re: Test data from .csv file

Postby Support Team » Mon Dec 12, 2011 10:21 am

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[i] = csvData[j].Split(';')[i];
...

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


Do it in the same way at line 60.

Regards,
Tobias
Ranorex Support Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Test data from .csv file

Postby Hermch » Thu Dec 15, 2011 11:20 am

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?
Hermch
 
Posts: 26
Joined: Thu May 26, 2011 8:17 am
Location: Germany

Re: Test data from .csv file

Postby Support Team » Thu Dec 15, 2011 4:42 pm

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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Test data from .csv file

Postby omayer » Thu Dec 15, 2011 5:09 pm

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
Tipu
omayer
 
Posts: 240
Joined: Thu Oct 28, 2010 7:14 pm

Re: Test data from .csv file

Postby omayer » Thu Dec 15, 2011 5:27 pm

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];
Tipu
omayer
 
Posts: 240
Joined: Thu Oct 28, 2010 7:14 pm

Re: Test data from .csv file

Postby Support Team » Fri Dec 16, 2011 12:11 pm

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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Previous

Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests