Wednesday, June 24, 2015

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.

No comments:

Post a Comment