-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using Excel Source i would like to keep the types... #57
Comments
Hallo Jörg, Nice that you like it! Regarding the DataTypes: So that this test keyword:
results in that output: ==============================================================================
Defaults Xlsx Data Type
==============================================================================
Test 123 :: €‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ
${var_1}: <class 'float'> - 1.0
${var_2}: <class 'str'> - Hello
${var_name}: <class 'datetime.time'> - 08:00:30
${var_doc}: <class 'int'> - 1
${var_tags}: <class 'str'> - ['tag1', 'tag2']
Test 123 :: €‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ | PASS |
------------------------------------------------------------------------------
default 3.41423 True :: ÖÄ?Üß!)=§$
${var_1}: <class 'float'> - 3.41423
${var_2}: <class 'bool'> - True
${var_name}: <class 'str'> - WAHR
${var_doc}: <class 'float'> - 0.02
${var_tags}: <class 'str'> - ['tag1']
default 3.41423 True :: ÖÄ?Üß!)=§$ | PASS |
------------------------------------------------------------------------------
My Test Name
${var_1}: <class 'float'> - 13.0
${var_2}: <class 'bool'> - False
${var_name}: <class 'str'> - 123
${var_doc}: <class 'str'> -
${var_tags}: <class 'str'> - []
My Test Name | PASS |
------------------------------------------------------------------------------
default 1.23 2012-10-05 00:00:00
${var_1}: <class 'float'> - 1.23
${var_2}: <class 'datetime.datetime'> - 2012-10-05 00:00:00
${var_name}: <class 'str'> - 05.06.21
${var_doc}: <class 'str'> -
${var_tags}: <class 'str'> - []
default 1.23 2012-10-05 00:00:00 | PASS |
------------------------------------------------------------------------------
Defaults Xlsx Data Type | PASS |
4 tests, 4 passed, 0 failed
==============================================================================
If you would like to have the option Anyway: Cheers |
MS Excel and typed cells Alternatively you may deactivate that string conversion. To do so, you have to add the option *** Settings ***
Library DataDriver file=my_data_source.xlsx preserve_xls_types=True |
Works like a charm - thanks for applying this change! |
Minor addendum: When Get Data Type
[Arguments] ${object}
Return From Keyword If not "${object}" None
${VARTYPE}= Evaluate type($object).__name__
[Return] ${VARTYPE} |
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.
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:
When I check the data type 'the Python way', both variable's data types are returned as 'string':
This crude yet somewhat effective approach does work for most cases but the one in question:
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
The text was updated successfully, but these errors were encountered: