Sikuli Script running test twice.

Asked by Georg Steyn

Hello

My Sikuli Test is runnig twice and i don't know why.
But its breaking the whole test. Do someone have any
tips plesae.

Here is the script:

#Georg Steyn - Goodx Login Screen - 2016/09/14
from sikuli import *
from GoodxLoginScreen import GoodxConfig

#Test for clicks
if GoodxConfig.TestType=="click":
 click( GoodxConfig.gxnav_login_entity_caption_combo )
 click( GoodxConfig.gxnav_login_entity_combo_value )
 click( GoodxConfig.gxnav_login_username_caption_combo )
 click( GoodxConfig.gxnav_login_username_combo_value )
 click( GoodxConfig.gxnav_login_password_caption_edit )
 type( GoodxConfig.UserPassword )
 click( GoodxConfig.gxnav_login_okbutton )

#Test with Keys
if GoodxConfig.TestType== "keys":
 click( GoodxConfig.gxnav_login_password_caption_edit )
 type( Key.TAB, KeyModifier.SHIFT ) #tab backwards to username field
 type( Key.TAB, KeyModifier.SHIFT ) #tab backwards to entity field
 type( Key.TAB )
 type( "G")
 type( Key.TAB ) # TAB to password field
 type( GoodxConfig.UserPassword )
 type( Key.F2 )

In both If statments it runs twice.

Question information

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

the pasted snippet does not contain any reason for this effect.

so you have to check the environmental code, that calls/runs this snippet.

Revision history for this message
Georg Steyn (georgsteyn) said :
#2

Thanks for the Quick Response.
Do you mean the import GoodxConfig that i am importing.

If so this is the code for that file. I can't see any problems to my knowledge.

Belowe is the code for GoodxConfig.py

#Links with GoodxLoginScreen.py
#from sikuli import *
import os
#Set the test Lang for Images.
#For Afrikaans Imgages: afr_eng = afr
#For English Images: afr_eng = eng
lang = "eng"

#Path to Sikuli Img
imgPath = os.path.normpath("C:/Users/User/Documents/Local_Repro/main/imageLibrary.sikuli/eng") if lang == "eng" else os.path.normpath("C:/Users/User/Documents/Local_Repro/main/imageLibrary.sikuli/afr")

#Call Imgage from Image Path
gxnav_login_entity_caption_combo = imgPath + "\gxnav\gxnav_login_entity_caption_combo.png"
gxnav_login_entity_combo_value = imgPath + "\gxnav\gxnav_login_entity_combo_value.png"
gxnav_login_okbutton = imgPath + "\gxnav\gxnav_login_okbutton.png"
gxnav_login_password_caption_edit = imgPath + "\gxnav\gxnav_login_password_caption_edit.png"
gxnav_login_username_caption_combo = imgPath + "\gxnav\gxnav_login_username_caption_combo.png"
gxnav_login_username_combo_value = imgPath + "\gxnav\gxnav_login_username_combo_value.png"

UserPassword='x'

#Test type is "click" or "keys"
TestType="click"

Revision history for this message
RaiMan (raimund-hocke) said :
#3

No, I was talking about the code, that calls/runs your script.

meaning:
how is the snippet from your question run (from commandline, IDE, ...)

Revision history for this message
Georg Steyn (georgsteyn) said :
#4

Oh Yes ok Sorry I understand. :-)

call C:\SikuliX\runsikulix.cmd -r C:\Users\Test2\Documents\Automated_Tests\GoodxLoginScreen.sikuli

Revision history for this message
RaiMan (raimund-hocke) said :
#5

ok, then you have to check, wether this call command is somehow executed twice.

The code I can see, does not contain any reason, to run the snippet twice.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#6

uups, just realized this:

from GoodxLoginScreen import GoodxConfig

this means you have this:

-- folder GoodxLoginScreen.sikuli
   -- GoodxLoginScreen.py
   -- GoodxConfig.py

import generally executes executable code at import time.

so your snippet is executed at import and normally == twice

You either have to restructure your files like this:

-- folder GoodxLoginScreen.sikuli
   -- GoodxLoginScreen.py
-- folder GoodxConfig.sikuli
   -- GoodxConfig.py

and change the import to
import GoodxConfig

or otherwise take care, that the code is not run at import.

Revision history for this message
RaiMan (raimund-hocke) said :
#7

Sorry, for not having seen that from the beginning ;-)

Revision history for this message
Georg Steyn (georgsteyn) said :
#8

Ok Thank You.

Just one little import note i forgot to mention:

If i open Sikuli IDE => File => Preferences => more options ... => save => close screen => Apply => ok => ok

If i do all that and then run the code its works fine for the first time.
If you run it again the twice code run thing start again.

Just little side note.

Revision history for this message
Georg Steyn (georgsteyn) said :
#9

Any feedback maybe on the above information? :-)

Revision history for this message
RaiMan (raimund-hocke) said :
#10

did you read comment #6?

Revision history for this message
Georg Steyn (georgsteyn) said :
#11

Thanks RaiMan, that solved my question.

Revision history for this message
Georg Steyn (georgsteyn) said :
#12

Oh! Sorry i didn't see that comments. :-)
Thank You very much RaiMan.