Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Get Environment Variables In Robot Framework Python

In some cases, test report should include computer name, user name and operating system to identify on which computer tests were run, who run the test, and on what operating system tests were run.  All of these information are environment variables. In Robot Framework we can obtain environment variables by using Operating System provided keywords.  See the example below. 

 

Step 1: Create a test suite and import library "OperatingSystem". 

Step 2: Add a test case named "GetEnvironmentVariableTest" and add following steps. 

Text View of the steps above

*** Settings ***
Library           OperatingSystem

*** Test Cases ***
GetEnvironmentVariablesTest
    [Tags]    system
    ${ComputerName}=    Get Environment Variable    COMPUTERNAME
    ${OperatingSystem}=    Get Environment Variable    OS
    ${TestUserName}=    Get Environment Variable    USERNAME
    ${SystemDir}=    Get Environment Variable    WINDIR
    ${ProcessorLevel}=    Get Environment Variable    PROCESSOR_LEVEL
    Log    ${ComputerName}
    Log    ${OperatingSystem}
    Log    ${TestUserName}
    Log    ${SystemDir}
    Log    ${ProcessorLevel}

Run the test and see the result

RobotFrameworkTest.SystemVariable                                                                                                                                       
=====================================================================================================
RobotFrameworkTest.SystemVariable.Tests                                                                                                                                 
=====================================================================================================
GetEnvironmentVariablesTest                                                                                                                                     | PASS |
---------------------------------------------------------------------------------------------------
RobotFrameworkTest.SystemVariable.Tests                                                                                                                         | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
====================================================================================================
RobotFrameworkTest.SystemVariable                                                                                                                               | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
====================================================================================================
RobotFrameworkTest                                                                                                                                              | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
====================================================================================================
Output:  C:\RobotFrameworkTest\TestResult\output-20140812-231708.xml
Log:     C:\RobotFrameworkTest\TestResult\log-20140812-231708.html
Report:  C:\RobotFrameworkTest\TestResult\report-20140812-231708.html

test finished 20140812 23:17:10

Log Result

Starting test: RobotFrameworkTest.SystemVariable.Tests.GetEnvironmentVariablesTest
20140812 23:17:09.664 :  INFO : ${ComputerName} = SELENIUMMASTER-
20140812 23:17:09.664 :  INFO : ${OperatingSystem} = Windows_NT
20140812 23:17:09.664 :  INFO : ${TestUserName} = Selenium Master
20140812 23:17:09.664 :  INFO : ${SystemDir} = C:\Windows
20140812 23:17:09.664 :  INFO : ${ProcessorLevel} = 16
20140812 23:17:09.664 :  INFO : SELENIUMMASTER-
20140812 23:17:09.679 :  INFO : Windows_NT
20140812 23:17:09.679 :  INFO : Selenium Master
20140812 23:17:09.679 :  INFO : C:\Windows
20140812 23:17:09.679 :  INFO : 16
Ending test:   RobotFrameworkTest.SystemVariable.Tests.GetEnvironmentVariablesTest