keyerror message when running automation script

Asked by mohammed ahmed on 2019-08-06

from sikuli.Sikuli import *
import os
myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)
from imagerepository import *
from imageclick import *
#from util import *
#from regionDictionary import *

class PSWTest():

            def openpsw():
            #def __init__(self):
#try
                myImages = imagerepository()
                Debug.on(3)
                app=App.open(r"C:\xxxx\Mxxxxxer\System\ftmerfr.exe")
                wait(5)
                click(myImages.getImage("open"))
                #click(myImages.getImage('open'))
            openpsw()

****image repository*****
from sikuli.Sikuli import *
myPath = os.path.dirname(getBundlePath())
getImagePath()
if not myPath in sys.path: sys.path.append(myPath)

class imagerepository():

    imgDict = {}
    def __init__(self):
        self.imgDict = {}
        self.addImage("open","1565006145909.png")
        self.addImage("addserver","1565006209232.png")
        self.addImage("servername","1564497837198.png")
        self.addImage("ok servername","1564497875916.png")
        self.addImage("startservice","1564497937218.png")
        self.addImage("stopservice","1564497991603.png")

    def addImage(self, name, img):
  self.imgDict[name] = img

    def getImage1(self, name):
  return self.imgDict[name]

****error***
[error] script [ PSWTest ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "C:\Users\mahmed\Documents\sikuli images\PSWTest.sikuli\PSWTest.py", line 11, in <module> class PSWTest(): File "C:\Users\mahmed\Documents\sikuli images\PSWTest.sikuli\PSWTest.py", line 22, in PSWTest openpsw() File "C:\Users\mahmed\Documents\sikuli images\PSWTest.sikuli\PSWTest.py", line 20, in openpsw click(myImages.getImage("open")) File "C:\Users\mahmed\Documents\sikuli images\imagerepository.sikuli\imagerepository.py", line 22, in getImage return self.imgDict[name] KeyError: open

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2019-09-05
Last reply:
2019-09-12
RaiMan (raimund-hocke) said : #1

not a SikuliX problem, since it is self-made Jython code.

mohammed ahmed (md-ahmd) said : #2

Apologies, to come back to this question.
I think I know what is happening, Every time I add an image to image dictionary.
I need to restart IDE for the image to be identified by other scripts.

I have "from imagerepository import *" in all the scripts that use the images.
Not sure if it is repeated question. Also I am using SikulixIDE 1.1.3.

Please let me know if you need more information to help me with this.
Thanks

mohammed ahmed (md-ahmd) said : #3

Can someone help me with this. It might be a trivial issue for experts to solve but I have reached a bottleneck.

RaiMan (raimund-hocke) said : #4

Your overall concept is not dynamic:
If you change a script's content, that was imported before in the IDE, it has to be reloaded at the next run, to reflect the changes.

So if you add an image in the script with class imagerepository, it is not reflected by the already imported script (the IDE is one continous Jython session).

A solution is to run your main script from command line, which starts a new session with every run and make your changes in parallel in the IDE.

Another solution is to rely on the image path feature:
instead of importing the imagerepository script, put it on the image path

Can you help with this problem?

Provide an answer of your own, or ask mohammed ahmed for more information if necessary.

To post a message you must log in.