当前位置:   article > 正文

【Termux Python3.11开发】安装opencv-contrib-python后终于可以尝鲜airtest,poco_termux opencv-python libicu.so

termux opencv-python libicu.so

无意看到airtest的一些介绍,正好在找一些工具,Python自动化的轮子,好放在Termux环境下进行测试效果如何,经过一些时间的折腾,总算顺利解决,安装好几个相关的库

点击链接加入群聊【Termux友情赞助群】:897177804

pip install -U airtest -i https://pypi.mirrors.ustc.edu.cn/simple/
pip install pocoui -i https://pypi.mirrors.ustc.edu.cn/simple/
  • 1
  • 2

将adb设备激活可见完成,发现运行得到以下结果,将**/data/data/com.termux/files/usr/bin/adb的可执行程序,进行替换/data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb**问题解决

OSError: [Errno 8] Exec format error: ‘/data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb’

找了些示例,测试成功,这次测试的代码主要还是使用shell方式,但看中的是图色识别自动化功能,以后再测试,python运行代码相对其它方式,除了功能强大,稳定运行性也是最重要的,这才是替换一些自动化脚本软件最大的原因.

from airtest.core.api import connect_device
from airtest.core.api import G
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco

# dev1 = connect_device("Android://127.0.0.1:5037/127.0.0.1:5555")
dev2 = connect_device("Android:///")
poco = AndroidUiautomationPoco(dev2)

poco('com.google.android.calculator:id/digit_1').click()
poco('com.google.android.calculator:id/op_add').click()
poco('com.google.android.calculator:id/digit_1').click()
poco('com.google.android.calculator:id/eq').click()

# 获取控件的“text”属性值
# result = poco('com.google.android.calculator:id/formula').get_text()
result = poco("com.google.android.calculator:id/formula").attr("text")

try:
    assert_equal(result, '21', '1+1=2 ^^')
except AssertionError:
    print("按钮值断言失败")

print("运行结束")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

以下是代码运行之后的调试输出信息

/data/data/com.termux/files/home/.virtualenvs/Termux/bin/python /data/data/com.termux/files/home//tmp/pycharm_project_272/actuon_ui/airtest/1.py 
[22:01:57][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb devices
[22:01:57][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb devices
[22:01:57][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 get-state
[22:01:57][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 wait-for-device
[22:01:57][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 shell getprop ro.build.version.sdk
[22:01:57][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 shell dumpsys activity top
[22:01:58][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 shell dumpsys package com.netease.open.pocoservice
[22:01:58][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 forward --no-rebind tcp:19025 tcp:10080
[22:01:58][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 forward --no-rebind tcp:15275 tcp:10081
[22:01:58][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 shell am start -n com.netease.open.pocoservice/.TestActivity
[22:01:58][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 shell am instrument -w -e debug false -e class com.netease.open.pocoservice.InstrumentedTestAsLauncher com.netease.open.pocoservice/androidx.test.runner.AndroidJUnitRunner
按钮值断言失败
运行结束
[22:02:10][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 forward --remove tcp:19025
[22:02:10][DEBUG]<airtest.core.android.adb> /data/data/com.termux/files/usr/lib/python3.11/site-packages/airtest/core/android/static/adb/linux/adb -s 127.0.0.1:5555 forward --remove tcp:15275

进程已结束,退出代码0

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

在这里插入图片描述

测试使用的软件:com.google.android.calculator.apk
以及代码,放在下载中
点击下载】https://download.csdn.net/download/hexinbo/88111861

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/394019
推荐阅读
相关标签
  

闽ICP备14008679号