tl;dr: is there a way to apply a datadriver Excel input file’s cell format to the variable’s format that is conveyed to the robot test?
Moin René,
first of all let me say that my users love the option of providing test data via Excel sheets. Great job with designing the datadriver library. There is however an issue that I have not yet found a solution for - maybe, you have an idea on how to solve this issue.
My main use case for using the data driver are API tests. Read: I have tons of potential input parameters which I expose to the users via an excel sheet.
- The end user populates all required parameters (read: Excel cells).
- My Robot script checks on a test-specific basis which of the test-specific cells are populated.
- If the cell is populated, its value is then added to a Robot dictionary
- That dictionary is later on converted to a JSON object which then is sent to my API.
This whole process works like a charm. However, there is an edge case which I need to cover but have not yet found a viable solution for:
Some of the APIs that I use require numeric content to be provided as string data: Read: my Excel cell will contain a value of e.g. 3 but I need to add the STRING value of “3” to the robot dictionary so that when it gets converted to the final JSON object.
Let’s assume that I have a data driver Excel input file which contains two variable columns with just one row of data:
${VAR1} --> numeric value of 1
${VAR2} --> string value of 2 (e.g. cell's format was set to string, Input was '2 in order to enforce string format)
When I check the data type ‘the Python way’, both variable’s data types are returned as ‘string’:
Check Variable Type New
[Arguments] ${object}
${VARTYPE}= Evaluate type($object).__name__
[Return] ${VARTYPE}
This crude yet somewhat effective approach does work for most cases but the one in question:
Check Variable Type
[Arguments] ${object}
Return From Keyword If not "${object}" NONE ${EMPTY}
${result} ${number_value}= Run Keyword And Ignore Error Convert To Number ${object}
${isnumber}= Run Keyword And Return Status Should Be Equal As Strings ${object} ${number_value}
${result} ${integer_value}= Run Keyword And Ignore Error Convert To Integer ${object}
${isinteger}= Run Keyword And Return Status Should Be Equal As Strings ${object} ${integer_value}
${result} ${bool_value}= Run Keyword And Ignore Error Convert To Boolean ${object}
${isbool}= Run Keyword And Return Status Should Be Equal As Strings ${object} ${bool_value}
Return From Keyword If ${isnumber} NUMBER ${number_value}
Return From Keyword If ${isinteger} INTEGER ${integer_value}
Return From Keyword If ${isbool} BOOLEAN ${bool_value}
Return From Keyword STRING ${object}
If this crude detection is applied, both variable’s values are not detected as string but as integer - which is correct for the first case but not desired for the 2nd case where that value’s format was set to ‘string’
Q: apart from detecting these edge cases’ formats with the help of e.g. leading format descriptors in the cell’s value, is there any way for the data driver to get the cell’s format based on its Excel formatting - and then return that cell’s value in its respective format?
Note that this does not only affect numeric data types but also boolean types. E.g.
TRUE (as boolean) and
'TRUE (as string)
are both conveyed to the Robot Test via data driver with a ‘string’ data type
Danke Dir:slight_smile:
Jörg