CSV File Reading/Writing

Ranorex Spy, Recorder, and Studio.
nandeesh
Posts: 14
Joined: Tue Jun 12, 2012 12:07 pm

CSV File Reading/Writing

Post by nandeesh » Mon Jun 25, 2012 9:13 am

Hi,

I Used the below code to read data from a csv file. Its working fine. but its displaying all the rows rows.count times. Even if i remove foreach statement same result i am getting.
1. How i can get each row values separately or a particular value for testing from a csv file..?
2. How to add new rows of data to an existing csv file (D:\\CSV\\csvFile.csv) for testing ..?

Help me out.
Thanks.

Code: Select all

CsvDataConnector csvConnector = new Ranorex.Core.Data.CsvDataConnector("CSVConnector","D:\\CSV\\csvFile.csv",true);
csvConnector.SeparatorChar = ',';
ColumnCollection outColCollection;  
			
RowCollection outRowCollection;
csvConnector.LoadData(out outColCollection, out outRowCollection);
foreach(Ranorex.Core.Data.Row dataRow in outRowCollection)
{ 
	Report.Info(""+dataRow["NUMBER"].ToString());
  	Report.Info(""+dataRow["Name"].ToString());  
}

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: CSV File Reading/Writing

Post by Support Team » Tue Jun 26, 2012 10:05 am

Hi,
nandeesh wrote:1. How i can get each row values separately or a particular value for testing from a csv file..?
Basically you can get the whole array of values of a specific row (defined in the foreach loop) using following code snippet:
...
string[] values = dataRow.Values;
...
nandeesh wrote:2. How to add new rows of data to an existing csv file (D:\\CSV\\csvFile.csv) for testing ..?
To write back data to your CSV file in code you can use following code snippet:
...
outRowCollection.Add(new string[2]{"10","Nandeesh"});
csvConnector.StoreData(outColCollection, outRowCollection);
...
Regards,
Tobias
Ranorex Tea,
.
Image

nandeesh
Posts: 14
Joined: Tue Jun 12, 2012 12:07 pm

Re: CSV File Reading/Writing

Post by nandeesh » Tue Jun 26, 2012 12:03 pm

Thanks Tobias.

Its working fine. Its adding.

Madan
Posts: 5
Joined: Mon Oct 15, 2012 3:20 pm

Re: CSV File Reading/Writing

Post by Madan » Wed Oct 31, 2012 8:56 am

Here is my test scenbario:
1.Login as User A
2.Go to Change Password
3.Change Password
4.Now, I want User A to make login with this password.

How can I implement this in Ranorex.pls reply asap.

Thanks,
Madan Singh

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: CSV File Reading/Writing

Post by Support Team » Wed Oct 31, 2012 4:54 pm

Hello,

The easiest way to do that is to record all actions with the 'Ranorex Recorder'.

Please take a look at the section Ranorex Recorder in our User Guide.

Regards,
Markus (T)
.
Image

Madan
Posts: 5
Joined: Mon Oct 15, 2012 3:20 pm

Re: CSV File Reading/Writing

Post by Madan » Thu Nov 01, 2012 4:18 am

Markus,

In my script, password get changed.In next run I want to make login with that password.
So how can i do that so that every time password get changed and am able to login with new password.

please tell me the whole code with example.

Also, how to write in data table in ranorex.

Thanks,
Madan Singh

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: CSV File Reading/Writing

Post by Support Team » Mon Nov 05, 2012 3:29 pm

Hello,

You could use 'Global Parameter' to set values within a test run.

Code: Select all

TestSuite.Current.Parameters["Password"] = "newPassword";
If you want to use these values in the next run you could use a CSV file.
The following example shows how to use this concept:

Code: Select all

string newPassword = "YourNewPassword";
string path = "C:\\Users\\user\\Documents\\test.csv";
string connector = "Params";

Ranorex.Core.Data.CsvDataConnector csvConnector = new Ranorex.Core.Data.CsvDataConnector(connector,path,true);
csvConnector.SeparatorChar = ',';
Ranorex.Core.Data.ColumnCollection inputCol = new Ranorex.Core.Data.ColumnCollection();
Ranorex.Core.Data.RowCollection outputRow = new Ranorex.Core.Data.RowCollection(inputCol);

outputRow.Add(new string[1]{"Password"});
outputRow.Add(new string[1]{newPassword});

csvConnector.StoreData(inputCol, outputRow);
Regards,
Markus (T)
.
Image

Madan
Posts: 5
Joined: Mon Oct 15, 2012 3:20 pm

Re: CSV File Reading/Writing

Post by Madan » Mon Dec 17, 2012 4:37 pm

Hi,

I want to click 'delete' button' for a particular element located on my application page.
Problem on this page is, a number of different 'delete' buttons exist for every element located on app page.
how to click on that particular delete button for that particular element.

Element link and delete button position can vary if some other element get created on that page.

Pls reply asap.

Thanks,
Madan Singh

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: CSV File Reading/Writing

Post by Support Team » Tue Dec 18, 2012 2:23 pm

Hi,

For the next time it would be great if you could create a new topic if you have a question concerning another problem. This would help others and would make the forum clearer.
In order to analyze your problem we would need a Ranorex snapshot file of your application when the different delete buttons are shown.
Following link will show you how to generate a snapshot file:
Creating Ranorex Snapshot Files.

Regards,
Markus
.
Image