Best Practices:- Working with Robot Framework

It is never too late to become smarter or better…Never stop learning.


We started with installation of Robot framework, followed with first test case and further implementing the same in RIDE.Today we would focus on some of the best practices while working with Robot Framework(RF).

Always remember if you are bored, it means that you are doing it wrong. Don’t be bored of learning..keep learning and sharing.

Do follow us to learn and share:- 
Best Practices in Robot Framework(RF):-

Settings:-
  • Implement suite setup and suite tear down for common setup like launching application, closing application. We can create an initialization file for it.


Variables:-
  • Use variables instead of direct hard coding of values and put variables inside a .variable file for easy maintenance.
  • Avoid variable assignment in Test cases; try to create test cases in domain specific language (thus to  avoid  programming concepts, like  reduce the approach if taking return from a test step and passing it in next test step.)


Test Cases:-
  • Avoid test case dependencies. Treat each test case as an independent identity.
  • Try to minimize the test steps in a test case and should not exceed the level of 10 steps.
  • Use Tags to segregate test cases like smoke or regression.


Keywords:-
  • Keyword name should describe what need to be done rather than how it needs to be done
  • Avoid complex logic inside this like for loops; rather utilize the external resources file to handle the programming part.
  • Avoid sleep, rather implement utilize inbuilt keywords like wait until page contains (selenium2Library).
  • Better not to have documentation all if it is not required. Like if test case or keyword name is self describing than why to go for documentation.
Practical implementation:-
Note:– We used sublime editor for creating our code structure.
Code structure :- 
Code structure Robot Framework

TestCase:- is name of our testSuite.It contains 2 test cases as per below example.
lib:- It contains the App and Common .txt files. App.txt contains the keywords specific to application. Common.txt contains the keywords for setup and tear down of application.
Resources:-It contains the page specific keywords.
Variables:- It contains our variable definition(we have taken python file for the same)

Code structure when opened in Sublime editor.

Extract the code to run the TestCase.robot file, we can run the same in RIDE also but we need to establish the link for external resources used.
Note:- When we would try to open the code in RIDE, we need to manually browse the path for External Resources.
On right side of RIDE -> Under Add Import ->Resource 
Same need to be done for Variables file.(i.e our GlobalVar.py file)

Adding resources to RIDE
After adding the resources our solution explorer of RIDE would look as below.

Opened test case in RIDE
Now we can run the test case in RIDE by pressing F8.

Hope you enjoyed our best practices in RF tutorial.

Implement Robot Framework using RIDE (Part-2)

In our part-1 we learned how to work with  existing test case written as .robot/.txt inside RIDE.

Here we would learn to implement the robot framework functionality in RIDE itself.Further we would move towards best approach in RF.
Do follow us on  Fb,G+,Twitter, it encourages us to learn and share more.

Requirement:- Enhance our existing test case using RIDE?

Step1:-
Adding new Test Case to existing functionality.

Right click Test Suite > New Test Case > Name ([TC-002]-Search Robot onthe opened Application).

Adding new test case in RIDE
Test case added in RIDE
Note:- We could have done the same using “Text Edit” tab.
Step2:-
Adding Test Steps for the newly created test case.
Click on the Test case Name (TC-002) and on right side under “Edit” tab, enter the test steps.

Test Step 1:- Search The Given Topic On Home Page Of Application
Test Step 2:– Click On The First Searched Link

Add test step in RIDE


Note:- Added Test Steps would be coming in black font, they would turn blue one’s RIDE is able to link them to the corresponding keywords.

Step3:-
Adding the Keywords for the created steps (Meaning using the Selenium2Library keywords to give meaning to the created test steps).

Right click the Test suite > New User Keyword > Name
Add user keywords in RIDE
Newly added keywords in RIDE

Select the newly created keyword -> Under “Edit” tab ->utilize the selenium2Library keywords to perform the operation .
Adding keywords in RIDE


Note:- 
Now if we click on the “Test Case”([TC-002]) we can see the color change as blue.

Link between test case and keywords
Incase we have already included the “Selenium2Library” in Setting table, we can utilize the intellisense available in RIDE to search for the required keyword from the selenium library.

Selenium2Library intellisense in RIDE


Step4:-
Here we would define “$TOPIC” variable used above in the keywords.
We can do the same from the explorer window but let’s try from the “Add Scalar” button.

Click on Test Suite Name -> on the right side click on “Add Scalar” button > Name/value/Comment
Creating variables in RIDE

Step5:-
 Save and run the test case

