这两天在写游戏自动化的时候遇到 poco 初始化的问题,搞了几天才找到问题所在。
报错信息如下

# 主入口main.py
from airtest.core.api import *
from pages.loginPage import loginPage
from pages.mainPage import *
from pages.setPage import setPage
from pocoMgr import *
from testcase.test_rename import test_rename

auto_setup(__file__, logdir=True, devices=["android://127.0.0.1:5037/959775083200472"])
# 设备号VIVOS7: android://127.0.0.1:5037/959775083200472
start_app("xxxxxxxxxx")
sleep(20)

if get_poco()("spCompeting").exists():
    mainPage.autoCloseFrame()
# mainPage.py 类文件
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
from poco.drivers.std import StdPoco
poco = StdPoco()


class MainPage:
    def __init__(self):
        self.loginreward = "text='登陆有礼'"
        self.mainpageLv = "textnumLevel"
        self.setPageBtn = "spbtnMore"

        # 弹窗关闭按钮
        self.spbtnClose = "spbtnClose"
        self.imgbtnOK = "imgbtnOK"
        # self.imgbtnClose = "imgbtnClose"
        self.imgbtnClose = "textSure"

        # 竞技匹配按钮就
        self.spCompeting = "spCompeting"

    def autoCloseFrame(self):
        notallspringframeisclose = True
        while notallspringframeisclose:
            notallspringframeisclose = False
            if get_poco()(self.imgbtnClose).exists():
                get_poco()(self.imgbtnClose).click()
                notallspringframeisclose = True
                continue
            if get_poco()(self.spbtnClose).exists():
                get_poco()(self.spbtnClose).click()
                notallspringframeisclose = True
                continue
            if get_poco()(self.imgbtnOK).exists():
                get_poco()(self.imgbtnOK).click()
                notallspringframeisclose = True
                continue

mainPage = MainPage()


↙↙↙阅读原文可查看相关链接,并与作者交流