Showing posts with label jython. Show all posts
Showing posts with label jython. 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, September 9, 2015

Jython remote library

Remote library for Jython/Jybot with sikuli

Machine 1:
1. Installed jython 2.5.2, Jybot, Sikuli
2. Install robot remote server using command "jython setup.py install"
       Note: Download robotremoteserver.tgz file and install
3. Own library for sikuli


Machine 2:
1.Robot framework, jython 2.5.2, jybot
2. Test scripts (Eg: Notepad.robot)

STEPS:

1. Run the sikuli library using command "jython <sikulilibrary>"

It will start the Remote library for the interface configured in the library file and exposed keywords

2.  Now run the robot script from any network machines using command

"jybot <Notepad.robot>"


The testresults will be available in the local machine (i.e Machine2)

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.

Tuesday, June 23, 2015

How to create Robot Framework Test library for Sikuli jython scripts: (Content Not yet Finalized: Warning)

1. Create Jython script, Filename -  Sample1.py

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


class Sample(object):

    def testing(self):
        print "testing"
        try:
            click("1.PNG")
            wait("1.PNG", FOREVER)
        except:
            print "Click windows icon is not occured - Failed "
        
       
#if __name__=='__main__':
#    test = Sample()
#    test.testing()
    
2.  Create Robot Library for the created script

*** Settings ***
Library    Sample1.Sample              

*** Test Cases ***
Sample testcase
    testing


3. Sikuliwrapper details: TO DO

4. Execute it as below





Monday, June 22, 2015

How to install sikuli for Jython?

How to install sikuli for Jython?

Before starting with sikuli installation, Install Jython 2.5.2 (In my windows 8.1, it not works with jython 2.5.3, So I used the earlier one). Refer my earlier post for jython installation

1. Download sikuli-setup.jar file and save it in a location: Eg: "C:\sikulix"

2. Now open the command prompt and go to the "C:\sikulix" location and execute command
      java -jar sikuli-setup.jar

3. It will generate a file named "runSetup.cmd" and available in the same location.

4. Now execute the command, it opens a installer window.

5. Choose the options for jython (2,4)

6. It will automatically download the required files from internet.

7. Once installation is completed, declare the following values in the system enviroment table




8. Now close the command prompt and open a new one

9. Open jython and import sikuli to verify everything works fine


Thursday, June 18, 2015

How to install jython in windows?

How to install jython in windows?

1. Download jython installer jar file from http://www.jython.org/downloads.html

          jython-installer-2.5.3.jar

2. Open command prompt and go to that downloaded location and execute

         java -jar jython-installer-2.5.3.jar

3. It will open a installer window, follow the instructions and install it.

4. Now open a  new command prompt and type "jython" and check it opens the interpreter window.


Note: To set path in environment variable, use path where the jython folder is available, in my case it's "C:\jython2.5.3"