Modular file, import code, library, OOP

Is it possible to import other .robot file into current robot file so the Keywords in other file can be reference and use (like in other OOP language, C# Java etc…).

What I have done:
I have completed until the level 2 tutorial course, and read a bunch of document.
But still doesn’t find anything that help.

It seems like whenever I run the robot with rcc run , it will run the tasks.robot only. Although robocorp is more like a procedural language, I do like to have separated code file that define my own Keywords so it can be reused in the main or other robot file, kinda like making my own library api, so it may be more maintainable and testable.
Is there a similar concept of modularize code, importing code for robocorp? Please advice. thanks.

Hi, @mingliangchua!

Yes, it is possible to import robot files into robot files.

Take a look at this example robot:

Here’s the GitHub repository:

If you open the tasks.robot file, you see that there is this line in the *** Settings *** section:

Resource          invoices.resource

That invoices.resource is a keyword file that resides in a separate folder (see here). Note that you can use either .robot or .resource extension with those files.

See the official Robot Framework User Guide for more information.

Note that if your import files are located in a separate folder, you need to add that folder in the robot.yaml file so that it is included in the Python path (see here).

If you have more questions, we are happy to help!

1 Like

Great! It is just what I’m looking for. Thanks!