What is the difference between resource and library file in robot framework? I searched google but couldn't able to find the answer
Resource files provide a re-usable way to abstract your test suites. To put it simply, resources files are just like all the other . robot -files, but they should not contain *** Test Cases *** certain *** Settings *** commands (Suite Setup, Suite Teardown, Test Setup or Test Teardown).
Robot Framework supports reStructuredText files using both .rst and .rest extension. When executing a directory containing reStucturedText files, the --extension option must be used to explicitly tell that these files should be parsed.
BuiltIn is Robot Framework's standard library that provides a set of generic keywords needed often. It is imported automatically and thus always available.
To import the Python script inside Robot, we use the keyword Library in the Robot file under settings. To call the function, we use <file_name><dot><function name> . To add keywords inside the function, we use the keyword decorator. Here, BuildIn().
The resource file content is in the Robot Framework syntax. When it's imported in a suite, you can use all its keywords and variables, defined in the corresponding sections. Also all its imports (other Resource
and Library
it defines in the Settings section) are now available for usage.
The libraries on the other hand are (usually) written in the Python language. They can be ones installed through pip
, or standalone scripts or modules. In the simplest case, all public functions of a module (more specifically - not-hidden) are available as keywords to be used in the suite. For more advanced usage (scope, state upkeep), they have to follow specific structure (usually accomplished through classes, and using identifiers/decorators expected by RF).
There is a third type of import, for which you haven't asked but I'm adding for completeness - the Variables
files. Their format is once again Python code, which makes them quite versatile and powerful compared to vars defined in RF syntax (you can set the variables' content through complex programming constructs).
One caveat to keep in mind with them - the framework expects every attribute of the module to be a variable, and makes it accessible in your suite; this includes even other modules the file imports :). Thus you have to hide them through the _
name suffix (or, abuse this side effect for silent imports in some exotic cases :)).
I've included links to the relevant sections of the user guide, for further information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With