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







Sunday, March 20, 2016

RF test status and Testcase ID from output.xml file

import xml.etree.ElementTree as ET
root = ET.parse('output.xml').getroot()
for suites in root.findall('suite'):
    for test in suites.findall('test'):
        for status in test.findall('status'):
            print status.attrib['status'], test.attrib['id']

Saturday, January 2, 2016

Python File handling

Python scripting:  Search and replace a string in file.

def Main():
    with open("E:\Softwares\Sample.txt") as f:
        for x, line in enumerate(f):
            if "Valli" in line:
                print line.replace("Valli", "Nayagam", -1),


if __name__ == "__main__":
    Main()