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}输出启动日志,但是并没有成功看到日志输出。几经测试,仍没有成功输出,如果有小伙伴找到问题解决方案,请联系指正。

目录
相关文章
|
3天前
|
数据采集 Java 开发工具
一文2500字从0到1教你搭建Android自动化python+appium环境
一文2500字从0到1教你搭建Android自动化python+appium环境
一文2500字从0到1教你搭建Android自动化python+appium环境
|
5天前
|
Python
Python-类视图和蓝图
Python-类视图和蓝图
11 2
|
5天前
|
存储 Java 数据安全/隐私保护
Python----类对象和实例对象
Python----类对象和实例对象
9 2
|
6天前
|
C++ Python
Python中的类与对象
Python中的类与对象
8 1
|
6天前
|
Python
在Python中,类的属性可以分为公有属性和私有属性
【5月更文挑战第7天】Python类包含公有和私有属性。公有属性可直接外部访问,如`person.name`,而私有属性如`_name`需通过getter/setter方法访问,如`person.getName()`和`person.setName()`。私有属性用于封装数据、隐藏实现细节,增强代码可维护性和安全性。封装能灵活修改内部实现,不影响外部;安全性防止外部非法修改数据;一致性确保所有数据操作在类内完成,简化代码并减少错误。
28 10
|
6天前
|
Python
【Python 基础】Python中的实例方法、静态方法和类方法有什么区别?
【5月更文挑战第6天】【Python 基础】Python中的实例方法、静态方法和类方法有什么区别?
|
6天前
|
存储 程序员 Python
Python中自定义类实例化数组的艺术
Python中自定义类实例化数组的艺术
11 1
|
6天前
|
程序员 Linux C++
Python中的WinForms类桌面应用程序开发
Python中的WinForms类桌面应用程序开发
25 4
|
6天前
|
Java 开发者 索引
Python基础语法:类笔记
本篇博文是把自己在学习python类的过程中自己理解和笔记,一点一点总结的写出出来,做一个总结,加深对面向对象编程的理解。
|
6天前
|
数据可视化 索引 Python
数据分享|Python用PyMC3贝叶斯模型平均BMA:采样、信息准则比较和预测可视化灵长类动物的乳汁成分数据
数据分享|Python用PyMC3贝叶斯模型平均BMA:采样、信息准则比较和预测可视化灵长类动物的乳汁成分数据