Forum Discussion

ngocvo3103_1's avatar
ngocvo3103_1
Occasional Contributor
14 years ago

How to run specific rows in data-driven test in script?

Hi all,



Please show me how to run specific rows in data-driven test in script? For example, I have 10 rows in the excel file, and I want to run the test with row number 5 to 9. Can anyone show me how to do it?



Thanks

8 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    There are a couple of ways of doing this.



    First, if your excel file has a column of unique ID's, you could modify your DDT driver to query for the specific ID's.  Something like



    var MyDDTDriver = DDT.ExcelDriver("C:\\Temp\\MyExcel.XLS", "MyDataSheet", true)

    MyDDTDriver.ADOCommandObject.CommandText = "SELECT * from MyExcel.XLS where ID BETWEEN 5 AND 9"



    Now, the SQL statement I have here might be incorrect... I personally work with CSV files which simplifies the queries a bit.



    The second way is to increment through the loop.  This takes a bit of a performance hit but it is a legitimate way and actually will translate if you're doing this in a keyword test.



    var MyDDTDriver = DDT.ExcelDriver("C:\\Temp\\MyExcel.XLS", "MyDataSheet", true)

    var CurrentRecord=1

    var StartRecord = 5;

    var EndRecord = 9

    for(CurrentRecord=1;CurrentRecord<=StartRecord;CurrentRecord++)

    {

        MyDDTDriver.Next()

    }

    while ((!MyDDTDriver.EOF()) && (CurrentRecord <= EndRecord))

    {



        DoWhatINeedToDo()

        CurrentRecord = CurrentRecord++

        MyDDTDriver.Next()

        

    }




    Note, the code has not been tested but that's how I would probably handle it.
  • If you're using keyword testing, you can double click on your data driven loop and follow the propmpt for selecting your excel data source. You can then specify the start and finish lines of the driving data e.g start line 5 finish line 10
  • ngocvo3103_1's avatar
    ngocvo3103_1
    Occasional Contributor
    Hi all,



    Thank you for answering me. I'm sorry for not specifying the case that I'm using script.



    To Robert Martin, can you please more specify about the first way? I think that's exactly what I'm looking for. I have a case, if I'm using the SQL Server 2008 to store test data, how can I retrieve it using the DDT?



    Thanks,



    Ngoc Vo
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    For a SQL database, use DDT.ADODriver.



    To use the specific values or rows you want from that driver, you would, again, reference the ADOCommandObject from the driver and set the CommandText to the SQL query you want.


  • Hi



    I want to make a text file where i will store my customize logs corresponding to action performed in my customized keywords.

    So how could i get access to current log folder in the project.



    Also suggest me the best way to work with environmental variable.



    Plz help...
  • Hi,



     
    There's no way to access the current log. Export it to XML and parse the created file, work with the logs of previous executions, or handle log events such as OnLogMessage, OnLogError, etc and save messages to an external file in their handlers.



    As for environment variables, use the aqEnvironment.GetEnvironmentVariable method.



    Also, your question is not related to the topic of this thread. In such cases, create new threads rather than posting unrelated questions to existing ones.
  • Dear Jared,





    You didn't got my question, i want to get the handle to current log folder to create a text file in that folder..



    Thanks in advance
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    First, as Jared mentioned, please post new questions in new threads.  It helps make them more searchable and relevant.



    In any case, by default, logs for a project are stored in the Log folder under the project folder.  So, as long as you're using the standard project pathing, your log folder can be found by concatenating a string like



    var LogFolder = Project.Path + "\\Log\\"