On Github julienbrunet / robot-training
By Julien Brunet Available on GitHub athttp://julienbrunet.github.io/robot-training
RobotFramework is a test automation framework designed for Acceptance Testing (ATDD)
Example : test the creation of an order on a web application
Download the standalone Robotframerwork package from Github and unzip it on your computer :
The only prerequisite to run this RobotFramework package is java 1.6 min.
This package contains the following folder tree :
robotframework-core All necessary binaries to run RobotFramework tests documentation Documentation on existing libraries and keywords lib External robotFramework library binaries standalone-browsers Binaries for standalone browsers web-drivers Web drivers executable tests Where we write all the tests scripts The entry point of tests keywords The keyword file definitionWrite the following code in a text file named myFirstTest.robot under "scripts" folder
*** Test Cases *** My First Test ${current_year}= Get Time year Should Start With ${current_year} 20
*** Settings *** Library OperatingSystem *** Variables *** ${PATH_TO_CHECK} c:\\temp *** Test Cases *** Check Host Configuration [Documentation] Check config... # Check existence of c:\temp folder Should Exists ${PATH_TO_CHECK} Check Host Date Is 2015 *** Keywords *** Check Host Date Is [Documentation] Check date... [Arguments] ${YEAR} ${host_year}= Get Time year Should Be Equal ${host_year} ${YEAR}
Create a new test case with this Robot Framework code
*** Settings *** Library OperatingSystem *** Variables *** ${PATH_TO_CHECK} c:\\temp *** Test Cases *** Check Host Configuration [Documentation] Check config... # Check existence of c:\temp folder Should Exists ${PATH_TO_CHECK} Check Host Date Is 2015 *** Keywords *** Check Host Date Is [Documentation] Check date... [Arguments] ${YEAR} ${host_year}= Get Time year Should Be Equal ${host_year} ${YEAR}
List of test cases with each test steps inside. Settings of a test cases are :
*** Settings *** Library OperatingSystem *** Variables *** ${PATH_TO_CHECK} c:\\temp *** Test Cases *** Check Host Configuration [Documentation] Check config... # Check existence of c:\temp folder Should Exists ${PATH_TO_CHECK} Check Host Date Is 2015 *** Keywords *** Check Host Date Is [Documentation] Check date... [Arguments] ${YEAR} ${host_year}= Get Time year Should Be Equal ${host_year} ${YEAR}
Contains keywords commons to your test suite. Keywords declared here can be used anywhere in the suite, even in setup and teardown calls. Keywords settings are:
*** Settings *** Library OperatingSystem *** Variables *** ${PATH_TO_CHECK} c:\\temp *** Test Cases *** Check Host Configuration [Documentation] Check config... # Check existence of c:\temp folder Should Exists ${PATH_TO_CHECK} Check Host Date Is 2015 *** Keywords *** Check Host Date Is [Documentation] Check date... [Arguments] ${YEAR} ${host_year}= Get Time year Should Be Equal ${host_year} ${YEAR}
Define variables at a "tests suite scope". Variables declared here are accessible from every test cases, keywords or settings
*** Settings *** Library OperatingSystem *** Variables *** ${PATH_TO_CHECK} c:\\temp *** Test Cases *** Check Host Configuration [Documentation] Check config... # Check existence of c:\temp folder Should Exists ${PATH_TO_CHECK} Check Host Date Is 2015 *** Keywords *** Check Host Date Is [Documentation] Check date... [Arguments] ${YEAR} ${host_year}= Get Time year Should Be Equal ${host_year} ${YEAR}
Library libraryName arg1 arg2...
Resource ../../keywords/myKWords.robot
Suite Setup My Suite Setup Keyword Suite Teardown My Suite Setup Keyword Test Setup My Test Setup Keyword Test Teardown My Test Setup Keyword
Force Tags TAG1 TAG2 Default tags TAG
*** Settings *** Library OperatingSystem *** Variables *** ${EXPECTED_YEAR} 2015 *** Keywords *** Check Host Date Is [Documentation] Check date... ${host_year}= Get Time year Should Be Equal ${host_year} ${EXPECTED_YEAR}
No *** Test Cases *** section in resource files !
__init__.ext
*** Settings *** Suite setup Do Something Library SeleniumLibrary Resource ../keywords/myKw.robot *** Variables *** ${MY_VAR} foo *** Keywords *** Do Something Log ${MY_VAR}
RIDE (RobotFramework Integrated Development Editor) is a light-weight and intuitive editor for Robot Framework test case files written in Python.
<input id="searchInput">
Wikipedia Search Open Browser http://en.wikipedia.org Input text id=searchInput Robot Framework
Input text xpath="xpath value" Robot Framework
<html> <title>My Page</title> <body> <span id="welcome-msg"> Hello World </span> <div name="form1"> <input id="searchInput"> <input type="button" value="Valider"> </div> </body> </html>
/
/html/body/span
//span
//input
//input[@id='searchInput']
//*[text()='Hello World']
//*[contains(text(),'Hello']
Check NY Population Open Browser https://en.wikipedia.org/wiki/New_York ${population1910}= Get NY Population 1910 Should Be Equals ${population1910} 9,113,614You must write the keyword Get NY Population !
@RobotKeywords public class FTPLibrary { public FTPLibrary(){} @RobotKeyword( "Put a file via ftp\n" + "Example :\n" + "| Ftp Put | 192.168.1.1 | user | passwd | C:\\myFile.txt | /home/user/dir |") @ArgumentNames({"host","user","passwd","filePath","targetDirectory"}) public void ftpPut(String host, String user, String passwd, String filePath, String targetDirectory) // Your Java code } }For more information, check the Java lib core documentation