Showing posts with label Jybot. Show all posts
Showing posts with label Jybot. Show all posts

Saturday, May 21, 2016

Robot Framework with Sikuli 1.1.0

Integration of Robot Framework with Sikuli 1.1.0

Pre-requsities:
1. Jython, Robot Framework (Jybot) should be installed and environment variables should be configured properly.
// Installation of Jython and Jybot are not covered here.

Sikuli installation steps:
1. Download the sikuli1.1.0 jar file from the website https://launchpad.net/sikuli/+download
2. Open the command prompt and install the sikuli as below

3. Choose the option 2

 4. Installation will be progress from internet and will be completed automatically


5. Once installation is completed, "sikulixapi.jar" file will be available in the corresponding folder.
6. To use the methods of sikuli in our jython script,  we have to add it in the jythonpath


7. Now open the command prompt and check its working properly.


8. Develop a sample jython script


"""Created on May 21, 2016
@author: vallikkv @ Vallinayagam.K
'''""

import org.sikuli.basics.SikuliXforJython
from sikuli import *


class Sikuli11Lib(object):
    ROBOT_CONTINUE_ON_FAILURE = True
    #Configure the path of image files
    myImagePath = "E:\\Sikuli11\\Images"
    addImagePath(myImagePath)


    def SampleMethod(self):
        click("1.PNG")
        click("2.PNG")

if __name__ == '__main__':
    a = Sikuli11Lib()
    a.SampleMethod()

9. Sample execution of  the script without integration of RF




10. To integrate with RF (Eg: Same script can be used to integrate with RF). Make sure the script file path is accessible by the RF+ Jybot, if not add it in the environment variable path

11, RF script by using the above sikuli script

*** Settings ***
Documentation  Testing with Sikuli 1.1.0 version

Library  Sample.Sikuli11Lib

*** Test Cases ***
Checking the version
    SampleMethod


12. Execute it using jybot



Note: This is a sample script, you can develop wrapper for sikuli methods and make it as common library which can be reused in robot framework like other libraries eg: Selenium2library


Reference: https://answers.launchpad.net/sikuli/+question/136170

Wednesday, May 18, 2016

Sample sikuli script

'''
Created on Jun 24, 2015

@author: vallikkv @ Vallinayagam.K
'''

from sikuli.Sikuli import *
import sys
from robotremoteserver import RobotRemoteServer


class SikuliLib(object):
    ROBOT_CONTINUE_ON_FAILURE = False
    myImagePath = "C:\\sikulix\\Images.sikuli"
    #setBundlePath = "C:\\sikulix\\Images.sikuli"
    addImagePath(myImagePath)
 
    def __init__(self):
        self.appCoordinates = (0, 0, 1024, 768)
        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:
            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

if __name__ == '__main__':
    from robot.libraries.Screenshot import *
    RobotRemoteServer(SikuliLib(), host="192.168.10.104", port=8270, allow_stop=True)


Reference: https://answers.launchpad.net/sikuli/+question/136170







Saturday, September 12, 2015

Robot framework + SSH Library + Monitor a log file until a string matches using Jython

SSH library installation.

1. Download SSH library and install using "jython setup.py install" command
2. Download Trilead-ssh2-1.0.0-build217.jar file and put it in a folder
3. Add that folder in the "CLASSPATH"

Eg: E:\Robot\trilead-ssh2-1.0.0-build217.jar;C:\Python27\Lib\site-packages

4. Similarly add "robot" folder in the JYTHONPATH

Eg: C:\Python27\Lib\site-packages\robot;C:\Python27\Lib\site-packages

5. Execute command jython -c "import SSHLibrary" for verification

Sample SSH Robot script

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

Library    SSHLibrary

*** Variables ***
${HOST}                192.168.10.135
${USERNAME}            test
${PASSWORD}            test

*** Test Cases ***
Open Connection And Log In
    Open Connection    ${HOST}
    Login    ${USERNAME}    ${PASSWORD}

Execute and expect a new session
    ${OUT}=    Execute Command    timeout 5 tail -f -n 1 /var/log/messages | awk '/vallikkv/;/vallikkv/ { exit }'
    BuiltIn.Log to console    ${OUT}
    BuiltIn.Should Not Be Equal    ${OUT}    \  
    

Closing the connections
    BuiltIn.Log to console    Test
    Close All Connections


ButiltIn.Log to console -> This is how, use the inbuilt keywords of robot(python) in jython scripts

Shell command to monitor log file until specific "word" matches, if not exit the script in 5 seconds


timeout 5 tail -f -n 1 /var/log/messages | awk '/vallikkv/;/vallikkv/ { exit }'  







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.