Skip to content

Commit

Permalink
Create SikuliXRobotLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
engkantosakanto committed Oct 31, 2015
1 parent 2f0c249 commit 822075e
Show file tree
Hide file tree
Showing 36 changed files with 3,764 additions and 2 deletions.
64 changes: 64 additions & 0 deletions INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SikuliXRobotLibrary Installation
=============================


Preconditions
-------------

SikuliXRobotLibrary supports Jython interpreters supported by the
Robot Framework.

SikuliXRobotLibrary depends on a few other Jython libraries, including
of course Robot Framework. All dependencies are declared in setup.py.

SikuliX must be installed with the Tesseract based OCR features. When running the sikulixsetup-1.1.0.jar,
make sure to select the second and third options.


Installing from source
----------------------

The source code can be retrieved either as a source distribution or as a clone
of the main source repository. The installer requires Jython version 2.7 or
newer. Install by running:

jython setup.py install

Note: In most linux systems, you need to have root privileges for installation.

Uninstallation is achieved by deleting the installation directory and its
contents from the file system. The default installation directory is
`[JythonLibraries]/site-packages/robotframework_SikuliXRobotLibrary-1.0.0-py2.7.egg`.


Verifying Installation
----------------------

Once you have installed SikuliXRobotLibrary it is a good idea to verify the installation. To verify installation start jython::

C:\> jython

and then at the Python prompt type::

>> import SikuliXRobotLibrary
>>

If the python command line interpretor returns with another prompt ('>>' as shown above) then your installation was successful.

Troubleshooting Installation
----------------------------

The most common issue with installing SikuliXRobotLibrary is missing dependencies. An error like::

ImportError: No module named sikuli

indicates that you are missing the sikulixapi.jar package. To correct this problem, install the sikulixapi.jar with tesseract
then add the following in the environment variables::

CLASSPATH = <path to sikulixapi.jar>
JYTHONPATH = <path to sikulixapi.jar>\Lib

Similarly if you receive "No module named ..." error message then you have another missing dependency. To correct, use easy_install to install the missing package.

.. _pip: http://www.pip-installer.org
.. _easy_install: http://pypi.python.org/pypi/setuptools
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,53 @@
# SikuliXRobotLibrary
SikuliX library for Robot Framework
Custom SikuliX library for Robot Framework
==================================================


Introduction
------------

SikuliXRobotLibrary is a gui recognition testing library for Robot Framework
that leverages the SikuliX version 1.1.0 methods.

It is modeled after the Selenium2Library library.

- More information about this library can be found in the `Keyword Documentation`_.
- Installation information is found in the `INSTALL.rst` file.


Directory Layout
----------------

demo/
A simple demonstration, with calculator application in Windows 8

doc/
Keyword documentation

src/
Python source code


Usage
-----

To write tests with Robot Framework and SikuliXRobotLibrary,
SikuliXRobotLibrary must be imported into your Robot test suite.
See `Robot Framework User Guide`_ for more information.


Running the Demo
----------------

The demo directory contains an easily executable demo for Robot Framework
using SikuliXRobotLibrary. To run the demo, run::

jybot -d <output directory> -i <tag> <suite directory>

E.g.::

jybot -d C:\demo\logs -i Win8CalculatorTest C:\demo\calc_test_suite
Note: C:\demo\logs directory must be created before running the script


.. _Keyword Documentation: https://confluence.flnltd.com/display/FREEL/Custom+SikuliX+Robot+Library
.. _Robot Framework User Guide: http://code.google.com/p/robotframework/wiki/UserGuide
77 changes: 77 additions & 0 deletions build_dist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python

import os, sys, shutil, subprocess, argparse

THIS_DIR = os.path.dirname(os.path.abspath(__file__))
DIST_DIR = os.path.join(THIS_DIR, "dist")
sys.path.append(os.path.join(THIS_DIR, "src", "SikuliXRobotLibrary"))
sys.path.append(os.path.join(THIS_DIR, "doc"))
sys.path.append(os.path.join(THIS_DIR, "demo"))

def main():
parser = argparse.ArgumentParser(description="Builds a Se2Lib distribution")
parser.add_argument('py_26_path', action='store', help='Python 2.6 executbale file path')
parser.add_argument('py_27_path', action='store', help='Python 2.7 executbale file path')
parser.add_argument('--release', action='store_true')
parser.add_argument('--winonly', action='store_true')
args = parser.parse_args()

if args.winonly:
run_builds(args)
return

clear_dist_folder()
run_register(args)
run_builds(args)
run_demo_packaging()
run_doc_gen()

def clear_dist_folder():
if os.path.exists(DIST_DIR):
shutil.rmtree(DIST_DIR)
os.mkdir(DIST_DIR)

