Friday 28 December 2012

How to write test cases in Ride


This section includes how to write test cases in Ride :-

The Robot Framework IDE (RIDE) is the integrated development environment to implement automated tests and it is a generic test automation framework for acceptance testing.

Pre-requisite :- Ride should be installed.

To install ride steps are :-
1.install python in ur disk drive.(python-2.7.1)
2.Set these two env variables 

PYTHONHOME = C:\Python27
PYTHONPATH = C:\Python27\Lib;C:\Python27\Scripts;C:\Python27\Lib\site-packages;C:\Python27\Lib\site-packages\Selenium2Library;C:\Python27\Lib\site-packages\robotide\;C:\Python27\Lib\site-packages\robot\;C:\Python27\Lib\site-packages\wx-2.8-msw-unicode;C:\Python27\Lib\site-packages\SampleLibrary

and also Add this to path
path =;%PYTHONHOME%;%PYTHONHOME%\Scripts


3. install setup tools (setuptools-0.6c11.win32-py2.7)
4. easy_install robotframework (robotframework-ride-0.49.win32)
5. easy_install robotframework-selenium2library(robotframework-seleniumlibrary-2.7.win32.exe)
6. install wxPython2.8-win64-unicode-2.8.12.1-py27(wxPython2.8-win32-unicode-2.8.11.0-py27)
7. install ride (robotide-0.31.win32.exe)
8. install pywin module(pywin32-214.win32-py2.7)

Verify the Installation 
Open new command prompt and type ‘pybot --version’ and output like  Robot Framework 2.7.5

Now let start with writing test cases :
Example :- 
If a user want to login :-
step 1:- Given url is opened.
step 2:- when user enter his credentials. 
step 3 :- and when user click on login 
step 4 :-Then he should navigate to home page.
In this example user name and password are the mandotary, then he will be able to login.



Getting started with Ride :-
1. Make a New project in ride  as follow say Test .it should be directory.

2.Add test suite as a file say test_suitte as follow.



Write the name of suite in popup as shown.



2. Add library selenium2 in test_suitte file by clicking on library as shown in bold in following image :- 





Write name of library in popup Selenium2Library as shown.Library will be added



3. Right click on that file and click new test case say TC1.



give the name of test case in popup as :-


Test case will be added.


Generic fields for this testcase – for example documentation and tagging – can then be defined in the upper part of the editor. In the lower part the testcase is written in tabular format as a sequence of corresponding keyword calls. Thereby the keyword is written in the first column and all possible parameters in the other columns as shown in below figure.

Keywords are predefined and user can make his keywords with predefined keywords.

e.g. if a user want to login then following steps are necessary :-

1. Given url is opened.
2.When user enter credentials.
3.When click on login button.
4.Then home page should appear.

and all steps I have taken as my keywords.





Now next step is to define all user defined keywords.
Given url is opened :- 

1. right click on test file and click on add new user keyword,named - Given url is opened.



Write the name of keyword Given url is opened ,it will be added.

2.click on Given url is opened resource , in the lower part there will be tabular format.




-To open that url,add predefined keywords in table and corresponding values
-as above "open browser" is predefined keyword in selenium library.
-Predefined keywords can be find by pressing f5 . Window will be open as :-
                  
-Open browser has 2 parameters , url and browser in which url will be opened.
- here I defined url -www.gmail.com and browser - chrome

Similarly for another user defined keywords follow the same process right click on test_suitte file and add.
When user enter his credentials:-




Next step define when user enter credentials with the help of predefined keywords.

-input text and input password are predefined keywords
Input text :- it has 2 arguments .one is locator and another is testdata that we'll enter
Input password:- it has 2 arguments .one is locator and another is testdata that we'll enter

To avoid  testdata in hard code we can use list and scalar variable as follow :-
List varaible :- The varaiables that can have multiple values.
Scalar variables :- The variables that can have only single values



Click on new list variable and define variable on popup as below.

Simlarly to avoid hardcode password define list variable.


Now we can use these list variable in "When user enter his credentialsas follow :-




-As shown in above figure i have user @{txt_username}[0] in place of user1. Here [0] means first index of @{txt_username} list variable.

when clicks on login button :-

Similarly define this keyword as other user defined keyword as follow:-



After adding the keyword define keword with the help of predefined keyword as follow.



- click button is predefined keyword. 
- id = login is locator of login button.

Then home page  should appear :-



Now follow the same process that define the keyword with predefined keywords .
Here I have used element should be visible and argument is its id (id=view_profile).If the element of that id is present then home page is opened





Now to run test case , checked that test case and click on run button as follow :-



This is the process to write test cases in Ride.

Now Enjoy with Ride :-)