I have a python library that implements robot framework keywords. I’m generating a test suite automatically given a yaml file and I have one last function to run the suite.
try:
result = test_suite.run(output=output_path)
stats = result.statistics
if stats.total.failed:
raise Exception(f"At least one test failed. Output: {output_path}")
except FileNotFoundError:
pass # Ignore if the file does not exist
return result
When I execute the code, everything is correct and my tests are running, but in the end I get this error:
Reading XML source failed: Incompatible child element ‘statistics’ for ‘kw’.
I already check the robot versions and they seem to be correct.
Any ideias? Thank you in advance!
Could you please check which Robot Framework Version you have installed?
You can just do a pip show robotframework to get the details about the installed package.
However, what I can say:
The message complains about finding an statistics element for a kw (keyword).
That error message makes sense to me, as there should indeed not be an statistics element for a kw . Statistics should only exist on the root suite element.
So something is maybe corrupt in your output.xml file.
Can you check it manually and search for statistics elements in there? And check where they appear?
Question about that function:
Do I see it correctly that is is actually a Robot Framework Keyword (@keyword(“Run Robot Tests”) in Python which then again executed a test_suite which is handed over as an argument ?
And you call that Keyword Run Robot Tests from inside anothter Robot Framework Test Case?
*** Test Cases ***
Generate And Run Test Cases
${file_path}= Set variable ${CURDIR}${/}tests_for_api_name.yml
${test_cases}= Read Yaml Test File ${file_path}
${suite}= Generate Robot Tests ${test_cases} ${file_path}
Run Robot Tests ${suite}
So basically in my python file I have 4 keywords: “Read Yaml Test File”, “Generate Robot Tests”, “Run Robot Tests” and “Request Api Call” which I only call from the “Generate Robot Tests” keyword.
I believe the problem is in the “Generate Robot Tests” keyword, which I showed in the post.
In my case I don’t have multiple processes writing the file.
I checked the version that i have installed and it is this one:
Name: robotframework
Version: 7.0
Summary: Generic automation framework for acceptance testing and robotic process automation (RPA)
Home-page: https://robotframework.org
Author: Pekka Klärck
Author-email: peke@eliga.fi
License: Apache License 2.0
but i’ll check the post you sent me for more information.
In my company we have one project with similar framework in which we generate test cases dynamically from a .yaml file and afterwards run them in Robot Framework.
However, we trigger that whole process for test case generation and execution from a python script (and not from inside a Robot Framework Test Suite).
So only the actual test cases will later be executed in Robot Framework (by using its api, similar like you do in the Run Robot Tests Keyword).
As your Keywords Read Yaml Test File , Generate Robot Tests and Run Robot Tests are also written in Python, I recommend to try running them from a Python script instead and not from inside Robot Framework. Maybe this would already solve some weird problems about the output.xml
I did it using robot framework because I believe I didn’t have any more options due to the framework we use. But I’ll search a little bit more to see if I can change that. It would simplify a lot if I could only use Python.
Thanks for you time
Don’t get me wrong, I strongly recommend to stay with Robot Framework as your test execution framework.
I would just slightly change how you “call” the process for the Test Case Generation and the Start of the Execution.
I will try to share an example later what I mean
I believe that is exactly what is happening.
Basically I am running this is a suite:
*** Test Cases ***
Generate And Run Test Cases
${file_path}= Set variable ${CURDIR}${/}tests_for_api_name.yml
${test_cases}= Read Yaml Test File ${file_path}
${suite}= Generate Robot Tests ${test_cases} ${file_path}
Run Robot Tests ${suite}
and then when I call Generate Robot Test keyword, I am creating another suite with some other tests to execute. That’s why the output gets “corrupted”.
I think I am going to try to change my approach. Thank you