Skip to content

1.8. Global variables

Goal

  • Store another name in the __init__.robot file and log it in a new test case named Greetings From Global using Print Your Name keyword.

Solution

Solution: tests/__init__.robot
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
*** Settings ***
Suite Setup       Global Suite Setup
Suite Teardown    Global Suite Teardown

*** Keywords ***
Global Suite Setup
    Log    Our Robot awesomeness begins!
    Set Global Variable    ${NAME_FROM_INIT}

Global Suite Teardown
    Log    The end of the awesomeness!

*** Variables ***
${NAME_FROM_INIT}    Global Name
Solution: tests/01-greetings/01-greetings.robot
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
*** Test Cases ***
Original Greetings
    [Tags]    ubuntu
    [Documentation]    This test case checks that the Print Your Name keyword works as expected.
    Print Your Name
    Print Your Name    ${YOUR_NAME}

Greetings Again
    [Tags]    centos
    [Documentation]    This test case proves that we can import variables from resource files.
    Print Your Name    ${ANOTHER_NAME_IN_RESOURCE}

Greetings From Init
    [Tags]    centos    ubuntu
    [Documentation]    This test case proves that we can create global variables using initialization files.
    Print Your Name    ${NAME_FROM_INIT}

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

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

Results

Inside the tests folder, execute the following command.

1
robot .

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


Last update: June 22, 2020