Showing posts with label robotframework. Show all posts
Showing posts with label robotframework. Show all posts

Monday, December 30, 2013

Robot Framework Test Automation Book

Found a book for Robot framework and eagerly read through all the pages. It covers majority of the features of Robot Framework.

Book Title: Robot Framework Test Automation
Author: Sumit Bisht
ISBN: 9781783283033
Book Page @ Packtpub


Robot framework is an advanced test automation framework. Primarily it is tool independent and OS independent. This book is very helpful for the novice.

Sumit has explained debugging methods, parametrized re-usable tests and Results reporting with different options in better way. Must read for the professionals to get to know major capabilities of Robot Framework.

Monday, April 16, 2012

Robotframework with IronPython (CSharp)

RobotFramework Installation is a tricky task. Also installing for IronPython, is bit risky one. You may end up doing installation 3-4 times.

RobotFramework DotNet Support
How To: Use CSharp with Robot Framework

Robot Framework has given above page for DotNetSupport and Below I have given the instructions for Windows OS..

Tools installation
All RobotFramework related software can be the latest. The other software should be as the same version.

  1. Install Python (python-2.6.4.msi). Set installation directory as C:\Python26
  2. Install Robot Framework (robotframework-2.6win32.exe)
  3. Install Robot Selenium Library (robotframework-seleniumlibrary-2.7.win32.exe)
  4. Install Python Widgets (wxPython2.8-win32-unicode-2.8.11.0-py26.exe)
  5. Install Robot IDE (robotide-0.31.win32.exe)
  6. Install Python Win32 module (pywin32-214.win32-py2.6.exe)
  7. Install IronPython (IronPython_262.msi). Set installation directory as C:\IronPython
  8. Ensure .NET framework 4 should be available in current system

Environment variables Configuration
To execute RIDE and Pybot, environment variables should set properly.
  1. Create a system level environment variable & value as --> PYTHONHOME=C:\Python26
  2. Create a system level environment variable & value as --> PYTHONPATH=C:\Python26\Lib;C:\Python26\Scripts;C:\Python26\Lib\site-packages;C:\Python26\Lib\site-packages\SeleniumLibrary;C:\Python26\Lib\site-packages\robotide\;C:\Python26\Lib\site-packages\robot\;C:\Python26\Lib\site-packages\wx-2.8-msw-unicode;
  3. Also add to PATH variable --> % PYTHONHOME%;% PYTHONHOME%\Scripts;

For IronPython, environment variables should set properly.
  1. Create a system level environment variable & value as --> IRONPYTHONHOME=C:\IronPython
  2. Create a system level environment variable & value as --> IRONPYTHONPATH=%IRONPYTHONHOME%\Lib;%IRONPYTHONHOME%\Scripts;%IRONPYTHONHOME%\Lib\site-packages;%IRONPYTHONHOME%\Lib\site-packages\SeleniumLibrary;%IRONPYTHONHOME%\Lib\site-packages\robotide\;%IRONPYTHONHOME%\Lib\site-packages\robot;

Preparing ipybot.bat
To run with IronPython, you need to create a batch script. Copy below contents into a text editor and save it as ipybot.bat.
@echo off :: :: ipybot.bat - for IronPython :: IRONPYTHONHOME - Env variable set for IronPython home directory :: PYTHONHOME - Env variable set for CPython home directory :: :: Copyright 2008-2010 Nokia Siemens Networks Oyj :: :: Licensed under the Apache License, Version 2.0 (the "License"); :: you may not use this file except in compliance with the License. :: You may obtain a copy of the License at :: :: http://www.apache.org/licenses/LICENSE-2.0 :: :: Unless required by applicable law or agreed to in writing, software :: distributed under the License is distributed on an "AS IS" BASIS, :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. :: See the License for the specific language governing permissions and :: limitations under the License. :: :: pybot.bat -- Python start up script for Robot Framework on Windows :: :: Python executable to use. set pythonExec="%IRONPYTHONHOME%\ipy.exe" :: Path to robot\runner.py :: set runner="%PYTHONHOME%\Lib\site-packages\robot\runner.py" set runner="%IRONPYTHONHOME%\Lib\site-packages\robot\runner.py" :: Run Robot on Python interpreter %pythonExec% %runner% %*

Changes for Robot Framework
RobotFramework is developed by CPython. To support IronPython, we need to do few changes.
  1. 1. Copy folders %PYTHONHOME%\Lib\site-packages\SeleniumLibrary;%PYTHONHOME%\Lib\site-packages\robotide\;%PYTHONHOME%\Lib\site-packages\robot\;
    To
    %IRONPYTHONHOME%\Lib\site-packages
  2. Need to copy few files from Python installation. Few files should be downloaded over internet and copy into ironpython installation. Few files may not be required to copy for latest Robot framework. Create a following batch file with required files and execute the script to copy all of them.
