Sunday, April 5, 2015

Robotframework: Customized library using python - How to

Robotframework: How to create a customized library using python to create a robot keyword

Below example shows the creating a robot keyword "Addition" using customized library

Step 1. Create the python script,

Addition.py - (Library name to be imported in RF)
-------------

from robot.api import logger
from robot.libraries.BuiltIn import BuiltIn


def add_two_numbers(number1, number2):
    """ Python function for adding two numbers """
    return int(number1) + int(number2)



add_two_numbers - Keyword to be used in test scripts

Step 2: Save the file in the folder "C:\Python27\Lib\site-packages"

Step 3: Robot test scripts

Filename - Addition.txt
Execution command - pybot Addition.txt


*** Settings ***
Documentation     Testing my own library

Library    Addition

*** Test Cases ***
Add two
    Add two numbers using own library


***Keywords***
Add two numbers using own library
    ${ADDITION}    Add two numbers    1    8
    Log to console    ${ADDITION}

 Execution Report


No comments:

Post a Comment