Search code examples
automated-testssikuli

Function from imported other Sikuli scripts not works


This is function in sikuli script named switch_to_apps.sikuli

def go_to_apps():
    if exists(Pattern("1505400746884.png").similar(0.85)):
        click(Pattern("1505400746884.png").similar(0.85))
        wait(2)
        if exists("1505400452627.png"):

            wait("1505746343759.png",FOREVER)

            click("1505745789021.png")

        else:
            click(Pattern("1505401581163.png").similar(0.95))

    else:
        click(Pattern("1505400343997.png").similar(0.80))
        if exists("1505400452627.png"):
            wait("1505746343759.png",FOREVER)

            click("1505745789021.png")
        else:
            click(Pattern("1505401581163.png").similar(0.95))

I import this script to another script(main script) and call function go_to_apps()

type("r", Key.WIN)
wait(1)
type ("***************" + Key.ENTER)

wnd= App ("*********.exe")

while not wnd.isRunning():
    wait(1)


if exists(Pattern("1505813384072.png").similar(0.85)):
    pass
else:    
    popup("ERROR")


import switch_to_apps
go_to_apps()

wait (5)

rightClick(Pattern("1504795371766.png").similar(0.80))
wait(1)
click(Pattern("1504795615700.png").targetOffset(-75,80))

But IDE says me:

[error] NameError ( name 'go_to_apps' is not defined )

If I first open the switch_to_apps.sikuli script and run function go_to_apps(), after that function finish work, I run main script and now all works.

That I need to do that my function from imported script works right?


Solution

  • Maybe if you would use from switch_to_apps import *, and not import switch_to_apps.
    Or maybe switch_to_apps.go_to_apps(), and not go_to_apps().

    I have my definitions in a class, so it might be a little different then lose definitions I think.