Showing posts with label Own keyword. Show all posts
Showing posts with label Own keyword. Show all posts

Wednesday, June 24, 2015

Sikuli Robotframework general libary + Robot testcase + Open a notepad

General sikuli robotframework library:

'''
Created on Jun 24, 2015

@author: vallikkv @ Vallinayagam.K
'''

from sikuli import *
from Screenshot import *


class SikuliLib(object):
    ROBOT_CONTINUE_ON_FAILURE = True
    myImagePath = "C:\\sikulix\\Images"
    addImagePath(myImagePath)

    def __init__(self):
        self.screen = Screenshot()

    def click_window(self, inputfile):
        self.inputfile = inputfile
        if exists(self.inputfile):
            find(self.inputfile)
            click(self.inputfile)
        else:
            self.screen.take_screenshot()
            raise AssertionError("Required screen to click is not available")

    def Type_and_enter(self, inputtotype, inputfile1):
        self.inputtotype = inputtotype
        self.inputfile1 = inputfile1
        if exists(self.inputfile1):
            find(self.inputfile1)
            type(self.inputtotype + Key.ENTER)
        else:
            self.screen.take_screenshot()
            raise AssertionError("Typing To inputfile is failed")

    def expected_screen(self, expectedfile):
        self.expectedfile = expectedfile
        if not exists(self.expectedfile):
            self.screen.take_screenshot()
            raise AssertionError("Error, Failed")
        else:
            pass



Robot Testcase using above library:

*** Settings ***
Documentation  Open Notepad using Sikuli and Robotframework

Library  Sikulilibrary.SikuliLib

*** Test Cases ***
Open a Notepad
    click window    windowicon.PNG
    click window    search.png
    Type and enter  notepad.exe    typerun.png
    expected screen  notepad.png

Failed Log:

By Giving wrong File name in the "Type and enter" keyword




Passed Log:







Sikuli + Robotframework + jybot - Execution with screenshot

Sample code:

Created on Jun 24, 2015

@author: vallikkv @ Vallinayagam.K
'''

from robot.api import *
import org.sikuli.basics.SikuliXforJython
from sikuli import *
from Screenshot import *

##Screenshot.py is copied and available in the location "C:\Python27\Lib\site-packages", or declare ##the path where screenshot.py is located.


class Notepad(object):
    ROBOT_CONTINUE_ON_FAILURE = True
    myImagePath = "C:\\sikuli\\Tests.sikuli\Notepad"
    addImagePath(myImagePath)

    def __init__(self):
        self.screen = Screenshot()

    def click_window(self):
        try:
            find("WindowsIcon.PNG")
            click("WindowsIcon.PNG")
        except Exception:
            print "Error in the click window"

    def Type_in_run_and_enter(self):
        try:
            wait("Runwindow.PNG", 5)
            type("notepad.exed"+ Key.ENTER)
        except Exception:
            print "Problem in second step"

    def verify_result(self):
        if not exists("Notepad.PNG"):
            self.screen.take_screenshot()
            raise AssertionError("Error, Failed")
        else:
            pass



Command used to execuet - jython C:\Python27\Lib\site-packages\robot\run.py C:\sikuli\Tests.sikuli\Notepad\Robot.txt


It will embeed screenshots when failed, I've used only for the verify_result method, It should be included for all the methods.

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