Script fail without proper message

Asked by sohail

Some time it pass and some time its fail.
My script is...
def assignfunction():
    for n in range (35):
        type(Key.TAB)
    type(Key.LEFT)
    type(Key.ENTER)
    wait(3)
    for n in range(27):
        type(Key.TAB)
    type(Key.ENTER)
    wait(3)
def assigndata():
    doubleClick(Pattern("1480419928033.png").exact().targetOffset(-6,0))
    wait(2)
    for n in range(6):
        type(Key.TAB)
    type(Key.ENTER)

Its fail some time after running first function . its fail after type(Key.ENTER) on teamcity logs.
and does not shows any message like unable to find Image of second function.

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
Alex Lunyov (lunyov-av) said :
#1

How do you see it fails? What happens? You have shown only function definitions, but it would better to give also their call points in your script (the part of your script where assigndata and assignfunction are called).

Revision history for this message
sohail (safdar) said :
#2

def assignfunction():
    for n in range (35):
        type(Key.TAB)
    type(Key.LEFT)
    type(Key.ENTER)
    wait(3)
    for n in range(27):
        type(Key.TAB)
    type(Key.ENTER)
    wait(3)
def assigndata():
    doubleClick(Pattern("1480419928033.png").exact().targetOffset(-6,0))
    wait(2)
    for n in range(6):
        type(Key.TAB)
    type(Key.ENTER)
try:
    assignfunction()
    assigndata()
except:
    defaultExceptionHandling()

Actually test passes several times but some time fail after executing first function .( Key.Enter) . But on local machine its always passes

Below is error message on teamcity log
[log] TYPE "#TAB."
[log] TYPE "#TAB."
[log] TYPE "#TAB."
[log] TYPE "#ENTER."
[error] script [ C:\BuildAgent\work\ef621962d08f8ac\SikuliSource\WinForm.Behaviour\permission_smoke.sikuli ] stopped with error in line 12

Revision history for this message
Alex Lunyov (lunyov-av) said :
#3

It seems your script fails while waiting for 1480419928033.png in doubleClick function after type(Key.ENTER) was successfully passed. That is usually a problem of system GUI response, that in some cases don't perform all key actions as you expect. You should better use waiting constructions like

gui_element_region.wait(gui_element_subpicture, wait_time)

where gui_element_subpicture is little piece of expected element to be acted on (20 × 20 pixels or so), gui_element_region is a rectangular region where the subpicture is expected to appear, wait_time is appropriate time, could be for example FOREVER = wait forever. Use SHOW button to get the region according to the captured image and use region.grow(2..5 pixels) to enlarge regions where Sikuli looks for the subpic.

So you could always be sure your script clicks on appropriate GUI elements. In most cases :)

Revision history for this message
sohail (safdar) said :
#4

can you write some example please to use region.wait()

Revision history for this message
Alex Lunyov (lunyov-av) said :
#5

For example:

button_OK_img = Pattern(mybuttonOK.png).similar(0.85) # this could just be a picture you paste in your script using sikuli tools

button_OK_reg = Region(100, 123, 30, 20) # this is a region on the screen where 30 × 20 px word "OK" on a button is expected to appear at some moment.

than you use:

button_OK_reg.wait(button_OK_img, FOREVER)

Sikuli will stop and wait forever (till you turn off the computer or interrupt the workflow manually) for the OK button in the place where it should appear.

Revision history for this message
Alex Lunyov (lunyov-av) said :
#6

*then you use...
sorry for misprint

Can you help with this problem?

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

To post a message you must log in.