Site Loader
Auckland, New Zealand
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#”

  1. 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

  2. Hi Karthik,

    The code in c# .Net is not working. It is throwing IndexOutOfBound exception. Please help.
    Thanks,
    Subha

    1. 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.

      colName = table.Columns[col].ColumnName,
      colValue = table.Rows[row - 1][col].ToString()
      

      Thanks,
      Karthik KK

  3. 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

      1. 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

  4. 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

  5. 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.

  6. 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

    1. 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

  7. 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?

    1. 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

  8. 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..

    1. 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,

      1. 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?

  9. 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

  10. 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.

  11. 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

    1. 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

      1. 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

  12. 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

  13. 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

  14. 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.

  15. 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!

  16. 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

  17. 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,

  18. 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)

  19. Hi Karthik!

    First of all thanks for easy to use video tutorials.
    Just wanted to ask how to write data in excel?

    1. Hello Karthik….thanks for your tutorials and sharing your knowledge with us.
      Do you have any videos on how to write data to excel?

  20. 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#.

  21. 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.

Leave a Reply to Reshma Cancel reply

Your email address will not be published. Required fields are marked *