:: Python Home directory. set pythonIns=%PYTHONHOME% set ironpythonIns=%IRONPYTHONHOME% :: Files to be copied :: Copy ipybot.bat from current directory to IronPython installed dir copy ipybot.bat "%ironpythonIns%\" /y :: Copy expatbuilder.py from under Python\Lib\xml\dom to IronPython\Lib\xml\dom copy "%pythonIns%\Lib\xml\dom\expatbuilder.py" "%ironpythonIns%\Lib\xml\dom\" /y :: Copy expat.py from under Python\Lib\xml\parsers to IronPython\Lib\xml\parsers copy "%pythonIns%\Lib\xml\parsers\expat.py" "%ironpythonIns%\Lib\xml\parsers\" /y :: copy fepy/trunk/lib/pyexpat.py from IronPython\Lib copy pyexpat.py "%ironpythonIns%\Lib\" /y :: copy fepy/trunk/lib/unicodedata.py from IronPython\Lib copy unicodedata.py "%ironpythonIns%\Lib\" /y :: Copy ElementTreePath.py from under Python\Lib\xml\etree to IronPython\Lib\xml\parsers copy "%pythonIns%\Lib\xml\etree\ElementTree.py" "%ironpythonIns%\Lib\xml\etree\" /y :: Copy a dummy signal.py from current dir



Steps for 64 Bit OS To enable Robot Framework for 64 bit OS, you should install 64 bit python setup in same directory. Also the command prompt should be invoked through setting ‘Run as a Administrator’ if OS is Vista or Windows 7 version.


Verify the Installation
Open new command prompt and type ‘pybot --version’ and output like --> Robot Framework 2.6.0 (Python 2.6.4 on win32) In Command prompt, type ‘ipy’ and output like ---> IronPython 2.6.2 (2.6.10920.0) on .NET 4.0.30319.1

Sunday, March 25, 2012

Robot Framework - TypeKey Library

Implemented a library to simulate keyboard events. It can be used for upload and download operations along with Selenium.

TypeKeyLib - Library

# Author: Palani Selvam
#
# Purpose: Test library to simulate keyboard actions.
#

import time
import sys,os
import win32api, win32con
from win32com.client import Dispatch

from robot.errors import DataError
from robot import utils

__version__ = '0.1' # Developed by Palani

class TypeKeyLib:
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = __version__

def __init__(self):
""" TypeKeyLib Library can be imported with optional arguments
"""
self._result='Init'
# To do

def TypeKeys(self,sKey):
""" TypeKeys - used to simulate keyboard keys. Parameter sKey can be STRING or LIST
For Key representation, see at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthsendkeys.asp

"""
try:
self._result='TypeKeys method'
shell=Dispatch("WScript.Shell")

stype = type(sKey).__name__
#print 'Given type: ', stype

if (stype == 'list'):
# Execute multiple times
for key1 in sKey:
shell.SendKeys(key1)
time.sleep (0.5)
else:
# Execute only one time
shell.SendKeys (sKey)
time.sleep(1)
#shell=Nothing
self._result='pass'
except:
self._result='fail'
print '*INFO* Exception occurs: ', sys.exc_type , ":", sys.exc_value
raise
finally:
self._result+= ' done'
return self._result

def TypeKeys_Space(self):
""" TypeKeys_Space - used to simulate SPACE.
"""
self.TypeKeys (" ")

NOTE: It will work only with Windows OS...

Sunday, March 18, 2012

Robot Framework - Database Libraries

Robot framework already has two database libraries and both are implemented in different lanugauges.
Database Library - Java
Database Library - Python

I have developed two simple database libraries. One is for generic ODBC interface and another one is especially for Oracle. The second one can be used as thin client.
Database Library - ODBC interface

#
# Author: Palani Selvam
#
# NOTE: It is supported all type of Databases, which are having support to ODBC
# For ex, DB2, ORACLE, MS SQL SERVER, Sybase.
#
import pyodbc as DB
from robot.errors import DataError
from robot import utils

__version__ = '0.1' # Developed by Palani - 20101022

class DBLibrary:

ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = __version__

def __init__(self):
"""DBLibrary Library can be imported with optional arguments.

"""
self._connection = None
self._default_log_level = 'INFO'
self._bexception = False
#self._prompt = prompt

