Forum Discussion

veronica_glynn's avatar
veronica_glynn
Contributor
11 years ago

Setting up Excel driver and using variables

Hi! I am running into some difficulties setting up my new scripts with variables contained in my Excel worksheet. I am converting my Keyword tests into Scripts and need to pass in my values contained in the worksheet.



Here is what I know so far.



I need to set up the driver and provide the path to my spreadsheet. Do I just declare my variables as usual and then pass them in? Is that enough for Test Complete to link the two? I have attached a snippet of my script. I need to pass in 3 variables from my spreadsheet; questionTitle, questionStem and SelectAnswer.  



Is there anything I am missing? I have read through all of the provided help online and cannot find a good example of the Excel driver getting setup AND data being passed into a test. It always just shows it getting posted to a log which does me no good.



Thank you so much for your help!



PS: Also, how do I call my Project variables ? Some are stored in Excel spreadsheets, some are declared on the Project itself.

4 Replies

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Veronica


     


    From your example, you seem to be iterating through the Drivers recordset but not actually setting anything from the Driver.


     


    You will need to use the DDT::CurrentDriver::Value() method to access each field and assign it as appropriate, as such:


     


    Sub CurDriverExample


      


      ' Creates a driver


      Call DDT.ExcelDriver("C:\MyFile.xls", "Sheet1")


       


      ' Iterates through records


      While Not DDT.CurrentDriver.EOF()


     


      ' Gets a value from the storage and posts it to the log


      ' Instead of logging, set the value of a Project Variable to be DDT.CurrentDriver.Value(0)

      ' Something like Project.Variables.questionTitle = DDT.CurrentDriver.Value(0)


        Log.Message(DDT.CurrentDriver.Value(0))


        DDT.CurrentDriver.Next()


      WEnd


       


      ' Closes the driver


      DDT.CloseDriver(DDT.CurrentDriver.Name)


      


    End Sub


     


    Full details of the Excel Driver can be found here




    Hope this helps.


     


    Regards,


    Phil Baird




  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    Have you read this article?

    I'd suggest starting here to get a grasp of these concepts.

    Essentially excel would work as a database and you would iterate through a reader.

    Hope that helps! :)
  • I have read those articles but they are mostly geared towards Keyword testing which I am no longer doing. I want to script my tests now. I have my Function set up that does all the heavy lifting, inserting the data, etc.. and which contains the variables and then I have my Test that calls the Function. I am calling my Excel driver within this Test and set up the one 'placeholder' variable that gets passed in with my project variables.



    Example:




    Sub TrueFalseTest()


     


      Dim TrueFalse


      TrueFalse = ""


        Set Driver = DDT.ExcelDriver("C:\Users\server\TG_questionDataApril2014.xlsx", "TrueFalse", True)


        While Not Driver.EOF()  


        


       Call Pub_TestGeneratorQuestions.Publisher_questionPanel1(questionTitle,questionStem,SelectAnswer)


      


      Driver.Next 


      WEnd


      


    End Sub





    My variable for 'questionTitle' within the function looks like this:



    Call title.SetText(Project.Variables.TrueFalse.Value("questionTitle"))

    Should it just be:

    Call title.SetText(("questionTitle"))



    Thanks much!

     


     

  • Hi Veronica,



    You can try this:





     set ddtobj = DDT.ExcelDriver(Ppath  & "User_Info\plan_user.xls","infotwo")

    Do While ddtobj.EOF = False

    project.variables.var1= ddtobj.Value(4)

    ddtobj.Next 

    loop 

    Call DDT.CloseDriver(ddtobj.Name)