Increment Value from Data Table used in test case

6 posts, 0 answers
  1. Sean
    Sean avatar
    9 posts
    Member since:
    Aug 2012

    Posted 21 Aug 2012 Link to this post

    Sorry new to all this automation so forgive my noobness.

    I have bound a csv file to my test plan which contains first names, last names, phone numbers and email addresses.  There is approximately 300000 records in the csv.  I have since created a data driven test case which requires a first name be entered into a text field.  Our system does existence checks on names numbers and email so I would like to increment the data used each time I run the test so I do not repeat names numbers and email. 

    Example:

    Test 1 pulls first name from row 2 (row one is header)
    Test 2 pulls first name from row 3
    and so forth

    Is there a way to do this. I would also be interested in just generating dummy data on the fly that gets entered in the fields. 
  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 24 Aug 2012 Link to this post

    Hello Sean,

    See our article on Non-Iterative Data Driven Testing.

    That sample is written for XLS, but its concept can easily be adapted for CSV.

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Carl
    Carl avatar
    11 posts
    Member since:
    Apr 2012

    Posted 25 Sep 2012 Link to this post

    I found the Non-Iterative Data Driven Testing to be a little cumbersome so I came up with a slightly different solution, instead of using code to retrieve the data, I instead used a normal data driven test then used a public override to remove the second row from the spread sheet at the end of the test.
    It works something like this; we use generatedata.com to generate hundreds of records and store them in a spread sheet, then we set the test to use only the first row of data (this is acutely the second row in excel) then when the test finishes the override removes the second row (from excels point of view) and shifts the remaining rows up to fill the gap so the next time it runs row 1 (from test studio point of view) is now the old row 2. This approach even works when you want to run multiple iterations!


    public override void OnAfterTestCompleted(TestResult result)
       {
               string dstFile = System.IO.Path.Combine(this.ExecutionContext.DeploymentDirectory, "Data\\driver.xlsx" as string);
               Microsoft.Office.Interop.Excel.Application myApp;
               Microsoft.Office.Interop.Excel.Workbook myWorkBook;
               Microsoft.Office.Interop.Excel.Worksheet myWorkSheet;
               Microsoft.Office.Interop.Excel.Range range;
               myApp = new Microsoft.Office.Interop.Excel.Application();
               myWorkBook = myApp.Workbooks.Open(dstFile, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false   , 0, true, 1, 0);
               myWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)myWorkBook.Worksheets.get_Item(2);
               ((Microsoft.Office.Interop.Excel.Worksheet)myApp.ActiveWorkbook.Sheets[1]).Select(Type.Missing);
               range = (Microsoft.Office.Interop.Excel.Range)myWorkSheet.Application.Rows[2, Type.Missing];
               range.Select();
               range.Delete(Microsoft.Office.Interop.Excel.XlDirection.xlUp);
               myApp.ActiveWorkbook.Save();
               myWorkBook.Close(true);
       }

  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 28 Sep 2012 Link to this post

    Hi Carl,

    Excellent! Thank you for sharing your solution and assisting another customer. I've updated your Telerik points accordingly.

    Regards,
    Plamen
    the Telerik team
    Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
    Vote now
  5. Tanu
    Tanu avatar
    2 posts
    Member since:
    Jan 2013

    Posted 19 Feb 2013 Link to this post

    When I used the code given above getting the followng error

    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 75: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 76: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 77: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 78: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 79: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 80: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 81: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 82: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 83: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\Tanu\Documents\Test Studio Projects\RadListBoxTesting\Add New Client.tstest.cs: Line 85: (CS0234) The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

  6. Carl
    Carl avatar
    11 posts
    Member since:
    Apr 2012

    Posted 19 Feb 2013 Link to this post

    Hi Tanu
           I probabley should have spelled this out in my origonal post, to use my solution you will still need to install the Microsoft.Office.Interop.Excel.dll (can be downloaded from here and by default will be installed to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\) then you need to add this dll to your test studio project and include an import statement in your coded step. After that you should no longer see this error.
Back to Top