python 使用 AppiumService 类启动appium server

简介: python 使用 AppiumService 类启动appium server

一、前置说明


Appium的1.6.0版本中引入了AppiumService类,可以很方便的通过该类来管理Appium服务器的启动和停止。


二、操作步骤


import os
from appium.webdriver.appium_service import AppiumService as OriginalServer
from libs import path
class AppiumService(OriginalServer):
    def __init__(self, port='4723', log_file_path=None):
        self.port = port
        self.log_file_path = log_file_path
        if not self.log_file_path:
            self.log_file_path = os.path.join(path.get_log_dir(), f'Appium_Server_{port}.log')
        super().__init__()
    def start_server(self, **kwargs):
        args = [
            f'-p {self.port}',
            f'-g {self.log_file_path}',
            '--session-override',
            '--log-timestamp',
            '--session-override',
            '--local-timezone',
            '--allow-insecure chromedriver_autodownload',
        ]
        self.start(args=args, **kwargs)
if __name__ == '__main__':
    service = AppiumService()
    service.start()
    print(service.is_running)
    print(service.is_listening)


三、Demo验证


运行代码,可以启动appium server,执行测试脚本,成功打开app:

def test_launch():
    import logging
    logging.basicConfig(level=logging.DEBUG)
    from driver.appium.driver import WebDriver
    appium_server_url = 'http://localhost:4723'
    capabilities = {
        "platformName": "Android",
        "automationName": "uiautomator2",
        "deviceName": "127.0.0.1:62001",
        "app": "D:\\resources\\ApiDemos-debug.apk",
    }
    driver = WebDriver(command_executor=appium_server_url, capabilities=capabilities)


但是,有一点小问题,在上面代码中我加入了-g {self.log_file_path}输出启动日志,但是并没有成功看到日志输出。几经测试,仍没有成功输出,如果有小伙伴找到问题解决方案,请联系指正。

目录
相关文章
|
2月前
|
数据采集 测试技术 API
python爬虫之Appium 的使用
搭建appium环境,appium基本使用,API操作等等
47 0
|
7天前
|
数据安全/隐私保护 Python
Python从入门到精通——2.2.1深入学习面向对象编程:类和对象的定义
Python从入门到精通——2.2.1深入学习面向对象编程:类和对象的定义
|
7天前
|
Python
Python 一步一步教你用pyglet制作可播放音乐的扬声器类
Python 一步一步教你用pyglet制作可播放音乐的扬声器类
16 0
|
14天前
|
Python
python面型对象编程进阶(继承、多态、私有化、异常捕获、类属性和类方法)(上)
python面型对象编程进阶(继承、多态、私有化、异常捕获、类属性和类方法)(上)
54 0
|
14天前
|
索引 Python
python 格式化、set类型和class类基础知识练习(上)
python 格式化、set类型和class类基础知识练习
40 0
|
16天前
|
Python
python学习12-类对象和实例对象
python学习12-类对象和实例对象
|
16天前
|
Java 程序员 Python
python学习13-面向对象的三大特征、特殊方法和特殊属性、类的浅拷贝和深拷贝
python学习13-面向对象的三大特征、特殊方法和特殊属性、类的浅拷贝和深拷贝
|
2月前
|
Python
Python类(class)中self的理解
Python类(class)中self的理解
19 0
|
2月前
|
Python
Python类定义:从小白到专家的旅程
Python类定义:从小白到专家的旅程
8 0
|
2月前
|
Python
Python类与对象:深入解析与应用
本文介绍了Python中的核心概念——类和对象,以及它们在面向对象编程中的应用。类是用户定义的类型,描述具有相同属性和行为的对象集合;对象是类的实例,具备类的属性和方法。文章通过示例讲解了如何定义类、创建及使用对象,包括`__init__`方法、属性访问和方法调用。此外,还阐述了类的继承,允许子类继承父类的属性和方法并进行扩展。掌握这些概念有助于提升Python编程的效率和灵活性。