Showing posts with label Sikuli. Show all posts
Showing posts with label Sikuli. 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







Wednesday, October 14, 2015

Sikuli: check multiple of the same/duplicate images and choose the image to perform action

def by_y(match):

   return match.y


icons = findAll("Capture.PNG")



# sort the icons by their y coordinates and put them into a new variable sorted_icons

sorted_icons = sorted(icons, key=by_y)

# another shorter version is using lambda.

print sorted_icons[3]


# Iterate the images and hover it - To confirm

for icon in list(sorted_icons)[:2]:

    hover(icon)


#Click the 4th image from the list.

click(list(sorted_icons)[4])

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.

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


Wednesday, June 17, 2015

Sikuli + Eclipse + java

How to execute sikuli script using Eclipse + java?

1. Download sikuli-setup.jar

2. Execute in cmd prompt "java -jar sikuli-setup.jar" file. It will generate runSetup.cmd in the same folder.

3. Execute it via cmd prompt.

4. It will lauch a window, choose the options "Download for IDE, eclipse" and for "windows, mac"

5. It will download sikuli-java.jar file.

6. Now open the eclipse, create a package -> create a project -> Add TestNG library and Sikuli-java.jar.

7. Save and reboot the pc (It requires a logout and login to activate)

8. Lauch eclipse and create a TestNG Class and write your code.(Note:- TestNG installation for eclipse is not covered here)

Sample code:

package sample_sikuli;

import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
import org.testng.annotations.Test;

public class NewTest {
Screen s = new Screen();
  @Test
  public void Sample() {
 try {
s.click("C:/Users/USER/Desktop/1.png");
s.click("C:/Users/USER/Desktop/2.png");
s.click("C:/Users/USER/Desktop/3.png");
s.type("notepad.exe");
} catch (FindFailed e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
  }
}