Skip to content

Tutorial: Simple calculator operations

Joshua Bellamy-Henn edited this page Mar 25, 2014 · 7 revisions

Under development - Stay tuned!

Introduction

This example does not automatically launch the Calculator application so you must ensure the calculator is visible somewhere on the screen. This tutorial will eventually support both Windows / Mac but currently the repository only has baseline images for OSX.

Running

To run the example type:

$ python run.py examples/calculator/validate.py 

Code

import bootstrap
..

# Change logging level verbosity
EntityLoggerProxy.getLogger().setLevel(TRACE)
Config.setScreenshotLoggingLevel(TRACE)

# Create a new instance of the calculator
calculator = Calculator()

# Validate that the calculator exists on the screen
calculator.validate()

Step-by-Step

First SikuliFramework should do some initial setup..

import bootstrap

Output:

Launching Jython [examples/calculator/validate.py]...
java -cp java/jython.jar:java/*:. -Dpython.path=.:java/sikuli-script.jar/Lib:src:resources -Xmx1024M org.python.util.jython -Dpythonpath=. -Dloglevel=TRACE examples/calculator/validate.py
[info] Sikuli vision engine loaded.
[info] Mac OS X utilities loaded.
[info] VDictProxy loaded.
*INFO:1363147546013* Changing screenshot logging level
*INFO:1363147546022* [SikuliFramework] Booting.. SikuliVersion=X-1.0rc3
*TRACE:1363147546037* Image search path: array(java.lang.String, [u'resources/baseline/os/mac/10.7/en/', u'resources/baseline/os/mac/10.7/', u'resources/baseline/os/mac/en/', u'resources/baseline/os/mac/', u'resources/baseline/en/', u'resources/baseline/'])

Changing the logging level..

EntityLoggerProxy.getLogger().setLevel(TRACE)
Config.setScreenshotLoggingLevel(TRACE)

Output:

*TRACE:1363147546084* Changing screenshot logging level

Note: This example currently has log verbosity set to TRACE so the output will be quite chatty. This can be modified by commenting out these lines or using DEBUG log level.

Next initialize the Calculator() context

calculator = Calculator()

Output:

*TRACE:1363147546086* [Calculator:Application]() created

Validate the Calculator is actually running

SikuliFramework will not try and validate that the application context until child-elements are operated on or until it validate() is called explicitly. Here we will validate the context explicitly with the validate() method.

calculator.validate()

Output:

*TRACE:1363147546088* [Calculator:Application]() trying to validate, parentRegion=[None]() timeout=60
*TRACE:1363147546094* [Calculator:Application->Finder]() ["Baselines"]() colType=SERIES nameType=FULL
*TRACE:1363147546095* [Calculator:Application->Finder]()  colType=SERIES
*DEBUG:1363147547525* [Calculator:Application->Finder->Transform]() PREVIOUS Applied RegionMorph dx1=1 dy1=1 dx2=2 dy2=2 transform, ["Region[0,0 1680x1050]"](4c0a71d1c73dca52cff28dc177b24907.png:Actual) -> ["Region[1,1 1681x1051]"](e15bad78640d8bbd3d5f1f947946bedd.png:Actual) 
*TRACE:1363147547539* [Calculator:Application->Finder]() Loading ["Pattern("/Users/smysnk/project/sikuli-framework/resources/baseline/os/mac/Calculator/Calculator[0].png").similar(0.7)"](dcd388e836527f29f425881fbaff7359.png)
*TRACE:1363147551218* [Calculator:Application->Finder]() failed to find on screen ["Images"]() in ["Region[1,1 1681x1051]"](1ea6219ff0abe5876517759bbf03e747.png:Actual) nameType=FULL colType=SERIES ser=0 seq=0
*DEBUG:1363147552222* [Calculator:Application->Finder->Transform]() PREVIOUS Applied RegionNearby value=10 transform, ["Region[0,0 1680x1050]"](24f9e6b1b5450dab3e04d32d843b0fa2.png:Actual) -> ["Region[0,0 1680x1050]"](9f4672e9445a56fd11e6f099ea94e250.png:Actual) 
*TRACE:1363147552225* [Calculator:Application->Finder]() Loading ["Pattern("/Users/smysnk/project/sikuli-framework/resources/baseline/os/mac/Calculator/Calculator[1].png").similar(0.7)"](5579e4a938e148b137090684d911feb7.png)
*TRACE:1363147553124* [Calculator:Application->Finder]() validated ["Pattern("/Users/smysnk/project/sikuli-framework/resources/baseline/os/mac/Calculator/Calculator[1].png").similar(0.7)"](5579e4a938e148b137090684d911feb7.png) ["Match[259,147 218x281 score=1.00 target=center]"](39590eb0b9d7d80086d59f0558a3bed4.png:Actual) in region ["Region[0,0 1680x1050]"](e2479a429c1f7d68543e94aaf68e416e.png:Actual) nameType=FULL colType=SERIES ser=1 seq=0
*TRACE:1363147553154* [Calculator:Application->Finder](39590eb0b9d7d80086d59f0558a3bed4.png:Actual) -- success! [attempt=0]
*DEBUG:1363147553213* [Calculator:Application](39590eb0b9d7d80086d59f0558a3bed4.png:Actual) identified at ["Region[259,147 218x281]"](39590eb0b9d7d80086d59f0558a3bed4.png:Actual)

Results

SikuliFramework will create a log file at /results/log.txt. Post-processing operations in run.py will markup a new HTML version of this file at /results/log.html.

RobotFramework Results Log