Warning: fopen(/tmp/SghXTngBZPli-ZuJBql.tmp): failed to open stream: Disk quota exceeded in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 139
Warning: unlink(/tmp/SghXTngBZPli-ZuJBql.tmp): No such file or directory in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 142
In this post we will start our discussion with Data Driven testing with Selenium in C#, but this post can well understood only if you have already read the articles listed below
Here is the complete video of the above discussion
Thanks for watching the video and reading the post !!!
Please leave your comments and let me know if there is anything need to be improved in this post.
Thanks,
Karthik KK
Post Author:
Karthik kk
38 Replies to “Data Driven testing in Selenium with C#”
Please, the link you left for the full code of DDT is not working.
Kinldy help with a full DDT code with java.
Thank you
Hi Karthik,
Thank you for the The code you have provided in c# .
Issue w/ xlsx file open as Read-only when i try to update or save the file manually after test run
Thanks for the posting.
I am currently running multiple rows with different data.
I have a scenario and need some guidance, if one row errors out, the selenium script should take us to the next row.
Can you help how this is possible.
You can do via exception handling or store all the value in a collection and verify just the collection, that way you will have more handle over the data and assertion rather doing directly via UI.
I need help as I am new to selenium.If I have 100 test cases each test case testing different scenario with different inputs do we need to to use 100 excel sheets?if so isn’t hard to maintain them?Can you please explain how to handle this kind of scenario?
Thanks a lot for this videos, it really helped me so much !! Appreciate your effort.
I have a doubt in retrieving data from different sheets in an excel file, Could you help me in that scenario… I am not able to sort it out by myself. It will be very helpful if you share some videos on that too..
All you have to do is to change the hardcoded sheet to the one you need
//Get all the Tables
DataTableCollection table = result.Tables;
//Store it in DataTable
DataTable resultTable = table["Sheet1"]; //any sheet value e.g Sheet2 or Sheet3
Hello Karthik,
First and above all thanks for easy to use video tutorials.
I’m using the excel reader in my login methods and able to login by it. But when using the same login method in multiple tests and running all the tests at once it is giving errors.
For 1st test it reads data from excel.
For 2nd test onwards it fails to read data, when debugging i’m getting ReadTimeout errors on streams.
This is a very nice example of reading excel. Although there was one exception which anyone can easily solve. Thanks Kartik for posting this. I appreciate your help.
hi
i remove the “=” in the PopulateInCollection(string fileName) method
replace for (int col = 0; col <= table.Columns.Count; col++)
with for (int col = 0; col Test Name: ExecuteTest Test Outcome: Failed Result Message: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. —-> System.ArgumentNullException : text cannot be null Parameter name: text Result StandardOutput: opened url close the broswer
Hello Karthik
I have read the previous posts related to this question:
The code you have provided in c# .Net is not working. It is throwing System.IndexOutOfRange Exception. cannot find column 5
I have read your reply and I even copied and pasted your entire code. I have gone through it line by line more than 8 times. I am still having the same problem:
System.IndexOutOfRange Exception. cannot find column 5
Yes I have applied
colName = table.Columns[col].ColumnName,
colValue = table.Rows[row – 1][col].ToString()
But still facing the same problem
Please help
Thank you
If you can also email me a coupon code for your Udemy courses such as Automation FrameWork Development with Selenium(Advanced) – which by the way you have increased the price and also in comparison to other instructors in Udemy who offer the same course. it would be extremely nice of you. Right now I am unemployed otherwise I wouldnt ask you for any coupons to discount as I came to a conclusion that you talented when it comes to teaching.
Hey there! I could have sworn I’ve been to this website before but after checking through some of the post I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll be book-marking and be checking back frequently!
Wonderful blog! I found it while searching on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Thanks
Hi Karthik,
I’m getting below error for the same code as you shared. Can you please help me on this.
An exception of type ‘System.IO.FileLoadException’ occurred in Excel.dll but was not handled in user code
Additional information: Could not load file or assembly ‘ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Hello Karthik,
I got a scenario where I have to read my test data from .tsv file (tab separated file) in my specflow BDD test. Unfortunately, if I convert the .tsv to csv then my original test data is corrupting. Please can you advise how to achieve this by .tsv file? Your reply is much appreciated.
Thanks in adv,
PDR, UK.
Please, the link you left for the full code of DDT is not working.
Kinldy help with a full DDT code with java.
Thank you
Hi Karthik,
The code in c# .Net is not working. It is throwing IndexOutOfBound exception. Please help.
Thanks,
Subha
Hi Subha,
The indexoutofbound exception happens if the row or column is not available in the excel which you are trying to get.
Can you check whats going on there.
Thanks,
Karthik KK
Hi Karthik,
The code you have provided in c# .Net is not working. It is throwing System.IndexOutOfRange Exception. cannot find column 3.
Please help.
Thanks,
Subha
Hi subha anand,
Use code: Count -1
for (int row = 1; row <= table.Rows.Count – 1; row++)
Hi Ramon/Subha Anand,
We can also use
for (int row =1;row < table.Rows.Count ; row ++)
or
for(int row =1 ;row <=table.Rows.Count-1; row ++)
To avoid getting "System.IndexOutOfBound exception ".
But it will be good if Karthik can explain how same code is working for him and when we use its throwing exception.
Thanks
Ali
Hi Karthik,
Thank you for the The code you have provided in c# .
Issue w/ xlsx file open as Read-only when i try to update or save the file manually after test run
Thank you for your videos.
But can you show me how to check a login screen displayed on a web page or not so that I can login.
Hi Karthik,
Thanks for the posting.
I am currently running multiple rows with different data.
I have a scenario and need some guidance, if one row errors out, the selenium script should take us to the next row.
Can you help how this is possible.
Thanks
You can do via exception handling or store all the value in a collection and verify just the collection, that way you will have more handle over the data and assertion rather doing directly via UI.
Thanks,
Karthik KK
Hi Karthik,
I need help as I am new to selenium.If I have 100 test cases each test case testing different scenario with different inputs do we need to to use 100 excel sheets?if so isn’t hard to maintain them?Can you please explain how to handle this kind of scenario?
Yap, its hard to maintain, thats why try to use Specflow and put all the datas in feature file tables, which is much efficient and business driven !!!
Thanks,
Karthik KK
Hi Karthikk,
Thanks a lot for this videos, it really helped me so much !! Appreciate your effort.
I have a doubt in retrieving data from different sheets in an excel file, Could you help me in that scenario… I am not able to sort it out by myself. It will be very helpful if you share some videos on that too..
Hi Reshama,
In this post http://executeautomation.com/blog/ddt-excel-cuit-part-1/, we discussed code snippet to open excel sheet and return DataTable.
All you have to do is to change the hardcoded sheet to the one you need
//Get all the Tables
DataTableCollection table = result.Tables;
//Store it in DataTable
DataTable resultTable = table["Sheet1"]; //any sheet value e.g Sheet2 or Sheet3
Hope it helps !
Thanks,
Hi Karthik.
And how if I would like to have both “Sheet1” and “Sheet2” . Looks like in above procedure we only can store one excel sheet at a time?
Hi Karthik!
Just wanted to ask if there’s a way to write data in excel?
Please help if you have time thanks!
And Thank you for your tutorials… It helped me a lot in my automation testing =)
Hello Karthik,
First and above all thanks for easy to use video tutorials.
I’m using the excel reader in my login methods and able to login by it. But when using the same login method in multiple tests and running all the tests at once it is giving errors.
For 1st test it reads data from excel.
For 2nd test onwards it fails to read data, when debugging i’m getting ReadTimeout errors on streams.
May be can you please look into it.
Thanks,
Saadat
This is a very nice example of reading excel. Although there was one exception which anyone can easily solve. Thanks Kartik for posting this. I appreciate your help.
Hi Karthik,
The code you have provided in c# .Net is not working. It is throwing System.IndexOutOfRange Exception. cannot find column 5.
Please help.
Thanks,
daniel
Hi Daniel,
The indexoutofbound exception happens if the row or column is not available in the excel which you are trying to get.
Can you check whats going on there.
colName = table.Columns[col].ColumnName,
colValue = table.Rows[row - 1][col].ToString()
Thanks,
Karthik KK
hi
i remove the “=” in the PopulateInCollection(string fileName) method
replace for (int col = 0; col <= table.Columns.Count; col++)
with for (int col = 0; col Test Name: ExecuteTest Test Outcome: Failed Result Message: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. —-> System.ArgumentNullException : text cannot be null Parameter name: text Result StandardOutput: opened url close the broswer
hi Karthik KK
If I want to make 100 times the test that will call to id how I do it with data driven
Please help.
Thanks,
daniel
Hi karthik
I am getting error for IsFirstRowAsColumnNames.
I am using ‘ExcelDataReader.DataSet 3.3.0’
Is there any other refernce that i need to add
Please help
Thanks
Jubin
Hi Jubin,
Its already covered here https://www.youtube.com/watch?v=_h_4-HxrMMc&t=8s
Thanks,
Karthik KK
https://github.com/ObjectivityLtd/Test.Automation/wiki/NUnit-DataDriven-tests-from-Xml,-CSV-and-Excel-files solution in NUnit. Test data is passed to the test as parameters (key – name of parameter and key value). Test data can be read from excel, xml or csv files.
Hello Karthik
I have read the previous posts related to this question:
The code you have provided in c# .Net is not working. It is throwing System.IndexOutOfRange Exception. cannot find column 5
I have read your reply and I even copied and pasted your entire code. I have gone through it line by line more than 8 times. I am still having the same problem:
System.IndexOutOfRange Exception. cannot find column 5
Yes I have applied
colName = table.Columns[col].ColumnName,
colValue = table.Rows[row – 1][col].ToString()
But still facing the same problem
Please help
Thank you
If you can also email me a coupon code for your Udemy courses such as Automation FrameWork Development with Selenium(Advanced) – which by the way you have increased the price and also in comparison to other instructors in Udemy who offer the same course. it would be extremely nice of you. Right now I am unemployed otherwise I wouldnt ask you for any coupons to discount as I came to a conclusion that you talented when it comes to teaching.
Hey there! I could have sworn I’ve been to this website before but after checking through some of the post I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll be book-marking and be checking back frequently!
Wonderful blog! I found it while searching on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Thanks
Hi, I need to open Excel Sheet and filter some columns. Kindly Help me for this.
I have used below code but I got an error.
Excel.Application x1Appl = new Excel.Application();
Excel.Workbook x1WorkBook = x1Appl.Workbooks.Open(@”C:\Users\User1\Desktop\Test.xlsx”);
with “Microsoft.Office.Interop.Excel” Library.
error was: “System.Runtime.InteropServices.COMException: ‘Exception from HRESULT: 0x800A03EC'”
Thanks,
Hi Karthik,
I’m getting below error for the same code as you shared. Can you please help me on this.
An exception of type ‘System.IO.FileLoadException’ occurred in Excel.dll but was not handled in user code
Additional information: Could not load file or assembly ‘ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
have you solved it?
I Got the same error. Please share how you resolved this issue. thanks
Hi Karthik!
First of all thanks for easy to use video tutorials.
Just wanted to ask how to write data in excel?
Hello Karthik….thanks for your tutorials and sharing your knowledge with us.
Do you have any videos on how to write data to excel?
Hi Karthik,
thanks for sharing this videos it was very helpful.could you please also post writing data to excel using datatable in selenium c#.
Hello i am getting this error
System.IndexOutOfRangeException: Cannot find column 2.
Hello Karthik,
I got a scenario where I have to read my test data from .tsv file (tab separated file) in my specflow BDD test. Unfortunately, if I convert the .tsv to csv then my original test data is corrupting. Please can you advise how to achieve this by .tsv file? Your reply is much appreciated.
Thanks in adv,
PDR, UK.