Result logs in RIDE (PASS)

CODE:-

*** Settings ***
Library Selenium2Library

*** Variables ***
${APP} uftHelp
${URL} https://www.google.ca
${BROWSER} CHROME
${TOPIC} Robot Framework # Variable containing the Topic to be searched on Application

*** 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

[TC-002]-Search Robot onthe opened Application
Search The Given Topic On Home Page Of Application
Click On The First Searched Link

*** 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

Search The Given Topic On Home Page Of Application
Input Text id=gsc-i-id1 ${TOPIC}
Click Element css=input.gsc-search-button.gsc-search-button-v2

Click On The First Searched Link
Wait Until Element Is Visible xpath=.//*[@id='___gcse_0']/div/div/div[1]/div[6]/div[2]/div[1]/div/div[2]/div[1]/div[1]/div/a 20 s
Click Element xpath=.//*[@id='___gcse_0']/div/div/div[1]/div[6]/div[2]/div[1]/div/div[2]/div[1]/div[1]/div/a
Hope you learned the basics of RIDE and enjoyed our tutorial. Keep learning 🙂

Implement Robot Framework using RIDE (Part-1)

Starting with installation prerequisite of robotframework(RF), we learned how to create our first test case using RF. Today we would enhance the same test case and implement it in RIDE. (IDE for robot framework).

Requirement:-Creating our first test case in RIDE?

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

Learn RIDE


Pre-requisites:- We would use the existing code in our firstexample which can be saved in .robot or .txt extension.

Step1:-
Launch RIDE:
We can launch it by writing the command ride.py on command prompt.

Or

Incase we have installed it using windors .exe installer it would gave use option to create  desktop shortcut to launch it.

Or 

But we did was simply created a .bat file with the ”ride.py”written inside it, now we can launch it by clicking the .bat icon.
bat file to launch RIDE

Step2:-
Opening our test case (like .htm/.html/.tsv/ .txt/.robot files) in RIDE.

Click on Open Test Suites (ctrl+o) and browse for file to open

Open test case in RIDE

Note: – You can save the code from step-5 in our first testcase example and save it with .robot or .txt format and open it in RIDE.

Step3:- 
Understanding the structure of the opened Test Case.
We can see that opened test case contains Variables, TestCases, Keywords and also settings table(it is on the right of the explorer window).

Explorer window in RIDE


Further if we open the “Text Edit” tab, it would contain our test case in raw form.

Text Editor in RIDE

Note:- Incase of error in the file, it would not open up in RIDE. Firstly we need to rectify the error.Like we can run the file on command prompt and observe the failure reasons to correct the file and than try opening in RIDE. 

File opening error in RIDE

Step4:-
To run the test case
We need to open the “Run” tab( or press F8, shortcut to run test case) -> Select the Test Runner(our case it is pybot) -> Click on start.

Run test case in RIDE

Step5:- 
After successful execution result logs would be shown.

Test Log in RIDE


Writing first test Case using Robot Framework?

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.

Learn RobotFramework


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


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

Test Steps:-

  • Launch Browser
  • Search Application On Google
  • Launch Application

Now let’s give structure to our above Test Case as per RobotFramework (RF).

Note:- 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

Things to Learn:-
Everything 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.

Settings: – 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).

Variables: – As the name indicates it contains our declaration of variables used in the flow of RF say like URL = www.google.com

Test 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.

Keywords:- 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.

Enough 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.

Steps to follow:-

Step1:-

  • 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.
  • Put one space and then add the name of the table,Say *** Settings ***

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


Note:- 

  • 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.
  • ‘*’ at the end are not required, but again for consistency purposed we are implementing them.

Step2:-

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

*** 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 ***


Note:-

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

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

*** 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 ***


Step4:-
Add 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.

*** 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 ***


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

*** 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


Step6:-
Save the file with .robot extension (it is same as .txt).

Note:- 

  • 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.
  • For identifying the locator properties of the object above, you can use firebug, or simply use selenium -IDE, record a script and extract properties.

Step7:-

Run the file using “pybot” interpreter.
Write the command pybot testcaseName.robot on command prompt and we are ready with results.

Running robotFramework Test


Note:- 
Don’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.
For any help and issues please share your comments below.
Learn further How to execute the above test case in RIDE (IDE for robot framework)

Keep learning and keep sharing 🙂

Learn RobotFramework
Learn Selenium

Setup for Robot Framework Automation

World changes constantly..
We change each day..
Once U find itself U have to begin again.

