Reputation: 1
I have a path of a project like this.
Main project
'-Service
'-Main service
'- A.robot
'- B.robot
'-resource.robot
When I run B.robot I would like to call resource.robot in setting file in my code
*** Settings ***
Documentation Test building
Resource resource.robot
Test Template Send data to bus
I expect to include resoucre.robot, but It's return resource.robot does not exist.
How can I import resouce.robot.
Upvotes: 0
Views: 3206
Reputation: 385800
The simplest solution is to use a path relative to the test file. For example, in B.robot you would refer to the resource file like this:
*** Settings ***
Resource ../../resource.robot
Robot will also search through the module search path, so you could define PYTHONPATH to include the directory with your resource files.
The user guide says this about locating resource files:
If the path is given in an absolute format, it is used directly. In other cases, the resource file is first searched relatively to the directory where the importing file is located. If the file is not found there, it is then searched from the directories in Python's module search path. The path can contain variables, and it is recommended to use them to make paths system-independent (for example, ${RESOURCES}/login_resources.robot or ${RESOURCE_PATH}). Additionally, forward slashes (/) in the path are automatically changed to backslashes () on Windows.
Upvotes: 1
Reputation: 329
Resource resource.robot
Would work if resource.robot was at same (directory) level as B.robot...
Main project
'-Service
'-Main service
'- A.robot
'- B.robot
'-resource.robot
You could give it the full path.
You could just use ${CURDIR}
Resource ${CURDIR}/../resource.robot
You also have https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#built-in-variables
Upvotes: 2