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 “doc.txt” in your robot project folder . Bellow is the code how to read file form the text file.

*** Settings ***
Library OperatingSystem

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

The output will come in as

Starting test: File.Read Text File
20170922 11:53:47.470 : INFO : Getting file ‘<a href=”file://C:\Users\Maa\robot\doc.txt”>C:\Users\Maa\robot\doc.txt</a>’.
20170922 11:53:47.486 : INFO :
${TextFileContent} = *** Settings ***
Library Selenium2Library

*** Test Cases ***
Tc1
Open Browser http://www.google.com ff

20170922 11:53:47.486 : INFO :
*** Settings ***
Library Selenium2Library

*** Test Cases ***
Tc1
Open Browser http://www.google.com ff

Ending test: File.Read Text File