Writing first test Case using Robot Framework? – User friendly Tech help

After our successful installation of Robot Framework and its required components or say dependencies, we would be writing our basic test case to taste the flavor of our newly learned framework.

n

nDo follow us on  Fb,G+,Twitter, it encourages us to learn and share more.
n

Manual Test Case:-
n[TC-001]-Launching the browser and search and launch the “uftHelp” Application on Google.com
n
nTest Steps:-

n

    n

  • Launch Browser
  • n

  • Search Application On Google
  • n

  • Launch Application
  • n

n

Now let’s give structure to our above Test Case as per RobotFramework (RF).
n
nNote:- For running the test cases in chrome browser we need to chromedriver(downlaod this), For Linux OS place it under /usr/bin, windows use python/Scripts
n
nThings to Learn:-
nEverything in RF is given in the form of 4 tables which are called as “Setting”,”Variables”,”Test Cases” and “Keywords” table.You can learn about the detailed explanation on the RF official link, but here we can talk about them in layman terms.
n
nSettings: – It’s equivalent to global dependencies like if we talk about Java language it’s like import statement written before coding begins or like stdio.h header in C language. Idea is it contains the settings like link to resources file, variable file, external libraries (say Selenium Library for web application).
n
nVariables: – As the name indicates it contains our declaration of variables used in the flow of RF say like URL = www.google.com
n
nTest Cases:- It is where we are going to define our manual test case flow in business like language thus it easily understood by non technical team members.
n
nKeywords:- This is the place where real actions happens, meaning we give implementation to our above defined test case, like we say “Launch Browser” in our test cases table, than how RF know that its suppose to launch the browser. For that we need to define the meaning of “Launch Browser” in our keywords table. Generally we use pre-defined keywords from our external libraries but to enhance the testing capabilities we need to write our keywords definition using programming languages like python, java, .net.
n
nEnough of theory lets create our first executable test case. We would be using any simple editor say notepad, notepad++ to create our RF tables. In future we would implement the same using RIDE or other editors like sublime/pyCharm.
n
nSteps to follow:-
n
Step1:-

n

    n

  • Open the editor and create the 4 tables preceded with asterisk (*) symbol, this is internally used by RF to distinguish the tables as anything outside these tables is redundant for RF.
  • n

  • Put one space and then add the name of the table,Say *** Settings ***
  • n

n

*** Settings ***
*** Variables ***
*** Test Cases ***
*** Keywords ***

n


Note:- 

n

    n

  • For consistency purposes it is advisable to use 3, *** symbols in front of table name (as same would be created in RIDE).We can use * or ** or *** as all are same for RF. So don’t be confused lets have 3 *** symbols.
  • n

  • ‘*’ at the end are not required, but again for consistency purposed we are implementing them.
  • n

n

Step2:-
n
Copy the business steps of manual test case above and add to “Test Cases” table

n

*** Settings ***
*** Variables ***
*** Test Cases ***
[TC-001]-Launching the browser and search and launch the “uftHelp” Application on Google.com Launch Browser Search Application On Google Launch Application
*** Keywords ***

n


Note:-

n

    n

  • First row of the Test Cases table is used for Test Case name say for documentation.
  • n

n

Step3:-
nDefine the required variables in Variables table. Each variable is defined as ${variable name}

n

*** Settings ***
*** Variables ***
${APP} uftHelp
${URL} https://www.google.ca
${BROWSER} CHROME
*** Test Cases ***
[TC-001]-Launching the browser and search and launch the “uftHelp” Application on Google.com Launch Browser Search Application On Google Launch Application
*** Keywords ***

n

nStep4:-
nAdd the required libraries in “Settings” table, we would be using Selenium2Library as we would be working with browser application thus we need the keywords defined in this library.

n

*** Settings ***
Library Selenium2Library
*** Variables ***
${APP} uftHelp
${URL} https://www.google.ca
${BROWSER} CHROME
*** Test Cases ***
[TC-001]-Launching the browser and search and launch the “uftHelp” Application on Google.com
Launch Browser
Search Application On Google
Launch Application
*** Keywords ***

n


Step5:-
nMain step to define the meaning of Keywords used in the Test Cases table. We would utilize the predefined keywords of “Selenium2Library”.
n

n

*** Settings ***
Library Selenium2Library
*** Variables ***
${APP} uftHelp
${URL} https://www.google.ca
${BROWSER} CHROME
*** Test Cases ***
[TC-001]-Launching the browser and search and launch the 'uftHelp' Application on Google.com
Launch Browser
Search Application On Google
Launch Application
*** Keywords ***
Launch Browser
Open Browser ${URL} ${BROWSER}
Maximize Browser Window
Search Application On Google
Input Text id=lst-ib ${APP}
Click Button name=btnG
Launch Application
Wait Until Element Is Visible link=User-Friendly Techy-Help 20 Seconds
Click Element link=User-Friendly Techy-Help

n

nStep6:-
nSave the file with .robot extension (it is same as .txt).
n
nNote:- 

n

    n

  • RF supports .html format, TSV format, Plain text and reStructuredText formats. In our example we have used plain text format which is widely implemented across the industry.
  • n

  • For identifying the locator properties of the object above, you can use firebug, or simply use selenium -IDE, record a script and extract properties.
  • n

n

Step7:-
n
Run the file using “pybot” interpreter.
nWrite the command pybot testcaseName.robot on command prompt and we are ready with results.
n

nn

nNote:- 
nDon’t worry incase the code is not running in first go, there can be issues like spell mistakes or extra spaces, just copy the above code, save and execute it.
nFor any help and issues please share your comments below.
nLearn further How to execute the above test case in RIDE (IDE for robot framework)
n
Keep learning and keep sharing 🙂
n
nLearn RobotFramework
nLearn Selenium

Was this article helpful?
YesNo

Similar Posts