Create common robot file for generic actions in robot framework

Hi,

I want to create common.robot or common resource file in robot framework where I can write all common methods for Click action , Input , select etc.

Further I can import that wherever needed and reuse it
Need help , please

Hi @bk-user ,

The section of the documentation you need is here: 2.8.1 Resource files

You can name the file as .resource or .robot, you import them with the resource keyword in the settings section. I find to syntax highlighting doesn’t work in some editors when you use .resource so I usually use .robot

You can also create a base .robot file that includes several .robot files, then you can group the keywords in several .robot files as needed but only have one .robot file to include in your test cases.

Here’s an example for an imaginary app:

myapp_tests/test_1.robot

*** Settings ***
Resource    ../myapp_keywords/main.robot

*** Test Cases ***
Test 101
    Myapp Login
    Myapp Nav To Screen A
    Myapp Close Screen A
    Myapp Nav To Screen B
    Myapp Close Screen B
    Myapp Logout

myapp_tests/test_2.robot

*** Settings ***
Resource    ../myapp_keywords/main.robot

*** Test Cases ***
Test 201
    Myapp Login
    Myapp Nav To Screen B
    Myapp Close Screen B
    Myapp Nav To Screen C
    Myapp Close Screen C
    Myapp Logout

myapp_keywords/main.robot

*** Settings ***
Resource    login.robot
Resource    screen_a.robot
Resource    screen_b.robot
Resource    screen_c.robot

myapp_keywords/screen_a.robot

*** Settings ***

*** Keywords ***
Myapp Nav To Screen A
    Log    Open Screen A

Myapp Close Screen A
    Log    Close Screen A

myapp_keywords/screen_b.robot

*** Settings ***

*** Keywords ***
Myapp Nav To Screen B
    Log    Open Screen B

Myapp Close Screen B
    Log    Close Screen B

myapp_keywords/screen_c.robot

*** Settings ***

*** Keywords ***
Myapp Nav To Screen C
    Log    Open Screen C

Myapp Close Screen C
    Log    Close Screen C

Hope that gets you started,

Dave.