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

3 comments:

Pekka Klärck said...

These instructions are somewhat complicated because you are using Robot Framework 2.6. Recently released Robot Framework 2.7 has a lot better support for installing with IronPython. See here for the updated installation instructions:
http://code.google.com/p/robotframework/wiki/Installation

Notice also that you don't necessarily need to install Python at all to use Robot Framework on IronPython. You do, however, need it to be able to use RIDE.

Palani Selvam said...

Pekka,
You are true.. I didn't try the recent Robot Framework version with IronPython..

As you know that I did it 2 years back...I got few mails like How to install IronPython for RobotFramework.. Thats why created this post...

Software Testing Services said...

Cool and interesting information, I am sure the information you have shared with blog readers can be beneficial for many out there willing to work with ironpython.