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


31 comments:

  1. Very useful article. Thank you

    ReplyDelete
  2. how could I enter the credential on the google home page ?

    ReplyDelete
  3. Thanks for the detailed steps. Do you have any similar document for testing REST Calls through RIDE?

    ReplyDelete
  4. Hi Jeffrey,
    No i don't have document for Rest calls. but i can give you an idea .
    As RIDE is used from UI perspective .For REST calls we can check their response from UI .
    e.g. On click of a button , hit the rest call , and validate its response , success or failure .
    Thanks!!!
    Let me know in case of any query .

    ReplyDelete
  5. Hi Gourav,
    What you didn't understand ?
    Let me know please .

    ReplyDelete
    Replies
    1. nidhi , can i use the id locator for select checkbox keyword ,
      ex | Select Checkbox | id=chk1|
      i tried something but it did not work , the test case could not locate the checbox with but it is the correct id of the checkbox

      Delete
    2. btw i was using phatomjs as the headless browser

      Delete
  6. Very usefull...Thanks for sharing :)

    ReplyDelete
  7. can u please help me with some links or page which has examples of using all or most of the selenium2 keywords , finding it little difficult to learn on own

    ReplyDelete
  8. Thanks for this tutorial. It was quite helpful.

    I tried your test but unfortunately it failed. Is this because I need a web driver for the firefox browser?

    ReplyDelete
  9. Can you help,as by doing step by step procedure my test get failed showing valueerror.

    ReplyDelete
  10. Hi How do you locate a menu bar?

    ReplyDelete
  11. How pass the argument variable value in RIDE UI like i used to pass in terminal. I want t pass the environment variable while running the test.
    robot --variable env:eng1 Tests/test_login.robotrobot

    ReplyDelete
  12. Can i know how to execute the commands using the Telnet library...

    ReplyDelete
  13. Hi Nidhi,

    I follow all steps but showing below message after running code, can you please check and provide me solution for this?
    --------------------------------------------------------
    Starting test: Test2.TC1
    20170416 00:53:01.120 : INFO : Opening browser 'chrome' to base url 'www.gamil.com'
    20170416 00:53:01.134 : FAIL : No browser is open
    20170416 00:53:01.135 : WARN : Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
    20170416 00:53:01.138 : FAIL :
    WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

    ReplyDelete
    Replies
    1. You need to install google driver from the provided link and copy the .exe file in C:\Python27\Scripts
      Then, you are ready to go. Selenium needs webdriver to deal with webpages.

      Delete
  14. Hi Nidhi,

    I'm getting list of test cases in suite using

    for testcase in suite.testcase_table:
    print testcase.name

    But I'm intrested in list of test cases in suite which are selected by user to run.
    Is there any way to get selected test cases for run in suite...?

    ReplyDelete
  15. Not able to identify objects with class I don't have IDs for my project

    ReplyDelete

  16. i was writing test suite on mobile automation. where i was checking streaming from one device to another device. i want to call to existing python code which is already written in python to go to some server and perform other action. i want to call my python script from ride IDE after certain steps. how can i call/execute my python script from the RIDE IDE.
    Could you please help me out ?

    regards,
    Sanjeevsuman88@gmail.com

    ReplyDelete
  17. Extra ordinary material with screenshot. Thanks you so much for all your efforts. Really good post to start with.

    It helped me a lot & I created my 1st TC in Ride. Yippee!!

    ReplyDelete
  18. Will be appreciated if you can provide the document for the same.

    ReplyDelete
  19. Hi,
    how to read the output one test case to another test case?

    ReplyDelete