Forum Discussion

ucuber's avatar
ucuber
Occasional Contributor
6 years ago

CSV Parameter trickery in keywordtests

 Hi *,

 

- I'm working with a data driven loop, connected to a csv file.

- The file holds scenario data organized in the form scenario;device_name;input1;input2;...;expected1;expected2;...

- The scripted test (in python) has the parameters def test(scenario, device, **kwargs).

 

**kwargs should take a dynamic numer of key-value-pairs, the input and expected values. But the kwargs-part is not shown in the keywordtest as valid parameter to be filled with values.

 

With *args which resembles a dynamic list of pararameter values it is a little bit different, because the argument is shown, but I can only address a single value to the list. And it does something very weird with the Operations Parameters order: if i have scenario, device, *args it presents scenario, args, device and even when I connect the correct values it switches the order. When I omit the astersik, everything is as it should.

 

TL;DR;

I have to accept TestComplete does not really support these typical pythonic constructs **kwargs and *args as Operation Parameters in keyword tests that call scripted code.

 

What to do now? I do not want to name every possible field in the parameter list of the script because this is ugly, not pythonic and worst of all: the number of fields may change in the (near) future

 

So there must be a way in the data driven loop to tell TestComplete that it takes a whole row and adresses it to a single variable, whatever format. Does anyone have an idea?

 

Regards

 

Ulrich

 

 

 

 

1 Reply

  • ucuber's avatar
    ucuber
    Occasional Contributor

    This is funny ... I'm thinking about things and do not have a clue and in the moment I've asked the community I have a possible solution in mind :-)

     

    I want to show what I think is a possible (but somewhat ugly) solution to the described problem:

     

    The local or project variable that holds the csv row is of type DB Table. If I hand over this one I can extract the values into a dictionary and everything is fine.

     

    test(scenario, device, db_table):

      values = dict()

      for i in range(0, db_table.ColumnCount):

         name = db_table.ColumnName[i]

         values[name] = db_table.Value[name]

      ...

     

    Feel free to comment/modify

     

    Regards

     

    Ulrich