Appium 简单使用(二)

上回我们说到,手机和appium已经连接成功。

下面我们开始写代码来进行测试。

运行代码前,先要安装python 库

pip install Appium-Python-Client

然后获取apk信息、工具在sdk目录下,build-tools对应版本下面。

命令:aapt.exe dump badging (APK的路径)

获取到包名,等信息之后,将包名填写到appium桌面版当中去。appium桌面版我稍后将资源上传。

大致内容如下:

直接点start server 启动

启动后,点击放大镜,填写链接内容,大致界面如下图。添加好APP信息

{
  "platformName": "Android", #固定
  "platformVersion": "9", #android版本
  "deviceName": "xxxxxx你自己的手机唯一识别码,adb可以看",
  "appPackage": "bin.mt.plus", #package 上面获取到的app信息里面有
  "appActivity": "bin.mt.plus.Main", # 上面获取到的app 第二个内容
  "automationName": "uiautomator2", #默认
  "unicodeKeyboard": true, #用unicode编码发送字符串
  "resetKeyboard": true, # 取消键盘
  "noReset": true # 应用信息不重置
}

点击Start Session启动

启动后会打卡app,然后获取到app对应页面上的信息。

剩下就是写脚本的事情了。获取到Xpath。写脚本

#coding=utf-8
from appium import webdriver
import time

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '9'
desired_caps['deviceName'] = 'xxxxxxxxx'
desired_caps['appPackage'] = 'bin.mt.plus'
desired_caps['appActivity'] = 'bin.mt.plus.Main'
desired_caps['automationName'] = 'uiautomator2'
desired_caps['unicodeKeyboard'] = 'True'
desired_caps['resetKeyboard'] = 'True'
desired_caps['noReset'] = 'True'

# 启动app
drivers = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# 定位到功能按键,并点击
driver.find_element_by_xpath(".//*[@text='功能']").click()

# 关闭退出
drivers.quit()

上面只是一个简单的例子。如何运行以及使用。

今天就讲到这里。感谢各位阅读。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

成都-Python开发-王帅

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值