body
BaseBody
¶
Bases: ItemList[BodyItem], Generic[KW, F, W, I, T, V, R, C, B, M, E]
Base class for Body and Branches objects.
Source code in src/robot/model/body.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
filter(keywords=None, messages=None, predicate=None)
¶
Filter body items based on type and/or custom predicate.
To include or exclude items based on types, give matching arguments
True or False values. For example, to include only keywords,
use body.filter(keywords=True) and to exclude messages use
body.filter(messages=False). Including and excluding by types
at the same time is not supported and filtering my messages
is supported only if the Body object actually supports messages.
Custom predicate is a callable getting each body item as an argument
that must return True/False depending on should the item be included
or not.
Selected items are returned as a list and the original body is not modified.
It was earlier possible to filter also based on FOR and IF types.
That support was removed in RF 5.0 because it was not considered useful
in general and because adding support for all new control structures
would have required extra work. To exclude all control structures, use
body.filter(keywords=True, messages=True) and to only include them
use body.filter(keywords=False, messages=False). For more detailed
filtering it is possible to usepredicate``.
Source code in src/robot/model/body.py
flatten()
¶
Return steps so that IF and TRY structures are flattened.
Basically the IF/ELSE and TRY/EXCEPT root elements are replaced with their branches. This is how they are shown in log files.
Source code in src/robot/model/body.py
to_dicts()
¶
Return list of items converted to dictionaries.
Items are converted to dictionaries using the to_dict method, if
they have it, or the built-in vars().
New in Robot Framework 6.1.
Source code in src/robot/model/itemlist.py
BaseBranches
¶
Bases: BaseBody[KW, F, W, I, T, V, R, C, B, M, E], BranchType[IT]
A list-like object representing IF and TRY branches.
Source code in src/robot/model/body.py
filter(keywords=None, messages=None, predicate=None)
¶
Filter body items based on type and/or custom predicate.
To include or exclude items based on types, give matching arguments
True or False values. For example, to include only keywords,
use body.filter(keywords=True) and to exclude messages use
body.filter(messages=False). Including and excluding by types
at the same time is not supported and filtering my messages
is supported only if the Body object actually supports messages.
Custom predicate is a callable getting each body item as an argument
that must return True/False depending on should the item be included
or not.
Selected items are returned as a list and the original body is not modified.
It was earlier possible to filter also based on FOR and IF types.
That support was removed in RF 5.0 because it was not considered useful
in general and because adding support for all new control structures
would have required extra work. To exclude all control structures, use
body.filter(keywords=True, messages=True) and to only include them
use body.filter(keywords=False, messages=False). For more detailed
filtering it is possible to usepredicate``.
Source code in src/robot/model/body.py
flatten()
¶
Return steps so that IF and TRY structures are flattened.
Basically the IF/ELSE and TRY/EXCEPT root elements are replaced with their branches. This is how they are shown in log files.
Source code in src/robot/model/body.py
to_dicts()
¶
Return list of items converted to dictionaries.
Items are converted to dictionaries using the to_dict method, if
they have it, or the built-in vars().
New in Robot Framework 6.1.
Source code in src/robot/model/itemlist.py
Body
¶
Bases: BaseBody['Keyword', 'For', 'While', 'If', 'Try', 'Var', 'Return', 'Continue', 'Break', 'Message', 'Error']
A list-like object representing a body of a test, keyword, etc.
Body contains the keywords and other structures such as FOR loops.
Source code in src/robot/model/body.py
filter(keywords=None, messages=None, predicate=None)
¶
Filter body items based on type and/or custom predicate.
To include or exclude items based on types, give matching arguments
True or False values. For example, to include only keywords,
use body.filter(keywords=True) and to exclude messages use
body.filter(messages=False). Including and excluding by types
at the same time is not supported and filtering my messages
is supported only if the Body object actually supports messages.
Custom predicate is a callable getting each body item as an argument
that must return True/False depending on should the item be included
or not.
Selected items are returned as a list and the original body is not modified.
It was earlier possible to filter also based on FOR and IF types.
That support was removed in RF 5.0 because it was not considered useful
in general and because adding support for all new control structures
would have required extra work. To exclude all control structures, use
body.filter(keywords=True, messages=True) and to only include them
use body.filter(keywords=False, messages=False). For more detailed
filtering it is possible to usepredicate``.
Source code in src/robot/model/body.py
flatten()
¶
Return steps so that IF and TRY structures are flattened.
Basically the IF/ELSE and TRY/EXCEPT root elements are replaced with their branches. This is how they are shown in log files.
Source code in src/robot/model/body.py
to_dicts()
¶
Return list of items converted to dictionaries.
Items are converted to dictionaries using the to_dict method, if
they have it, or the built-in vars().
New in Robot Framework 6.1.
Source code in src/robot/model/itemlist.py
BodyItem
¶
Bases: ModelObject
Source code in src/robot/model/body.py
id: str | None
property
¶
Item id in format like s1-t3-k1.
See :attr:TestSuite.id <robot.model.testsuite.TestSuite.id> for
more information.
id is None only in these special cases:
- Keyword uses a placeholder for
setuporteardownwhen asetuporteardownis not actually used. - With :class:
~robot.model.control.Ifand :class:~robot.model.control.Tryinstances representing IF/TRY structure roots.
config(**attributes)
¶
Configure model object with given attributes.
obj.config(name='Example', doc='Something') is equivalent to setting
obj.name = 'Example' and obj.doc = 'Something'.
New in Robot Framework 4.0.
Source code in src/robot/model/modelobject.py
copy(**attributes)
¶
Return a shallow copy of this object.
:param attributes: Attributes to be set to the returned copy.
For example, obj.copy(name='New name').
See also :meth:deepcopy. The difference between copy and
deepcopy is the same as with the methods having same names in
the copy__ module.
__ https://docs.python.org/3/library/copy.html
Source code in src/robot/model/modelobject.py
deepcopy(**attributes)
¶
Return a deep copy of this object.
:param attributes: Attributes to be set to the returned copy.
For example, obj.deepcopy(name='New name').
See also :meth:copy. The difference between deepcopy and
copy is the same as with the methods having same names in
the copy__ module.
__ https://docs.python.org/3/library/copy.html
Source code in src/robot/model/modelobject.py
from_dict(data)
classmethod
¶
Create this object based on data in a dictionary.
Data can be got from the :meth:to_dict method or created externally.
With robot.running model objects new in Robot Framework 6.1,
with robot.result new in Robot Framework 7.0.
Source code in src/robot/model/modelobject.py
from_json(source)
classmethod
¶
Create this object based on JSON data.
The data is given as the source parameter. It can be:
- a string (or bytes) containing the data directly,
- an open file object where to read the data from, or
- a path (
pathlib.Pathor string) to a UTF-8 encoded file to read.
The JSON data is first converted to a Python dictionary and the object
created using the :meth:from_dict method.
Notice that the source is considered to be JSON data if it is
a string and contains {. If you need to use { in a file system
path, pass it in as a pathlib.Path instance.
With robot.running model objects new in Robot Framework 6.1,
with robot.result new in Robot Framework 7.0.
Source code in src/robot/model/modelobject.py
to_json(file=None, *, ensure_ascii=False, indent=0, separators=(',', ':'))
¶
Serialize this object into JSON.
The object is first converted to a Python dictionary using the
:meth:to_dict method and then the dictionary is converted to JSON.
The file parameter controls what to do with the resulting JSON data.
It can be:
None(default) to return the data as a string,- an open file object where to write the data to, or
- a path (
pathlib.Pathor string) to a file where to write the data using UTF-8 encoding.
JSON formatting can be configured using optional parameters that
are passed directly to the underlying json__ module. Notice that
the defaults differ from what json uses.
With robot.running model objects new in Robot Framework 6.1,
with robot.result new in Robot Framework 7.0.
__ https://docs.python.org/3/library/json.html