Search code examples
automated-testssikuli

How to make a function in Sikuli to use it in other Sikuli scripts?


I want to create a function which use Sikuli features (as click, doubleclick, wait, etc.) to create other scripts in Sikuli, as a library using functions from sikuli.

Example in the "libary" file:

def openCalc(self):
    doubleClick("imgs\calculator.png")

def closeCalc(self):
    click("imgs\clickclose.png")

And using it in Sikuli IDE:

def testSum(self):
    self.openCalc()
    type("5+5\n")
    type("c",KEY_CTRL)
    try:
        assert Env.getClipboard()!="10"
    except:
        self.nop()
    self.closeCalc()
    

Can I do that in some way? How?


Solution

  • I agree with above comment that we should always use class wherever we can... but to answer your question, here is the way to what you want to do -

    Called Function File called_fun.sikuli has -

    a = "abc"
    def hey():
      print(a)
    

    And calling function (whatever name it has) is -

    import called_fun
    called_fun.hey()
    

    Just make sure that both of the files are in the same folder.

    Let me know if you have questions on this.