Test data from .csv file

Class library usage, coding and language questions.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Test data from .csv file

Post by omayer » Thu Jul 14, 2011 7:15 am

is there code snippet for read through the entire .csv file and passing the data to test method in ranorex,
Thank you,
Beginner

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Test data from .csv file

Post by Support Team » Thu Jul 14, 2011 3:28 pm

Hi,

Do you know the Ranorex Studio "Manage Data Source" functionality?
You can easily load your (csv, excel, ...) files with all data into your project and you can easily access them.
For additional information see the link below: http://www.ranorex.com/support/user-gui ... sting.html
If you mean something else please explain it in a more detailed way.

Thanks in advance!

Regards,
Markus
Ranorex Support Team

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Sat Jul 16, 2011 2:08 am

how to load csv file w/out using "Manage Data Source" functionality, i like to creae a function that will read the .csv file from external source then passing data as function parameter.
Thank you
Beginner

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Test data from .csv file

Post by Support Team » Mon Jul 18, 2011 12:02 pm

Hi,

if you do not like to use our new data connectors with data binding, you can use attached CSVConnector.
Following code sample shows you how to use it:
...
try
{
	// Create a new CSVConnector object
	CSVConnector csvConnector = new CSVConnector(@"../../data.csv");

	// Read every row from connector and send to AddVIPApplication.
	foreach(System.Data.DataRow row in csvConnector.Rows)
	{
		String str1 = row[0].ToString();
		String str2  = row[1].ToString();
	}
}
catch (RanorexException e)
{
...
Regards,
Tobias
Support Team
You do not have the required permissions to view the files attached to this post.

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Mon Jul 18, 2011 3:10 pm

Thank you Markus, I really like the dataconnecters and binding feature in Ranorex, the problem i am having w/binding data w/parameter, I am working on it , will keep you posted the progress.
Thank you
Beginner

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Tue Jul 19, 2011 8:34 pm

how to view the data str1, I tried to use messagebox.show but no go

try
{
// Create a new CSVConnector object
CSVConnector csvConnector = new CSVConnector(@"../../data.csv");

// Read every row from connector and send to AddVIPApplication.
foreach(System.Data.DataRow row in csvConnector.Rows)
{
String str1 = row[0].ToString();
String str2 = row[1].ToString();
}
}
catch (RanorexException e)
{

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Test data from .csv file

Post by Support Team » Wed Jul 20, 2011 12:20 pm

Hi,

No idea why MessageBox.Show should not work, but instead you can use Console.WriteLine(), or log the data to the Ranorex Report file, or you set a breakpoint and use the debugging mode of Studio to read the data for str1.

Regards,
Peter
Ranorex Team

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Wed Jul 20, 2011 1:28 pm

Thank you Peter, I might need instruction or what to do w/attached file "CSVConnector.cs" on previous post .
Thanks
Beginner

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Test data from .csv file

Post by Support Team » Wed Jul 20, 2011 1:50 pm

Hi,

Attached you will find the old Data Drive Sample. In this sample the VIP Application uses the CSV Connector.
Data Driven Test.zip
Regards,
Peter
Ranorex Team
You do not have the required permissions to view the files attached to this post.

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Wed Jul 20, 2011 2:00 pm

Thank you Peter
Beginner

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Wed Jul 20, 2011 4:15 pm

i amg getting the error " Index was outside the bounds of the array. "

Code: Select all

void ITestModule.Run()    

        	
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
                                    // Create a new CSVConnector object

CSVConnector csvConnector = new CSVConnector(@"C:\Automation_Ranorex\TestData.csv");
	         // Read every row from connector and send to AddVIPApplication.
            	foreach(DataRow row in csvConnector.Rows)
		{          		
			
            		LoginTo.userId = row["userID"].ToString();
            		LoginTo.passWord = row["passWord"].ToString();
            		MessageBox.Show(LoginTo.userId);
            		                           
           		}  


Thanks
Beginner

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Thu Jul 21, 2011 4:20 am

Thank you all, csvconnector working as expected.
Beginner

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Thu Dec 08, 2011 4:33 pm

How to parse data in csv File that contains this format "lastname, firstname (company name)". Thank you in advance...beginner
Tipu

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Test data from .csv file

Post by Support Team » Fri Dec 09, 2011 12:38 pm

Hi,
How to parse data in csv File that contains this format "lastname, firstname (company name)".
Like you have done it, you just have to replace "userID" with "lastname", "passWord" with "firstname" and so on.

Regards,
Markus
Ranorex Support Team

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Test data from .csv file

Post by omayer » Sun Dec 11, 2011 6:58 pm

I do have data in csv file that looks like this " omayer,baba-(testing field)" . Now when that field gets parsed its value display as "omayer. Not the entire data, so how will i get the data that read as " omayer,baba-(testing field)"
Thank you
Beginner
Tipu