Comments (5)
MS Excel and typed cells
Microsoft Excel xls or xlsx file have the possibility to type thair data cells. Numbers are typically of the type float. If these data are not explicitly defined as text in Excel, pandas will read it as the type that is has in excel. Because we have to work with strings in Robot Framework® these data are converted to string. This leads to the situation that a European time value like "04.02.2019" (4th January 2019) is handed over to Robot Framework® in Iso time "2019-01-04 00:00:00". This may cause unwanted behavior. To mitigate this risk you should define Excel based files explicitly as text within Excel.
Alternatively you may deactivate that string conversion. To do so, you have to add the option preserve_xls_types
to True
. In that case, you will get str
, float
, boolean
, int
, datetime.time
, datetime.datetime
and some others.
*** Settings ***
Library DataDriver file=my_data_source.xlsx preserve_xls_types=True
from robotframework-datadriver.
Hallo Jörg,
Nice that you like it!
Regarding the DataTypes:
At the moment the XLS(X) reader are configured so that they do convert all stuff to strings.
But this could be made configurable.
So that this test keyword:
*** Keywords ***
Check Variables
[Arguments] ${var_1} ${var_2} ${var_name} ${var_doc} ${var_tags}
Log To Console \n
Log To Console \${var_1}: ${{type($var_1)}} - ${var_1}
Log To Console \${var_2}: ${{type($var_2)}} - ${var_2}
Log To Console \${var_name}: ${{type($var_name)}} - ${var_name}
Log To Console \${var_doc}: ${{type($var_doc)}} - ${var_doc}
Log To Console \${var_tags}: ${{type($var_tags)}} - ${var_tags}
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 preserve_xls_types=True
for xlsx_reader could you please raise an issue? on Github?
Anyway:
You can also already now use the RF type notation for int ${1}
, float ${1.0}
, and boolean ${true}.
or Python evaluations ${{2+int("3")}}
Cheers
from robotframework-datadriver.
Original Discussion here:
https://forum.robotframework.org/t/get-a-cells-data-type-from-a-datadriver-excel-input-sheet-based-on-its-cell-format/2331
from robotframework-datadriver.
Works like a charm - thanks for applying this change!
from robotframework-datadriver.
Minor addendum:
When preserve_xls_types=True
is used in combination with empty Excel cells, the cell's variable type is always returned as str
. If you need to detect these empty Excel cells in Robot and rather prefer a fake None
data type over a str
data type, the following workaround might be helpful:
Get Data Type
[Arguments] ${object}
Return From Keyword If not "${object}" None
${VARTYPE}= Evaluate type($object).__name__
[Return] ${VARTYPE}
from robotframework-datadriver.
Related Issues (20)
- [Documentation] field on Test Case template not honored HOT 1
- Read literal "null" string from excel file HOT 4
- Variable '&{inputs}' not found. HOT 1
- Pabot Data Driver optimization HOT 1
- Datadriver not picking up timeout value from suite
- Unable to import robotframework-datadriver HOT 1
- [ ERROR ] Calling method '_start_suite' of listener 'DataDriver' failed: HOT 2
- -i tags does not work when [Tags] is column in excel sheet HOT 4
- Spaces around variablenames in CSV header destroy variable recognition HOT 4
- Unable to use dictionary variables in testcase names.
- Modify documentation - Force Tags and Default tags are deprecated
- DataDriver Run in Python with tags (include) HOT 6
- I am using data driver library. How can I include tags at test level when I have test template (suite). I tried giving [Tags] in excel but It's not working? do we have any solution? HOT 1
- Robot 6.1 compatibility HOT 6
- bug: importing a custom reader class from module doesn't work HOT 1
- All tests of a suite are run, if include tag not available in data file
- how to parse all .py files under a testcase dir and generate robot testcases dynamic using robotframework-datadriver lib
- https://docs.robotframework.org/docs/testcase_styles/datadriven interactive example is broken HOT 2
- Rerun failed tests raise an error in the latest 1.11.0 version HOT 2
- Get current row index of excel or any data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robotframework-datadriver.