def run_doc_gen():
import generate
print
generate.main()

def run_register(args):
if args.release:
_run_setup(args.py_27_path, "register", [], False)

def run_builds(args):
print
if not args.winonly:
_run_setup(args.py_27_path, "sdist", [ "--formats=gztar,zip" ], args.release)
_run_setup(args.py_26_path, "bdist_egg", [], args.release)
_run_setup(args.py_27_path, "bdist_egg", [], args.release)
if os.name == 'nt':
_run_setup(args.py_27_path, "bdist_wininst", [ "--plat-name=win32" ], args.release)
_run_setup(args.py_27_path, "bdist_wininst", [ "--plat-name=win-amd64" ], args.release)
else:
print
print("Windows binary installers cannot be built on this platform!")

"""def run_demo_packaging():
import package
print
package.main()"""

def _run_setup(py_path, type, params, upload):
setup_args = [py_path, os.path.join(THIS_DIR, "setup.py")]
#setup_args.append("--quiet")
setup_args.append(type)
setup_args.extend(params)
if upload:
setup_args.append("upload")

print
print("Running: %s" % ' '.join(setup_args))
returncode = subprocess.call(setup_args)
if returncode != 0:
print("Error running setup.py")
sys.exit(1)

if __name__ == '__main__':
main()
12 changes: 12 additions & 0 deletions demo/calc_test_suite/CalculatorImageAssertionTest.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*** Settings ***
Documentation Calculator test for image assertion.
Library SikuliXRobotLibrary
Resource CalculatorTestGivenWhenThen.robot
Suite Setup Set Default Pattern Library Directory
Test Teardown Close "Calculator" Application
Default Tags CalculatorImageAssertionTest DemoTest2

*** Test Cases ***
Availability Test
Given User Opens "Calculator" Application
Then "Calculator" Application Window Should Be Displayed
25 changes: 25 additions & 0 deletions demo/calc_test_suite/CalculatorTest.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*** Settings ***
Documentation Calculator test suite for the common operations. Does not use patterns as parameters in the keywords but uses offsets of regions instead
Library SikuliXRobotLibrary
Resource CalculatorTestGivenWhenThen.robot
Test Setup Open "Calculator" Application
Test Teardown Close "Calculator" Application
Default Tags CalculatorTest DemoTest
Test Template Functionality Test

*** Test Cases *** NUM1 OPERATION NUM2 EXPECTED RESULT
12 + 100 = 112 12 Plus 100 112
9 + 9 = 18 9 Plus 9 18
112 - 100 = 12 112 Minus 100 12
119 - 9 = 110 119 Minus 9 110 # You may set a test case to fail in order to see how the reporting works.
100 / 2 = 50 100 Divide 2 50
1 / 4 = 0.25 1 Divide 4 0.25
10 * 100 = 1000 10 Times 100 1000
2 * 9 = 18 2 Times 9 18

*** Keywords ***
Functionality Test
[Arguments] ${num1} ${operation} ${num2} ${expected_result}
Given User Calculates "${num1}" "${operation}" "${num2}"
When User Clicks "Equals" Button
Then Actual Result Should Be Equal To "${expected_result}"
42 changes: 42 additions & 0 deletions demo/calc_test_suite/CalculatorTestConstants.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
*** Variables ***

#******************************************************************************#
# PATTERN LIBRARY
#******************************************************************************#
${WIN7_CALCULATOR_APP} Win7/calc.png
${WIN8_CALCULATOR_APP} Win8/calc.png

#******************************************************************************#
# Offsets: x, y, width, height
#******************************************************************************#
#[Documentation] These constants uses regions instead of patterns, thus leads to a smaller storage cost
${BUTTON_0_REGION} 18, 276, -157, -296
${BUTTON_1_REGION} 18, 244, -195, -296
${BUTTON_2_REGION} 58, 244, -195, -296
${BUTTON_3_REGION} 98, 244, -195, -296
${BUTTON_4_REGION} 18, 212, -195, -296
${BUTTON_5_REGION} 58, 212, -195, -296
${BUTTON_6_REGION} 98, 212, -195, -296
${BUTTON_7_REGION} 18, 180, -195, -296
${BUTTON_8_REGION} 58, 180, -195, -296
${BUTTON_9_REGION} 98, 180, -195, -296
${BUTTON_DECIMAL_REGION} 98, 276, -195, -296
${BUTTON_PLUS_REGION} 136, 276, -195, -296
${BUTTON_MINUS_REGION} 136, 244, -195, -296
${BUTTON_TIMES_REGION} 136, 212, -195, -296
${BUTTON_DIVIDE_REGION} 136, 180, -195, -296
${BUTTON_EQUALS_REGION} 176, 244, -195, -265
${CALCULATOR_RESULT_SCREEN_REGION} 18, 61, -40, -274

