re-use image name

Asked by Sander

Hi there,

As I want to test my application in different browsers, i've created (so far) two different classes
firefoxTestImages():
chromeTestImages():

 imgDict = {}

 def __init__(self):
  self.imgDict = {}
  self.addImage("checkbox", "checkbox.png")
  self.addImage("okButton", "okButton.png")

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

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

The image names for both classes are exactly the same (except the image).
The import seems to be working fine, but when I switch from chrome to firefox it does not recognize the image anymore, just because it is still trying to find the chrome version.

Is using the reload() function the way forward, what would be the best solution for this?

Regards,
Sander

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

yep, that is tricky ;-)

supposing you have something like this:

# main script
import firefoxtest
import chrometest

firefoxtest.run() # uses the ff-images

chrometest.run() # uses the ff-images also

the reason behind:

the image path is automatically arranged according to the sequence of the imports:

imagepath after the imports:
-- main
-- firefoxtest
-- chrometest

since the images are searched on the image path according to "first wins", images with the same name will always be used from the firefoxtest.

So the solution is to implement some "rearrange the imagepath" logic using the features getImagePath(), removeImagePath() and addImagePath() (see docs)

Revision history for this message
Sander (sander-helsloot) said :
#2

Hi Raiman,

Thanks for your prompt relpy.
I'll take your suggestion on board and come back to this if it all works fine.

Cheers.

Regards,
Sander

Can you help with this problem?

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

To post a message you must log in.