Forum Discussion

rhu's avatar
rhu
Contributor
31 days ago
Solved

How to user parameters in a data-driven loop?

I have the following scenario

I use a Testcomplete Keywordtest to login to a customer page
in  a search field  i enter some Text and press search
if i get a result a button appears and will be press and after pressing the button an automatic action will be done like entering the text to a list.
For dataloop I use a csv file where I enter the text to be searched and that will be entered to the list as a result.
Lest say the csv file contains 4 lines (1 description and 3 Values) and then adds Text1 Text2 Text3 to the list (1 line per entry)
Value
Text1
Text2
Text3
- THIS IS ALREADY WORKING 


No I want to generalize the test and use parameters (that i can set in the "testexecution-list")

Is that possible? And if so what character like ";" do i have to use for separating the single parameter-entries (e.g.Text1;Text2;Text3) so that the loop wil enter 3 correct entries to the list.

If no possible is it possible to add the paramteres to the csv file (each Value in 1 Line) so that it could also work.
If so how?

Thanks for help

  • You can pass a string variable like so /PSVar:carNames="BMW, Audi, Ford, Lexus" at the command line. You will then need to split and read each value of the string variable, which then becomes "BMW", "Audi", "Ford", "Lexus"

7 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    This can be achieved via scripting in a number of ways, but you need to define your data structure first i.e. the inputs. 

    Comma-separated values (CSV), usually contains a set number of columns, first being the header, followed by X number of rows that contains the data.

    Year, Make, Model, Trim, BodyStyleName, ChromeTrim
    2003, Acura, CL, 3.2 Type S, Coupe, 2dr Cpe 3.2L Type S
    2003, Acura, CL, 3.2 Type S, Coupe, 2dr Cpe 3.2L Type S 6-Speed
    2003, Acura, CL, 3.2, Coupe, 
    2002, Acura, CL, 3.2 Type S, Coupe, 2dr Cpe 3.2L Type S
    2002, Acura, CL, 3.2, , 2dr Cpe 3.2L
    2001, Acura, CL, 3.2 Type S, Coupe, 2dr Cpe 3.2L
    2001, Acura, CL, 3.2 Type S, Coupe, 2dr Cpe 3.2L Type S
    1999, Acura, CL, , Coupe, 2dr Cpe 2.3L Manual
    1999, Acura, CL, 3, Coupe, 2dr Cpe 3.0L
    

    Read the csv file, and pass the appropriate data to the function - empty values can be ignored

  • rhu's avatar
    rhu
    Contributor

    Sorry to say but i do not think that will solve my problem.
    I want to run the test with different "values" and want to set these values at the start of the test
    E.g. i will run the tets with Value "Test1"
    Then another person running the tets wants to use the following values" xyz", "abc"
    A third person will run the test with e.g. the following values "Tester", "testvaluezzz"
    So there is no fixed list and i want to give the values at the start of the test and then do a data-diven test with all values i set in the "parameter" at start

    • rraghvani's avatar
      rraghvani
      Champion Level 3

      To run with different values, you will have to modify the csv file, or alternatively, you can use TestComplete Command Line with parameters /PSVar or /PrjVar.

      Within my Project Suite, users have the options to run the automation based on different configurations defined in the ini file.

  • rhu's avatar
    rhu
    Contributor

    Thanks, using the commandline sounds a little better but is it also possible to enter multiple values within the commandline (so that i can do a data-loop)?
    The idear behind is:
    1st set userrights to a used testuser (on a customer webpage)
    2nd  do a specific test with minumul userrights (that i set before)
    3rd delete userrights

    And as i need more that 1right i am actually doing that with a predefined .csv file and dataloop (this already works,
    but i have to use/adapt the csv file before each testrun it i need different "values".

    So i tried to "generalize" it but did not find a method where i can set the values at teststart.

    If there would be a posibility to enter mutliple values for a parameter and use it in dataloop i could enter the values at testexecution or in the executionplan for each test (instead of using a csv for each test)

    • rraghvani's avatar
      rraghvani
      Champion Level 3

      You can pass a string variable like so /PSVar:carNames="BMW, Audi, Ford, Lexus" at the command line. You will then need to split and read each value of the string variable, which then becomes "BMW", "Audi", "Ford", "Lexus"

  • rhu's avatar
    rhu
    Contributor

    Ok thanks for help. I will check if that is easier for us.
    Did i get it right, it is only possible when using a variable and enter the variable values via commandline, seperate it with a  script to multiple values and use the variable in dataloop.
    But it is not possible to do it with multiple parameters (in a dataloop) what would be much easier.
    Nevertheless thatnks for your help. I will close it now

    • rraghvani's avatar
      rraghvani
      Champion Level 3

      It's best to create a new project, to try the different methods that I've mentioned, and see which one will suit you and your users.

      Think about the size of your inputs, if you have 100's, then passing parameter via command line may not be suitable.