Forum Discussion

nidhi1's avatar
nidhi1
Occasional Contributor
15 years ago

Conditional moving to next record in the excel sheet in data loop

I want to create several orders on a website. Every order can have one or more products.



To implement this, I have created a data-driven loop in keyword test. I am passing order details in an excel sheet. Script works fine when there is single product for an order.

However, when I have to add multiple products for an order, I am not able to add it because the data loop is still on the original line..



Please find attached the sample excel sheet.



Could you please provide a solution to this?

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    What you might need to do is split your data into two different sheets.  The first sheet will be the information for each individual order, the second sheet will be the product data per order.   Then, you'll need to nest two different Data Loops so that you will loop through once for each order and then, within that loop, you'll loop once per product for the order.  Within the product loop, you'll need to do some sort of conditional check to see if the product record is supposed to be for the current order record.



    I'd be able to give better suggestions based upon your XLS but I'm unable to open the sheet.  


  • nidhi1's avatar
    nidhi1
    Occasional Contributor
    Thanks for the solution.



    I was thinking of using a csv file for providing product details for an order. So, I will make my csv file containing one row of values for every order. For eg.



    Ord1;Product1;Size1;Qty1;Product2;Size2;Qty2

    Ord2;Product1;Size1;Qty1;Product2;Size2;Qty2

    Ord3;Product1;Size1;Qty1;Product2;Size2;Qty2

    Ord4;Product1;Size1;Qty1;Product2;Size2;Qty2;Product3;Size3;Qty3;Product4;Size4

    Ord5;Product1;Size1;Qty1



    So, inside my order data loop, I will call add_product keyword test and inside it I want to read the line from csv variable that corresponds to the order number that is being created. Then, I want to split this line based on ";" as separator and probably use a WHILE or FOR Loop to add products for that order.



    Could you please provide me a way to do this in keyword test? How can I split the line from csv file? Can you provide me a javascript to do this splitting and then probably I can call this script routine inside my keyword test...



    Many Thanks for your help!



    -Nidhi
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    What I would suggest is using a different separator to separate "fields" in your CSV so that the first "field" is the order number and the second "field" is the product designators.  Something like the following:



    "Ord1","Product1|Size1|Qty1;Product2|Size2|Qty2"




    In the above example, the two fields are separated by a comma.  The second field is actually two records separated by a semi-colon.  Each record is then separated into it's individual components by the vertical pipes.



    Your DDT loop will then operate on the CSV file and return the two fields.  You'll then need to use the List Item methods of the aqString object to first parse out the two different records using the semi colon and then parse out the components of the records using the vertical pipe.



    Check out the article on aqString.GetListItem found here http://smartbear.com/support/viewarticle/13275/