Forum Discussion

HealthAutomate's avatar
HealthAutomate
Occasional Contributor
9 years ago
Solved

Passing each row values as test variables for various tests from one single Excel sheet

Hi All,

 

I am wondering if below scenario is achieveable. Please let me know if this is an option.

 

In an excel sheet say I have below values

1st row | Value1 | value 2| Value 3|

2nd row| Value4 | value 5| Value 6|

3rd row | Value7 | value 8| Value 9| 

 

I have below tests as

Test1

Test2

Test3

 

I want to pass 1st row values of excel sheet for only Test1 and 2nd row values for Test2 and so on.

How can I achieve this in KDT.

 

Thanks

 

  • dmiscannon's avatar
    dmiscannon
    9 years ago

    If you know the number of tests that will be run, you can accomplish what you want using a combination of a Data Driven Loop and If..Then statements with 1 If..Then statement for each called test. I was able to write a simple KWT doing that. (See below.) If you run a different number of tests at different times, then you can include an If..Then statement as the first statement after the DataDriver Loop that looks to see if the TestNumber in the Excel file is a specific value, say 9999. If it finds that value, the script exits the data loop. So the logic is as follows:

     

    Main Test

    - DDT Loop

      * If TestNumber = 9999 GoTo 'ExitLoop' Label

      * If TestNumber = 1 Run KWT Test1

      * If TestNumber = 2 Run KWT Test2

      * If TestNumber = 3 Run KWT Test3

      * etc.

    Label ExitLoop

    {end of test}

     

  • NisHera's avatar
    NisHera
    Valued Contributor

    write another test say MainTest

    Call DDT ExcelDriver loop in it

    in side loop call your tests by number 

     you can make a variable increase by one 

    • HealthAutomate's avatar
      HealthAutomate
      Occasional Contributor

      Thanks for your reply.

       

      I was unable to do the same in KDT but trying to write a script with similar logic as suggested.

      I am passing the variables at project level.

       

      Is there an example on how to structure this in KDT, if I am missing something on what was mentioned earlier ?

       

       

       

       

  • dmiscannon's avatar
    dmiscannon
    Frequent Contributor

    Are Test1, Test2, and Test3 iterations of the same automated test simply using different values for the same variables or are they separate and distinct automated tests?

     

    If Test1, Test2, and Test3 are the same automated test and you just want to pass different values to different scenarios, then do something similar to the following:

     

    Create a Data Driven Loop tied to your Excel sheet. Make sure the variable for the DDT is at either the Project or Project Suite level. Within the DDT, call your test (KWT or Script). In the called test, reference the different variables from the DDT that correspond to the columns of your Excel sheet. I did this using Log.Message as a simple example. My Excel workbook had four columns (TestNumber, Column1, Column2, Column3)

     

    Below is the MAIN test.

    This is the called test.

    Here is the result of running the test.

    Not sure if this is what you are looking for.

     

     

     

     

    • HealthAutomate's avatar
      HealthAutomate
      Occasional Contributor

      Thanks for your time and screenshots.

       

      The tests are distinct, I am trying to filter the test based on Testnumber for example and then pass corresponding row values as variables to that particular test.

       

       

      MainTest (Loops through Excel data for below Test )

      Test1 (Takes 3 variables )

      Test2 (Takes 3 variables )

      Test3 (Takes 3 variables )

       

       

      Main Test

      Loops Excel data

      {

      Test1 (I want to pass only Row1 value for this Test , should filter based on a column for example TestNumber and then passes rest of the variables)

      Test2 (I want to pass only Row2 value for this Test )  

      Test3....

      }

       

      Excel data:

      Row1 (Value1, Value 2, Value 3)

      Row2 (Value4, Value 5, Value 6)

       

      Hope that explains what I am trying to achieve without any confusion.

       

       

      • dmiscannon's avatar
        dmiscannon
        Frequent Contributor

        If you know the number of tests that will be run, you can accomplish what you want using a combination of a Data Driven Loop and If..Then statements with 1 If..Then statement for each called test. I was able to write a simple KWT doing that. (See below.) If you run a different number of tests at different times, then you can include an If..Then statement as the first statement after the DataDriver Loop that looks to see if the TestNumber in the Excel file is a specific value, say 9999. If it finds that value, the script exits the data loop. So the logic is as follows:

         

        Main Test

        - DDT Loop

          * If TestNumber = 9999 GoTo 'ExitLoop' Label

          * If TestNumber = 1 Run KWT Test1

          * If TestNumber = 2 Run KWT Test2

          * If TestNumber = 3 Run KWT Test3

          * etc.

        Label ExitLoop

        {end of test}