简体   繁体   中英

Unable to run script from Sikuli IDE

First of all let me tell you that I am new to Sikuli. I have developed some scripts using the Sikuli IDE and it works fine.

But when i created class and have added the tests as methods to it..it does not work. Can someone let me know what am I missing here. my sikuli script is like this:

class Test:  
    def setUp(self):
        openApp("abc")
        wait(10)

    def tearDown(self):
       closeApp("abc")    

    def test1(self):
        click("1401168929740.png")
        time.sleep(1)
        type('o')
        time.sleep(3)
        click("1401169004890.png")
        wait("1401169047733.png")
        type("some text here")
        time.sleep(2)
        click("1401169154910.png")

        time.sleep(10)

        print("the outcome")

    def test2(self):
        wait("1401169193096.png")
        click("1401100914478.png")
        time.sleep(3)

        print("the outcome")


    def test3(self):
        type("m", KEY_ALT)
        type("cus1")
        type(Key.ENTER)
        time.sleep(2)
        type(Key.TAB)
        time.sleep(2)
        type("10.00")
        time.sleep(2)
        type(Key.TAB)
        time.sleep(2)
        type(Key.TAB)
        time.sleep(2)
        type(Key.ENTER)
        time.sleep(3)
        type(Key.ENTER)
        time.sleep(17)
        type(Key.ENTER)
        time.sleep(10)

    def test4(self):
        if exists("1401100952048.png"):
            popup("the outcome")

        else:
            popup("failure message")

I'm no expert, but I'm not sure if a class is what you really want...I question if you really do want a class, because it doesn't look like you're meaning for your Test class to have different attributes, just different pieces of code that will execute.

If you're wanting to wrap up these definitions into one easy-to-call piece of code, you could do it like this--

After defining all of the functions you have listed above, you could define one more function that includes them all:

def setUp():
    openApp("abc")
    wait(10)

def tearDown():
   closeApp("abc")    

def test1():
    click("1401168929740.png")
    time.sleep(1)
    type('o')
    time.sleep(3)
    click("1401169004890.png")
    wait("1401169047733.png")
    type("some text here")
    time.sleep(2)
    click("1401169154910.png")

    time.sleep(10)

    print("the outcome")

def test2():
    wait("1401169193096.png")
    click("1401100914478.png")
    time.sleep(3)

    print("the outcome")


def test3():
    type("m", KEY_ALT)
    type("cus1")
    type(Key.ENTER)
    time.sleep(2)
    type(Key.TAB)
    time.sleep(2)
    type("10.00")
    time.sleep(2)
    type(Key.TAB)
    time.sleep(2)
    type(Key.TAB)
    time.sleep(2)
    type(Key.ENTER)
    time.sleep(3)
    type(Key.ENTER)
    time.sleep(17)
    type(Key.ENTER)
    time.sleep(10)

def test4():
    if exists("1401100952048.png"):
        popup("the outcome")

    else:
        popup("failure message")

def completeTest():
    setUp()
    tearDown()
    test1()
    test2()
    test3()
    test4()

###program begins here

completeTest()

If you really did want a class, seeing how you're implementing the class could help us see where the problem is. If you want to keep these methods inside the class, then I think the proper way to call them is:

Test.setUp()
Test.tearDown()
Test.test1()
Test.test2()
Test.test3()
Test.test4()

There is a good discussion about how to construct classes in python here (particularly the second answer).

You need to call the class to make it execute.
Also the definitions you made need to be called before they execute.
If you make a definition named __init__ , that one will execute when the class is called.

class Test():
    def __init__(self):
        self.setUp()
        self.tearDown()

    def setUp(self):
        print('Hello')

    def tearDown(self):
        print('World')

# Run class 
Test()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM