Forum Discussion

keithowens's avatar
keithowens
New Contributor
11 years ago

excel parent child data driven testing

Hi

Apologies if this is a newbie question but I am new at this.

I have built some data driven tests using excel as input & output and have managed to make some great forward strides and am really excited at the possibilities ahead.

 

I cannot grasp how to deal with a one to many relationship in the xml.

I have to test an api along the lines of the following;

PurchaserDetails

    Name

    Address

    Phone

    Email

    Item Ordered

        ItemId

        Name

        Quantity

        Cost

 

The details are captured on line and tehre can be any number of items ordered for one purchaser.

 

How can I do this with data driven from Excel? Can I do it with two data sources and build a relationship?

 

Thanks

Keith

 

 

 

 

4 Replies

  • Lage's avatar
    Lage
    Contributor

    Hi, maybe this is not the best way because i never did something similar but... I would do something like that:

     

    excel_example_some_products.png

     

    excel_example_some_products2.png

     

    In the script, for each Item in ItemOrdered you can go to the second Excel and retrieve the rest of the values...

     

    hope it helps

  • 'this is a slower option,but if you dont have too much data to scan through

    'this also assume that the order number in the parent exists as a column in the child excel sheet, otherwise i m not sure how to 'identify what 'order' belongs to what parent

     

     

    set parentDriver = DDT.ExcelDriver ("FullPathParentFileName","sheet",T/FAce)
    set childDriver = DDT.Exceldriver("FullPathChildFileName","sheet",T/FAce)
    
    parentDriver.First
    while not parentDriver.EOF
          ..'your code here
           orderItemNumer=parentDriver.Value("OrderNumberColumn")
           childDriver.First 
           while not chidldriver.EOF
                  if orderItemNumber = childDriver.Value("OrderNumberColumn") then
                          ...'your code here
                  end if 
                   childDriver.Next
            wend
           parentDriver.Next
    wend

    The second would be to create an adodb object and query the excel file.

     

    I dont recall the whole process so you might have to do some homework also the above is in vbscript.

     

    the second would to deal with  : http://www.w3schools.com/asp/ado_ref_connection.asp

    .. open a connection to the excel file : https://www.connectionstrings.com/excel/

     

    here's an code script from microsoft (again this is vbscript)

     

     

    On Error Resume Next
    
    Const adOpenStatic = 3
    Const adLockOptimistic = 3
    Const adCmdText = &H0001
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordSet = CreateObject("ADODB.Recordset")
    
    objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\Scripts\Test.xls;" & _
            "Extended Properties=""Excel 8.0;HDR=Yes;"";" 
    
    objRecordset.Open "Select * FROM [Sheet1$]", _
        objConnection, adOpenStatic, adLockOptimistic, adCmdText
    
    Do Until objRecordset.EOF
        Wscript.Echo objRecordset.Fields.Item("Name"), _
            objRecordset.Fields.Item("Number")
        objRecordset.MoveNext
    Loop

     

    the site:https://technet.microsoft.com/en-us/library/ee692882.aspx

     

    Hope this helps

          

     

    EDIT:

    forgot to mention,

     

    if you are using a keyword test:

     

    could you not create data driven loop and loop inside that loop?

     

      DDL ->parent file

           Set Variable Value ->assign the id to a variable

           DDL-> child file

                 if.. then    ->variables.variablename Equals Variable.def("d") <--this last one is the DDL from the child above.

                      ..your code?

     

     

    test.jpg

    something like above?

     

    • keithowens's avatar
      keithowens
      New Contributor

      Thanks for the suggestions. I am trying to integrate teh final one with the nested datasource into my work however my screen is looking much different to yours. I have the xml mapped to the data source but cannot see where I would place the nested one.

       

      My screen looks like this image.

       

      Am I way off target with my thinking?

       

       

      • finae's avatar
        finae
        Contributor

        I think we're using different version of the application.

        I m using TestComplete 9,  and the GUI image of teh DDL is different than yours. 

        I do not see a Data Source Loop operation in my list of default operation, so my answer to your question might be mute.

         

        The Data source i have available are: Excel, CSV, DataTable, Database Query, and Database Table.

        I dont see XML as the source, though i think it would be possible.