#******************************************************************************#
# File Path/Directories
#******************************************************************************#
${IMAGE_LIBRARY} ${CURDIR}\\calc_image_library
${CALCULATOR_EXECUTABLE} C:/Windows/System32/calc.exe
${CALCULATOR_APP_NAME} Calculator

#******************************************************************************#
# Timeouts and Retries
#******************************************************************************#
${TIMEOUT} 20
${RETRY_INTERVAL} 5
48 changes: 48 additions & 0 deletions demo/calc_test_suite/CalculatorTestGivenWhenThen.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
*** Settings ***
Library SikuliXRobotLibrary
Resource CalculatorTestConstants.robot
Resource CalculatorTestGlobalHelpers.robot


*** Keywords ***
#******************************************************************************#
# Given
#******************************************************************************#
User Calculates "${p_num1}" "${p_operation}" "${p_num2}"
User Clicks "${p_num1}" Button
User Clicks "${p_operation}" Button
User Clicks "${p_num2}" Button

User Opens "${p_application}" Application
Open "${p_application}" Application

#******************************************************************************#
# When
#******************************************************************************#
User Clicks "${p_button}" Button
String "${p_button}" Only Contains Numbers

Run Keyword If ${NUMBERS_ONLY}
... Click Number "${p_button}" Button
... ELSE
... Click "${p_button}" Button

#******************************************************************************#
# Then
#******************************************************************************#
Actual Result Should Be Equal To "${p_expected_result}"
${ACTUAL_ANSWER}= Get Text In "Calculator Result Screen" Region
Should Be Equal ${ACTUAL_ANSWER} ${p_expected_result}

"${p_application}" Application Window Should Be Displayed
Get OS Type

Wait Until Keyword Succeeds ${TIMEOUT} ${RETRY_INTERVAL}
... Window "${p_application}" Should Be Open

Element "${${OS_TYPE}_${p_application}_APP}" Should Be Visible Before Timeout


#******************************************************************************#
# Internal Keywords
#******************************************************************************#
61 changes: 61 additions & 0 deletions demo/calc_test_suite/CalculatorTestGlobalHelpers.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
*** Settings ***
Library String

*** Keywords ***
Click "${p_button_name}" Button
[Documentation] Clicks a button using the region constants in CalculatorTestConstants.robot
Set New Search Region In Active App ${BUTTON_${p_button_name}_REGION}
Click Region

Click Number "${p_button}" Button
@{numbers} = Split String To Characters ${p_button}
: FOR ${number} IN @{numbers}
\ Click "${number}" Button

String "${p_string}" Only Contains Numbers
${ret} = Run Keyword And Return Status
... Should Match Regexp ${p_string} [0-9]+
Set Test Variable ${NUMBERS_ONLY} ${ret}

Window "${p_window}" Should Be Open
[Documentation] Checks if ${p_window} has window, returns True if window is available, otherwise False.
${has_window} = Run Keyword and Return Status
... App Has Window ${p_window}
Should Be True ${has_window}

Set Focus To "${p_window}" Window
Wait Until Keyword Succeeds 20 5
... Set Application Focus ${p_window}

Element "${p_pattern}" Should Be Visible Before Timeout
[Documentation] Waits until pattern is visible before timeout value, returns an error if pattern is still not visible once timeout expires.
Wait Until Pattern Is Visible ${p_pattern} ${TIMEOUT}

Set Default Pattern Library Directory
Set Image Library ${IMAGE_LIBRARY}

Open "${p_app_name}" Application
Check and Open Application ${${p_app_name}_EXECUTABLE} ${${p_app_name}_APP_NAME}
Wait Until Keyword Succeeds ${TIMEOUT} ${RETRY_INTERVAL}
... Window "Calculator" Should Be Open
#Set Focus To "Calculator" Window

Close "${p_application_name}" Application
Close Application ${p_application_name}

Get Text In "${p_region}" Region
[Documentation] Returns the text in the specified region ${p_region}
Set New Search Region In Active App ${${p_region}_REGION}
${p_text}= Get Text In Search Region region
[Return] ${p_text}

#******************************************************************************#
# Archive
#******************************************************************************#
Get OS Type
${OS_type_version} = Get Env OS Type And Version
${t_OS_type} = Set Variable If
... '${OS_type_version}' == 'WINDOWS 6.1' Win7
... '${OS_type_version}' == 'WINDOWS 6.3' Win8
Set Test Variable ${OS_TYPE} ${t_OS_type}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 822075e

Please sign in to comment.