def make_connection(self, sDsn, sUid=None, sPwd=None):
""" make_connection method is used to create the connection object.
sDsn - DataSource Name
sUid - User Id to access the database
sPwd - Password to access the database
"""
sConn = None
try:
sConn = DB.connect(dsn=sDsn, uid=sUid, pwd=sPwd )

except Exception:
self._bexception = True
print 'Connection for database has failed', Exception
raise
finally:
self._connection = sConn

def execute_sql (self,sSql=None,iRows=None):
""" execute_sql method is used to execute the sql query to the given connection object.
sSql - Query to access the database
iRows - No of rows to be returned.
"""
sOut = None
sCursor = None
sConn = self._connection

if (sConn == None) :
return sOut
else:
try:
sCursor = sConn.cursor()
sCursor.execute(sSql )
# curs.execute("SELECT * FROM EmpTable WHERE SCOPE=3 ")
if (iRows <> None) :
iRows = int (iRows)
sOut = sCursor.fetchmany (iRows)
else :
sOut = sCursor.fetchall ()

except Exception:
self._bexception = True
print 'Query execution is failed. ', Exception
raise
finally:
if (sCursor <> None):
sCursor.close ()
return sOut

def execute_for_one_row (self,sSql=None):
""" execute_for_one_row method is used to execute the sql query and returns only first row.
sSql - Query to access the database
"""
sOut = None
sCursor = None
sConn = self._connection

if (sConn == None) :
return sOut
else:
try:
sCursor = sConn.cursor()
sCursor.execute(sSql )
rows = sCursor.fetchone ()
for sOut in rows:
break

except Exception:
self._bexception = True
print 'Query execution is failed. ', Exception
raise
finally:
if (sCursor <> None):
sCursor.close ()
return sOut

def disconnect_from_database (self,sConn=None):
""" disconnect_from_database method is used to disconnect from the given connection object.
sConn - Connected Object, which is got through make_connection method.
"""
if (sConn <> None):
sConn.close ()
else:
self._connection.close ()

Database Library - Oracle
#
# Author: Palani Selvam
#
#
# NOTE: It is supported only ORACLE Databases
# DSN is not required.
#
import cx_Oracle as DB
from robot.errors import DataError
from robot import utils

__version__ = '0.1' # Developed by Palani

class ORADBLibrary:

ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = __version__

def __init__(self):
"""DBLibrary Library can be imported with optional arguments.

"""
self._connection = None
self._default_log_level = 'INFO'
self._bexception = False
#self._prompt = prompt

def ora_make_connection(self, sConnString):
""" make_connection method is used to create the connection object.
sConnString - Connection String

Example:
'sqluser/welcome@127.0.0.1/orcl'
"""
sConn = None
try:
sConn = DB.connect(sConnString )

except Exception:
self._bexception = True
print 'Connection for database has failed', Exception, sConnString
raise
finally:
self._connection = sConn

def ora_execute_sql (self,sSql=None,iRows=None):
""" execute_sql method is used to execute the sql query to the given connection object.
sSql - Query to access the database
iRows - No of rows to be returned.
"""
sOut = None
sCursor = None
sConn = self._connection

if (sConn == None) :
return sOut
else:
try:
sCursor = sConn.cursor()
sCursor.execute(sSql )
# curs.execute("SELECT * FROM EMP_Table WHERE SCOPE=3 ")
if (iRows <> None) :
iRows = int (iRows)
sOut = sCursor.fetchmany (iRows)
else :
sOut = sCursor.fetchall ()

except Exception:
self._bexception = True
print 'Query execution is failed. ', Exception
raise
finally:
if (sCursor <> None):
sCursor.close ()
return sOut

def ora_execute_for_one_row (self,sSql=None):
""" execute_for_one_row method is used to execute the sql query and returns only first row.
sSql - Query to access the database
"""
sOut = None
sCursor = None
sConn = self._connection

if (sConn == None) :
return sOut
else:
try:
sCursor = sConn.cursor()
sCursor.execute(sSql )
rows = sCursor.fetchone ()
for sOut in rows:
break

except Exception:
self._bexception = True
print 'Query execution is failed. ', Exception
raise
finally:
if (sCursor <> None):
sCursor.close ()
return sOut

def ora_disconnect_from_database (self,sConn=None):
""" disconnect_from_database method is used to disconnect from the given connection object.
sConn - Connected Object, which is got through make_connection method.
"""
if (sConn <> None):
sConn.close ()
else:
self._connection.close ()
Like above, we can extend Robot Framework easily...

Sunday, February 12, 2012

RobotFramework Standards

