Repository navigation
Description
The TestSuite structures we use on the execution and result sides (robot.running.model and robot.result.model, respectively, with a common base classes in robot.model) have certain things that need to be changed:
-
Remove
keywordsandmessagesfrom execution sideKeywordobjects. These keywords never actually have child keywords or messages, they just represent the keyword call with the keyword name and arguments. Basically this means moving the related code from the common base class to the result side model objects. -
TestSuiteobjects should not havekeywordsattribute but instead should havesetupandteardowndirectly. Suites having keywords is odd in general and being able to use e.g.suite.setupinstead ofsuite.keywords.setupis convenient. -
keywordsattribute used byTestCase,For,If(new in RF 4.0) andUserKeywordobjects should be renamed tobody. The body can contain FOR loops and soon also IF/ELSE in addition to keywords sobodyis a much better name thankeywordsand that's also the term parsing side model uses. The forthcomingIfElseobjects should naturally havebody, notkeywords, as well. -
Add
setupandteadowndirectly toTestCaseandUserKeywordobjects. Accessingtest.setupis more convenient than the currenttest.keywords.setupandtest.body.setupwould be just wrong. -
Make
setupandteardownobjects, notNone, also when they are not defined. This makes it easier for external code like pre-run modifiers to modify them. Their initial truth value should be false to make it possible to use code likeif test.setup:.
This kind of changes are naturally backwards incompatible but in my opinion better model is worth that. We should, however, preserve keywords as a deprecated read-only property that is generated based on body and setup/teardown when accessed.
[Update on 2021-01-18] Everything discussed above has now been done, but doing these changes has uncovered other highly related problems in the model that also need to be changed:
-
On the execution side make
ForandIfindependent classes instead of extendingKeyword. They don't need keyword related attributes likenameorargs, but instead they should have context specific attributes likeFor.flavorandIf.condition. Earlier those context specific attributes were implemented as properties but they should be normal attributes. Old keyword specific attributes should probably be preserved as deprecated properties for backwards compatibility. -
Add separate
visit/start/end_forandvisit/start/end_ifmethods to the visitor interface. EarlierForandIfwere visited usingvisit/start/end_keywordbut that doesn't work anymore when they don't extendKeyword. -
Add separate
ForandIfclasses on result side. Currently FOR and IF construct are reported as keywords withtypeset accordingly. This makes inspecting FOR/IF hard because their context specific information is not directly available and need to be parsed from keyword attributes. For example, all FOR information is in keyword name in format like${x} IN [ a | b | c ]. This change requires some changes to output.xml as well and I added a separate comment about that. -
On the result side move keywords' messages to
bodyto preserve their relative order with keywords and FOR/IF constructs. This makes it easier to preserve their order also in log (Relative order of messages and keywords is not preserved in log #2086). The oldmessagesattribute should be preserved as a property to make accessing only messages easy.
Activity
pekkaklarck commentedon Oct 30, 2020
These changes affect also pre-run modifier examples in the User Guide:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#example-skip-setups-and-teardowns
Related to those examples, we need an easy way to disable setup/teardown.
pekkaklarck commentedon Nov 26, 2020
Important things to decide:
Should visitor and listener APIs be changed? They both currently have
start/end_keywordmethod which are called also with FOR and IF constructs. Should we add separatestart/end_forandstart/end_ifmethods? If we do, they could callstart/end_keywordby default to avoid backwards incompatibly problems.Should we change
<keywords>to<body>also in output.xml? It would make this change even more backwards incompatible, but output.xml being inconsistent with internal model would also be a smallish problem. If we would decide to change output.xml format, we need to submit a separate issue about it and enhance output.xml also otherwise. For example, attributes currently using valuesyesornoshould be changed to usetrueorfalse(i.e.xsd:booleantype).model: setters for setup and teardown (#3782)
prescod commentedon Dec 12, 2020
Relevant to your refactor:
I'm trying to measure and log the execution time of tests with Setup and Teardown subtracted. I'm having a tough time using the current Listener V3 Results object to do so.
Given this test:
And this code:
I get:
So the result model thinks I have 0 keywords and the running model thinks I have 3.
But the running model has no start-time or end-time. So I have not figured out how to get a hold of the elapsed time for the Setup and Teardown in the end_test listener hook.
20 remaining items
boakley commentedon Feb 2, 2021
Having an
<if>inside an<if>, and having<if>both represent an "if" and "else" seems very odd. Why not a single tag such as<block>or<compound>which could be used for all statements that start a block of statements? For example,<block type='for'>,<block type='if'>,<block type='else'>, etc? Then, if robot ever gets a "with" or "while" or "try" statement, we don't have to invent more tags.pekkaklarck commentedon Feb 3, 2021
A problem with a generic element like
<block>is that IF and FOR need to store different information. This means that depending on the usage<block>would have different attributes and/or child elements. This makes, for example, creating a schema harder.pekkaklarck commentedon Feb 11, 2021
Some more work to be done still:
Ifobject with all its branches inbodyand not the next ELSE IF or ELSE inorelse. Also change output.xml accordingly. This was discussed in the comment above.Refactor IF/ELSE running and result model. Part of #3749.
Model: Better type constant names and values.
pekkaklarck commentedon Feb 11, 2021
IF/ELSE model model and type constants were enhanced by the comments linked above. Class, method and attribute names were enhanced in 00c282f
Store FOR loop iterations better internallly and in output.xml.
pekkaklarck commentedon Feb 12, 2021
Everything listed above now done. Closing this again.
pekkaklarck commentedon Mar 3, 2021
As #3868 demonstrates, external tools using
test.keywords.create()need to be updated becausekeywordsis nowadays only a read-only property. The new way to write that istest.body.create_keyword(). This code is compatible both with the old and new model: