背景介绍

代码结构

测试用例

使用用户登录的例子进行说明
class XXX():
    logging.basicConfig(level=logging.DEBUG, filename="D:/XXX/XXX/Log/LoginLOG.log",
                        format="%(asctime)s%(filename)s [line:%(lineno)d] %(levelname)s %(message)s")

    with open('D:/XXX/XXX/Config/desired_caps.yaml', 'r', encoding='UTF-8') as file:
        data = yaml.load(file, Loader=yaml.FullLoader)

    # 把YAML中的字段值一一存放到desired_caps
    desired_caps = {}
    desired_caps['platformName'] = data['platformName']
    desired_caps['platformVersion'] = data['platformVersion']
    desired_caps['deviceName'] = data['deviceName']

    # base_dir = os.path.dirname(os.path.dirname(__file__))
    # app_path = os.path.join(base_dir, 'app', data['appname'])
    # desired_caps['app'] = app_path

    desired_caps['udid'] = data['udid']
    desired_caps['appPackage'] = data['appPackage']
    desired_caps['appActivity'] = data['appActivity']
    desired_caps['noReset'] = data['noReset']

    # 启动远程端口服务
    driver = webdriver.Remote('http://' + str(data['ip']) + ':' + str(data['port']) + '/wd/hub', desired_caps)
    driver.implicitly_wait(5)

    @allure.feature('XXX_00')
    @allure.story('test_story_00')
    @allure.severity('critical')
    def XXX_00(self):
        """
        测试用例1:登录
        :return:
        """
        gp = GuidePage(self.driver)
        gp.click_enter()
        print("点击立即体验,成功进入")
        lgp = LoginPage(self.driver)
        time.sleep(2)

        # 点击同意授权
        lgp.agree()

        # 输入帐号密码,并登录
        f = open("D:/XXX/XXX/Config/account.txt")
        lines = f.readlines()
        for line in lines:
            # 替换掉每多余符号
            line = line.replace("\"", "").replace("\n", "")
            lineList = line.split(",")
            account1 = lineList[0]
            account2 = lineList[1]
        lgp.input(account1, account2)

        lgp.login()
        print("登录成功")

启动 Appium+ 连接模拟器

appium -a 127.0.0.1 -p 4723 -U 127.0.0.1:62001 --session-override

Appium 运行

模拟器运行

补充说明

连接夜神模拟器
获取当前窗口信息
可能会遇到的问题


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