Thursday, May 5, 2016

Selenium Robot Framework Python Test Case with RIDE

In this example, you will learn how to use RIDE in Selenium Robot Framework Python test automation. 

Test Case: authorized users are able to login Mahara Demo site. Here are test steps.


 1. Navigate to demo.mahara.org and verify that web page title "Home-Mahara" displays.
 2. Enter "student2" in the Username filed.
 3. Enter "Testing1" in the Password field.
 4. Click on the Login button
 5. Assert that Dashboard Title is "Dashboard - Mahara".
 Note: if the above username and password do not work, try registering one and 
 use your   own user account for testing because the demo user password may have 
 been changed by others.

Selenium Python Robot Framework Implementation

Step 1: open command window as administrator and launch RIDE with the command "ride.py".  RIDE window will display. Please remember that do not close the command window, or else RIDE will be closed. 
Step 2: under File menu, click on "New Project", enter project Name and select a Parent Directory as shown below. Please note that you need to create "C:\MaharaDemoTest" folder in advance.




Step 3: in the navigation window, Right Click and choose "New Directory" and enter "LoginModuleTest". 



Step 4: right click on the "LoginModuleTest" and select "New Suite". Enter "Login" in the suite name field. 
Step 5: click on the "Login" test suite and enter the following keywords and test case in the "Text Edit" window. 


*** Settings ***
Library           Selenium2Library

*** Variables ***
${Username}       student2
${Password}       Testing1
${Browser}        Firefox
${SiteUrl}        http://demo.mahara.org
${DashboardTitle}    Dashboard - Mahara
${Delay}          5s

*** Test Cases ***
LoginTest
    Open Browser to the Login Page
    Enter User Name
    Enter Password
    Click Login
    sleep    ${Delay}
    Assert Dashboard Title
    [Teardown]    Close Browser

*** Keywords ***
Open Browser to the Login Page
    open browser    ${SiteUrl}    ${Browser}
    Maximize Browser Window

Enter User Name
    Input Text    login_login_username    ${Username}

Enter Password
    Input Text    login_login_password    ${Password}

Click Login
    click button    login_submit

Assert Dashboard Title
    Title Should be    ${DashboardTitle}
 
 
 

After you enter all the above information, the screen looks like this below.


Step 6: click on the "Run" tab and execute the test case "LoginTest". 




Step 7: check the log file "C:\MaharaDemoTest\LoginModuleTest\TestResult\log-20140601-232305.html" and result file "C:\MaharaDemoTest\LoginModuleTest\TestResult\report-20140601-232305.html". The result indicates that test passed. If test fails, the background will be Red. Click on the file links to see the result file in html format.

 

Wednesday, May 4, 2016

Selenium Robot Framework Installation with Python


To use Robot Framework with Python, you need to install Python, robot framework, Selenium2Library and other supporting libraries. 

Step 1: Install Python 2.7 version
        Before installing Robot Framework, you need to install Python 2.5 or later. Robot Framework has not been updated to work with Python 3 or above, so you should certainly install Python 2.7 version. Visit the link to download and install Python 2.7 version. After installing Python 2.7, add your python installation to your system environment path. 

on Windows, add "c:\Python27\;c:\Python27\Scripts\;" to your path. On Windows vista or Windows 7 environment, it is recommended to install Python to all users, and to run the installation as an administrator. After installing, you can confirm python installation with the command below. 

Step 2: Verify Python 2.7 version

 python --version

 command result will be

 Python 2.7.6

 Step 3: install robot framework with pip command. When you install Python, pip application will be installed automatically. If you are familiar with installing Python packages and have pip available, just run the following command.

 pip install robotframework

 Step 4: Verify robot framework installation
After a successful installation with Python, you should be able to  execute the following commands on the command prompt to verify the installation. 

pybot --version

 Command Result

 Robot Framework 2.8.4 (Python 2.7.6 on win32)

Step 5: Install Selenium2Library
You can install robotframework-selenium2library by downloading the packaged executable file or using the python pip application. Here is the link to download. Use the following command to install robotframework-selenium2library with pip. 

pip install robotframework-selenium2library

 Step 6: Install Selenium Library
Since Selenium2Library has some dependencies for selenium library, you need to install selenium library. The easy way of installing selenium library is to use pip. You can use the following command to install selenium.

 pip install -U selenium

 Step 7:  Install the Selenium robot framework IDE - RIDE
RIDE is a light-weight and intuitive editor for Robot Framework test case files. Since RIDE uses wxpython 2.8, you need to install the package as well. Visit the link for details. RIDE does not yet support Python 3. On OS X RIDE requires 32-bit Python version. 

To install wxpython 2.8 or later version, visit the wxpython.org download page and download the version depending on your OS. Please note that the package has 32 bit and 64 bit, so you need to install the corresponding package depending on your operating system version. 

To install RIDE, you can use pip with the following command. 

 pip install robotframework-ride

 Step 8: Verify RIDE Installation
After a successful installation, RIDE can be started from the command line by running

 ride.py 

 Alternatively you can specify a file or directory to open as an argument like ride.py path/to/tests. Starting from RIDE 0.54, you can also create a desktop shortcut during installation on Windows.

On Windows running ride.py requires having <PythonInstallationDir>\Scripts on PATH. If pybot command to run tests with Robot Framework works you should be fine. If it does not, see Robot Framework installation instructions for more information about setting PATH. When RIDE starts, you will see the UI as shown below. This screenshot has a MaharaDemoTest created by RIDE Program.



Selenium Robot Framework Introduction

Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD). It has easy-to-use tabular test data syntax and it utilizes the keyword-driven testing approach. Its testing capabilities can be extended by test libraries implemented either with Python or Java, and users can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases. (Source: http://robotframework.org/).
Robot framework project is hosted on Google code, where users can find technical documentation and source code. Robot framework Python language bindings are hosted at Pypi
Robot framework has following features:
  • Framework architecture is clear. Robot Framework has a modular architecture that can be extended with bundled and self-made test libraries.
  • Framework is easy. When test execution is started, the framework first parses the test data, and then it utilizes keywords provided by the test libraries to interact with the system under test. 
  • Framework test result is user friendly. Test execution is started from the command line. As a result, users get report and log in HTML format as well as XML output. 
  • Framework is modular as listed below: 
  1. Test Date (test data is defined in files using robot framework syntax)
  2. Robot Framework ( framework application)
  3. Test Libraries (robot framework has common libraries , see the link
  4. System Under Test (this is the test application) 
Selenium Robot Framework is using Selenium2Library for Selenium 2 Web Driver or SeleniumLibrary for Selenium Remote Controller API with robot framework. For details, visit the link
Robot Framework and Selenium libraries are open source, so users can use it without any additional cost. 
Selenium Master will guide you how to use Selenium2Library with robot framework to complete test automation of your application under test.