RobotFramework team has given guidelines --> HowToWriteGoodTestCasesWithExamples. Similar to coding standards, Automation team should use certain guidelines for Keyword-Driven framework also. It would be more useful to functional team as well as other teams.

Test Suite / Script

  • Test Script names should be less than 20 characters and file type should be HTML.
  • It should be easily readable and self-explanatory.
  • Remember that suite names are created automatically from file/directory names. Extensions are stripped, underscores are converted to spaces and, if name is all lower case, words are capitalized. For example login_tests.html -> Login Tests and DHCP_and_DNS -> DHCP and DNS.
  • Documentation should be updated with purpose of the script and pre-conditions.
  • Proper keywords should be given for Suite Setup, Suite Teardown, Test Setup and Test Teardown.
  • Should not have too many tests (max 50) in one suite unless they are data-driven.

TestCases / Tests
  • Test case names should be less than 40 characters and file type should be HTML.
  • Test case Name should be in camel case (In a word, First letter is capital and remaining letters are in small).
  • It should be easily readable and self explanatory.
  • Documentation should be updated with manual test case steps, notes and pre-conditions.
  • Proper keywords should be given for Suite Setup, Suite Teardown, Test Setup and Test Teardown.
  • Appropriate tags should be given for each case.
  • Tests should be independent.
  • In dependant tests, detailed notes should be given. Consider verifying the status of the previous test using ${PREV TEST STATUS} variable.
  • Hard coding of object name should be avoided.
  • Should contain many high level keywords instead of repeating steps often.
  • High level keywords should be used for navigation.
  • Local variables should have prefix char ‘t’ as temporary variables

Resources
  • Keep all resource files in single folder.
  • Resource file names should be less than 20 characters and file type should be HTML.
  • All characters should be small characters.
  • Documentation should be updated with purpose.
  • All constants should be maintained in separate resource file.
  • Keep separate resource files for application’s data.
  • Keep separate resource files for all GUI objects page wise or module-wise.
  • Group the high level keywords by categories like business logic, module and general.

High Level Keyword / User Keyword / Function
  • Function names should be less than 35 characters.
  • It should be easily readable and self explanatory.
  • For easy readability, it should be in camel case (Capital & Small letters).
  • Prefixes are sometimes useful. For example, Is - to ask a question about something, Get - get a value, Set - set a value
  • Can have space for better readability.
  • Documentation should have clear details for purpose, variables and returning values.
  • Hard coding of object name should be avoided.
  • Arguments should have char ‘p’ as prefix and returned variable should have char ‘r’ as prefix.
  • Local variables should have prefix char ‘t’ as temporary variables
  • Duplicate Functions should not be added.
  • Can contain some programming logic (for loops, if/else)
  • Complex logic in libraries rather than in user keywords
  • Important variables can have comments on the RHS

Variables
  • Variable names should be less than 20 characters.
  • Variables should have meaningful words
  • For easy readability, it should be in camel case (Capital & Small letters).
  • Local variables should have prefix char ‘t’ as temporary variables
  • Arguments should have char ‘p’ as prefix and returned variable should have char ‘r’ as prefix.
  • GUI object variables should have char ‘o’ as prefix.
  • Constant variables should be in Capital letters. For example, APP_URL, DB_SERVER. All other type of variables should have mixed style (small and capital) characters.
  • Script/Global variables should be defined at the top of the script.
  • Function / test case level variables should be defined at top of the function.
  • Can have space. But try to restrict for minimum

Sunday, October 2, 2011

FOR loops & IF condition in RobotFramework

Using Robot Framework, test engineer can create FOR loops and IF conditions. I don't think so, any other Keyword driven framework is giving this kind of flexibility.

FOR loop can be set in two ways. First one is based on number of items in a List. Another one is based on range like from 1 to 50. Similarly keywords can be executed if condition matches or not. See below example.

FOR Loop & IF condition explantation using Robot Framework

TestCase Action Arguments
VerifyListItems [Arguments] ${Locator} @{ListItems}
[Documentation] Verifies the list of items present in a List Object.
: FOR ${Element} IN @{ListItems}
Select From List ${Locator} ${Element}
List Selection Should Be ${Locator} ${Element}
: FOR ${index} IN RANGE 50
${obj1}= Evaluate ${index}*4+3
Run Keyword if '@{tDriverData}[4]'=='2' Go To MyProfile
Run Keyword Unless '@{tDriverData}[4]'=='2' Go To UserCreation

Monday, August 15, 2011

Robotframework Installation

RobotFramework Installation is a tricky task. We need to install 6-7 utilities. All should be installed in the same order. Here I have given the instructions for Windows OS.

