Skip to content

1.5. Create a common resource file

Goal

  • Move the keyword named Print Your Name to a common resource file named greetings.resource.
  • Import this resource file in 01-Greetings suite to make Greetings test case pass.
  • Rename Greetings test case to Original Greetings.
  • Store another name in the greetings.resource and log it in a new test case named Greetings Again using Print Your Name keyword.

Solution

Hints

You can import resource files using the Resource setting in the *** Settings *** table.

Click here to learn more about importing resource files.

You can use built-in variables related to operating system like ${CURDIR}, ${EXECDIR} and ${/} when you define the path for a resource file.

Click here to learn more about operating system related variables.

Solution: tests/01-greetings/resources/greetings.resource
1
2
3
4
5
6
7
*** Keywords ***
Print Your Name
    [Arguments]    ${your_name}=Jane Doe
    Log    ${your_name}

*** Variables ***
${ANOTHER_NAME_IN_RESOURCE}    Common Name
Solution: tests/01-greetings/01-greetings.robot
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
*** Test Cases ***
Original Greetings
    Print Your Name
    Print Your Name    ${YOUR_NAME}

Greetings Again
    Print Your Name    ${ANOTHER_NAME_IN_RESOURCE}

*** Settings ***
Resource    ${CURDIR}${/}resources${/}greetings.resource

*** Variables ***
${YOUR_NAME}    Your Name

Results

Inside the tests folder, execute the following command to execute both test cases.

1
robot .

You can check the generated log.html file to see how your test cases worked.


Last update: June 22, 2020