Today we are changing and learning Robot Framework and thought of sharing the same with others co-learners, please add your expertise as comments to this post. We have already shared our posts on established automation tools like UFT and Selenium.

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

Lets start with the installation of Robot Framework(RF), followed with our first test case with RF.

Prerequisites :-
1.Python:- This is the language on which the architecture of RF is based on.Most updated version of RF(2.9), supports Python-2.7, still contributing team is working on the support for Python -3.

Download Link:- Python  – Click on Downloads Menu – Download the latest version of python 2.7.* 

Note:-

  • On most UNIX-like systems such as Linux and OS X you have Python installed by default
  • Latest Python Windows installers allow setting PATH as part of the installation. This is disabled by default, but Add python.exe to Path can be enabled on the Customize Python screen.
  • Python Installation
  • Now if we check (Control PanelSystem and SecuritySystemAdvance system settingsEnvironment VariablesSystem variables path) we can see the value added in the starting itself C:Python27;C:Python27Scripts;
  • Where our Installation path  = C:Python27 and Python scripts(where our Robot framework would be installed)= C:Python27Scripts
  • Enviornment variables for python
  • We haven’t discussed about installation of Jython and IronPython, these are interpreters we need incase we are coding in Java and .net technologies.


How to check python is installed on system?
Easiest approach is open the command prompt and execute the command “python –version”

python version using cmd prompt


2.Package Manger:-We can use any package manager like pip, easy_intstall for installing robot-framework.We would be using pip as it is coming bundled with latest version of python (starting 2.7.9) , else we need to install pip first and then utilize it.
So don’t worry about this now.

Installing Robot Framework(RF):-
Using pip command:-
# Install the latest version
pip install robotframework
Install RobotFramework
It would take fractions of seconds to install the setup.The above command would install only the latest stable release in case we want a particular version like old or beta release we can use it like:-

# Install 2.9 beta 1
pip install robotframework==2.9b1

#For upgrade we can use the command
pip install –upgrade robotframework

Using Windows installer:-
Installers are available on PyPI, select the one as per the OS(32 or 64 bit)
1.Extract the .tar file using (say 7-zip)
2.Open the command window inthe installer package and type “setup.py install

Installing Robot Framework
Note:-We can install RF by using “Source from GitHub”, “Using JAR in Maven Central” or “Manual” approach but we are not discussing this as above techniques are frequently used.

How to verify the installation of Robot Framework?
To verify, we need to use the Runner script, based on the interpreter used. Meaning a technique to trigger RF based on each type of interpreter. 

In our example we have used Python interpreter.
Simply type the command pybot –version in the command prompt and we are done.

Checking version of Robot Framework
Note:- Each type of interpreter have their own Runner scripts:-

Interpreters for Robot Framework

Where we can locate the Robot Framework code?

All the robot framework code after installation can be found inside C:Python27Libsite-packagesrobot


How to install “Selenium2Library”?

We need this library to work with web applications.

Execute the command pip install robotframework-selenium2library and we are done with the installation.

Installing SeleniumLibrary2



How to verify the installation of Selenium2Library:-
Open cmd prompt type python
type import Selenium2Library
if we are able to see >> symbol means we are succsessfull.

Check installation of Selenium2Library



How to check the Selenium Keywords that we can use:-
We can utilize the online resource for Selenium Library.
Further we can play with python code of these keywords.
Path of Selenium Keywords on local system relative to Python installation = Python27Libsite-packagesSelenium2Librarykeywords 
Open any of the .py file and check the code.

RIDE:-

We can use this IDE for writing our robot framework.As a beginner it is easy to grasp this IDE, further we can implement other IDE’s like pyCharm also.

Preconditons:- We need python, robotframework and wxPython already installed to launch RIDE. Thus we still need to install wxPython as we already done with first 2 components.

wxPython:- RIDE’s GUI is implemented using wxPython toolkit.

Install wxPython:- 
Select the required .exe as per the system requirement.

Download link:- wxPython

installing wxPython

For Unix OS: – sudo apt install python-wxgtk2.8

 Installing RIDE:-

We would install it using the following pip command.
pip install robotframework-ride

Pip command to install RIDE


Note:-


  • Using the pip command we are installing the latest stable release.Incase we want to check the beta/alpha release we can follow the RIDE github page.
  • To create the desktop shortcut on windows we need to use the .exe of the installer, that we can get again at the release link.



Launching RIDE :- type the command ride.py in command prompt and we are done


RIDE IDE

Writing our first test case in RF?