Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robot Framework resource and library file difference

What is the difference between resource and library file in robot framework? I searched google but couldn't able to find the answer

like image 402
RobotFython Avatar asked May 10 '19 06:05

RobotFython


People also ask

What is resource file in Robot Framework?

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).

What are the Robot Framework file extensions?

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.

What is BuiltIn library in Robot Framework?

BuiltIn is Robot Framework's standard library that provides a set of generic keywords needed often. It is imported automatically and thus always available.

How do I import a Python library into Robot Framework?

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().


1 Answers

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.

like image 92
Todor Minakov Avatar answered Sep 30 '22 12:09

Todor Minakov