简体   繁体   English

无法从Sikuli IDE运行脚本

[英]Unable to run script from Sikuli IDE

First of all let me tell you that I am new to Sikuli. 首先,让我告诉您,我是Sikuli的新手。 I have developed some scripts using the Sikuli IDE and it works fine. 我已经使用Sikuli IDE开发了一些脚本,并且运行良好。

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: 我的sikuli脚本是这样的:

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. 我不是专家,但是我不确定您是否真的想要一门课程...我质疑您是否真的想要一门课程,因为它看起来并不意味着您的Test课程具有不同的属性,只是将执行的不同代码段。

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). 有一个关于如何构建Python类商量好了在这里 (特别是第二个答案)。

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. 如果您定义了一个名为__init__的定义,则该定义将在调用该类时执行。

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

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

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

# Run class 
Test()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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