Tools installation
All RobotFramework related software can be the latest. The other software should be as the same version.

  1. Install Python (python-2.6.4.msi). Set installation directory as C:\Python26
  2. Install Robot Framework (robotframework-2.6win32.exe)
  3. Install Robot Selenium Library (robotframework-seleniumlibrary-2.7.win32.exe)
  4. Install Python Widgets (wxPython2.8-win32-unicode-2.8.11.0-py26.exe)
  5. Install Robot IDE (robotide-0.31.win32.exe)
  6. Install Python Win32 module (pywin32-214.win32-py2.6.exe)
  7. OPTIONAL (For SeleniumLibrary)- Install Java (jdk-6u14-windows-i586.exe), if your machine does not have Java.
  8. OPTIONAL (For SeleniumLibrary)- Extract Selenium RC Server (selenium-remote-control-1.0.3.zip)

Environment variables Configuration
To execute RIDE and Pybot, environment variables should set properly.
  1. Create a system level environment variable & value as --> PYTHONHOME=C:\Python26
  2. Create a system level environment variable & value as --> PYTHONPATH=C:\Python26\Lib;C:\Python26\Scripts;C:\Python26\Lib\site-packages;C:\Python26\Lib\site-packages\SeleniumLibrary;C:\Python26\Lib\site-packages\robotide\;C:\Python26\Lib\site-packages\robot\;C:\Python26\Lib\site-packages\wx-2.8-msw-unicode;
  3. Also add to PATH variable --> % PYTHONHOME%;% PYTHONHOME%\Scripts;

Steps for 64 Bit OS
To enable Robot Framework for 64 bit OS, you should install 64 bit python setup in same directory. Also the command prompt should be invoked through setting ‘Run as a Administrator’ if OS is Vista or Windows 7 version.

Verify the Installation
Open new command prompt and type ‘pybot --version’ and output like --> Robot Framework 2.6.0 (Python 2.6.4 on win32).

Tuesday, July 12, 2011

RobotFramework - Overview

I have executed many automation projects and also developed various automation frameworks using different tools like Silktest, QTP, Selenium, CodedUI, MS UIA, VisualTest (dead) and Winrunner (dead). Tried few open source frameworks and found RobotFramework as the best one. Successfully completed five projects using RobotFramework. Main advantage is, I'm able to integrate with different test tools and libraries. It is neither related to IBM Rational tools or any other commercial tools.

Summary in RobotFramework Homepage
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 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 keywords from existing ones using the same syntax that is used for creating test cases.

Robot Framework is open source software released under Apache License 2.0. Its copyrights are owned and development supported by Nokia Siemens Networks.

Robot Framework Features

  1. Advanced Keyword Driven framework
  2. Enable functional team contribution for automation
  3. Reusable/custom keywords
  4. Dynamic variables
  5. Easily extendable by Python, C# & Java
  6. Supports few test libraries including Selenium
  7. Provides simple and powerful Results Reporting
  8. Multiple Operating Systems support
  9. $ Free


Links for Robot Framework Resources
Robot Framework Home Page
Robot Framework User Guide
Robot Framework Quick Start Guide
Robot IDE
Robot Selenium Library

Robot Framework - Introduction
Robot Framework - Articles
Simple tutorial for Robot Framework

In last 6 months, many updates are happened on Robot framework and its related libraries. It is supporting many of my generic automation framework features.

Headers

Features

Robot Framework

Supported FrameworksFunctional DecompositionYes
Data DrivenYes
Keyword DrivenYes
Table DrivenYes
Independent toOperating SystemYes
ApplicationYes
TechnologyYes
Test ScriptingRecordingNo
ParametrizationYes
Suite Setup ModuleYes
Suite TearDown ModuleYes
Test Setup ModuleYes
Test TearDown ModuleYes
Database IntegrationYes
ScriptingYes
Environment LibraryYes
Test ExecutionMultiple OSYes
Multiple platformsYes
Parallel ExecutionNo
Test TimeoutYes
Based on PriorityYes
Grouping TestsYes
Running Failed testsYes
Result AnalysisDetail reporting for each step executionYes
Snapshots for failed testsYes
Test level reportingYes
Compiled reportYes
Results by categoryYes
Expected BenefitsLess effort to automateYes
Less dependence on highly skilled automation professionalsYes
Exception handlingYes
Easy to MaintainYes
Easy to Integrate with Other toolsYes
Support to CI (Continuous Integration) toolsYes
Additional ExpectationsDynamic conditionsYes
Dynamic Loop supportYes
UI to Edit dataYes
UI to execute testsYes
Update test metrics automaticallyYes
Update captured defects automaticallyYes