Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

How To Read Values From Text File In Robot Framework

In Robot Framework, you can use the keyword "Get File" in OperatingSystem to read values from a text file. Let's say, you have a text file "TestFile.txt" in your robot project folder "D:\RobotExample". Here is the file content. 

 

Selenium Master 

Here is the robot framework code to read the text file and assign its content to a variable.

*** Settings ***
Library           OperatingSystem

*** Test Cases ***
Read Text File
    [Tags]    test text
    ${TextFileContent}=    Get File    TestFile.txt
    Log    ${TextFileContent}

Run the robot framework script and see the result log below; test result is written under TestResult folder. 

RobotExample                                                                                             
=========================================================================================================
RobotExample.Read File Suite                                                                             
=========================================================================================================
Read Text File                                                                                   | PASS |
---------------------------------------------------------------------------------------------------------
RobotExample.Read File Suite                                                                     | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
=========================================================================================================
RobotExample                                                                                     | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
=========================================================================================================
Output:  D:\RobotExample\TestResult\output-20150411-172035.xml
Log:     D:\RobotExample\TestResult\log-20150411-172036.html
Report:  D:\RobotExample\TestResult\report-20150411-172036.html

test finished 20150411 17:20:36
Starting test: RobotExample.Read File Suite.Read Text File
20150411 17:20:36.377 :  INFO : Getting file 'D:\RobotExample\TestFile.txt'
20150411 17:20:36.377 :  INFO : ${TextFileContent} = Selenium Master
20150411 17:20:36.377 :  INFO : Selenium Master
Ending test:   RobotExample.Read File Suite.Read Text File

Test passed and the text file content is assigned to the variable ${TextFileContent}.