robotframework
robotframework copied to clipboard
Variable file using `BuiltIn.run_keyword` can cause output.xml to be invalid
This happens only if path to tests is direct path to file. If the path is to parent dir then 'suite' tag is in the output between 'robot' and 'kw' tags.
I checked in rf6.1.1 and rf4.1.3 and it exists on both.
All the information to reproduce are visible on the screenshot:
The reason for the error is that suite execution hasn't properly started yet and there is no <suite>
element in the output.xml file under which the <kw>
element belongs to. If you execute a directory, there's already a <suite>
element (the <kw>
ends up under wrong <suite>
), but when you execute just a file, there's no <suite>
whatsoever and having a <kw>
directly under the <robot>
element isn't allowed.
It would be easy to change output.xml parsing so that <kw>
elements under the <robot>
element would be silently ignored, but I don't like throwing away data like that too much. A better solution would be adjusting output.xml writing so that <suite>
would be written earlier. I'm afraid it wouldn't be exactly trivial and I don't consider that important enough to be investigated this late in RF 7.0 development cycle. Notice that if you had provided examples as test, not as a hard to read screenshot, it would have been easier for me to test this.
In your example you seem to be setting a suite level variable in a variable file. That sounds pretty odd, because the point with the variable file is to create such variables and there's no need to use BuiltIn.run_keyword
or any other Robot API. Have you studied the documentation related to variable files to see how they typically are used? If yes, what is the use case for using BuiltIn.run_keyword
?
Well, here are the factors that resulted in such solution:
- I need to use suite setup with some data from Variables section.
- In these Variables section data I need to use some dynamically set variables, let's say ids, unique per suite. I have some resource file with keywords generating these variables, however I cannot use it in suite setup before actual keyword (like: Suite Setup Run Keywords Setup Dynamic Vars Do Actual Setup), because Variables section is resolved before suite setup and these variables will not be available yet.
- That's why I used Variables in Settings section which is resolved earlier, and inside this Variables file I'm triggering my keyword from resource file, which sets suite variables internally. I wanted to avoid reimplementation of this custom kw inside variables file as it's come common resource.
Ok. I would recommend you to implement the logic in Python so that you can directly use it from the variable file. You could then also expose the logic as a keyword if needed.
I leave this issue open because we in general should change logging so that <suite>
(and <test>
and <kw>
, ...) is written earlier. The problem is that we currently write some attributes like name
to it and we don't know them that early. In practice we needed to first write an empty <suite>
and names etc. later under some new element. That's big and backwards incompatible change and won't happen in the near future.