← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #173899]: Robot Framework Problem

 

Question #173899 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/173899

Sergio posted a new comment:
Thank you RaiMan
Now I got calc working.
But I can't make the images to be found.

"To manage your images, the following might be the easiest way:

make a e.g. LoadSikuliScripts.py containing:
from sikuli import *
from script1 import *
from script2 import *
....

and add to test settings:
Library LoadSikuliScripts

this would use Sikuli to import all your scripts and populate the image
path accordingly."

I made a LoadSikuliScripts.sikuli in the same folder of calc.sikuli.
Its content is:
from sikuli import *
from calc import *

And my Test.txt file is:
*** Settings ***
Library           calc.Calculator    WITH NAME    Calculator
Library           LoadSikuliScripts

*** Test Cases ***
v
    Start App
    Verify App
    Perform Action    2    +    2
    Verify Result    4

My runfw.bat:
set work=C:\Users\Sergio\sikuli\rfw
set rfwj=%work%\robotframework-2.7a1.jar
set sikj=%work%\sikuli-script.jar
set CLASSPATH=%rfwj%;%sikj%
set JYTHONPATH=%work%\LoadSikuliScripts.sikuli;%work%\calc.sikuli;%rfwj%\Lib;%sikj%\Lib
java org.robotframework.RobotFramework --outputdir=results %*

The log:
TEST CASE: v
Full Name:	Teste.v
Start / End / Elapsed:	20120120 12:08:11.279  /  20120120 12:08:26.245  /  00:00:14.966
Status:	FAIL (critical)
Message:	FindFailed: can not find CalcApp.png on the screen.
+KEYWORD: Calculator.Start App
+KEYWORD: Calculator.Verify App
- KEYWORD: Calculator.Perform Action 2, +, 2
Start / End / Elapsed:	20120120 12:08:20.469  /  20120120 12:08:26.243  /  00:00:05.774
12:08:26.218	INFO	[error] CalcApp.png looks like a file, but can't be found on the disk. Assume it's text.
12:08:26.242	FAIL	FindFailed: can not find CalcApp.png on the screen.

My calc.sikuli:

from __future__ import with_statement
from sikuli.Sikuli import *

class Calculator(object):

	def __init__(self):
		self.appCoordinates = (0, 0, 1024, 768)

	def startApp(self):
		calcApp = App("Calculator")
		if not calcApp.window():
				App.open("calc.exe"); wait(2)
		calcApp.focus(); wait(1)

	def verifyApp(self):
		# check application
		if exists("CalcApp.png"):
			print("PASS: Calculator window appeared")
		else:
			print("FAIL: No calculator window")

	def performAction(self, *args):
		# get application region
		find("CalcApp.png")

		match = getLastMatch()
		self.appCoordinates = (match.getX(), match.getY(), match.getW(), match.getH())
		appRegion = Region(*self.appCoordinates)

		#rewrite action
		action = args[1]
		if args[1] == '+':
			action = 'Plus'
		elif args[1] == 'exp':
			action = 'Exp'

		with appRegion:
			click("btnC.png")

			click( "C:\Users\Sergio\sikuli\rfw\calc.sikuli\btn%s.png" % (args[0],) )
			click( "C:\Users\Sergio\sikuli\rfw\calc.sikuli\btn%s.png" % (action,) )
			click( "C:\Users\Sergio\sikuli\rfw\calc.sikuli\btn%s.png" % (args[2],) )

			click("btnEqual.png")
			
	def verifyResult(self, *args):
		expected_result = str(eval(''.join(args)))
		actual_result = self.getResultFromClipboard()

		#verification
		if actual_result == expected_result:
			print("PASS: Action performed correctly and result equals %s" % expected_result)
		else:
			print("FAIL: Actual result '%s' is not equal to expected result '%s'" % (actual_result, expected_result))

	def getResultFromClipboard(self):
		type('c', KEY_CTRL)
		return str(Env.getClipboard())

	def runTest(self):
		self.startApp()
		self.verifyApp()

		actions = '2+2'
		self.performAction(*actions)
		self.verifyResult(*actions)

if __name__ == "__main__":
	addImagePath("calc.sikuli")
	calc = Calculator()
	calc.runTest()

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.