1.录制自动化脚本

场景:启动雪球,点击我的,登陆雪球,选择手机及其他登陆,输入手机号

2.Appium客户端

客户端介绍:https://github.com/appium/appium/blob/master/docs/en/about-appium/appium-clients.md

3.使用python进行测试

3.1安装python客户端

pip install Appium-Python-Client

3.2python在线编辑器,建议使用pycharm

pip install jupyter

3.3本地开服务器

使用Go语言,不会,需要学习

./gohttpserver --upload

ifconfig en0

3.4打印session,用session开启Inspector

from appium import webdriver

caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "domo"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["automationName"] = "UiAutomator2"
caps["newCommandTimeout"] = 600 driver = webdriver.Remote("http://localhost:4723/wd/hub",caps)
driver.implicitly_wait(10)
print(driver.session_id)

3.5测试代码

#python代码
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python from appium import webdriver caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "domo"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["automationName"]="Uiautomator2" #可加可不加,默认Uiautomator
caps["newCommandTimeout"]=600 #session超时时间,默认60秒。如果一段时间内没有接收到请求,session会消失 driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) el1 = driver.find_element_by_id("com.xueqiu.android:id/user_profile_icon")
el1.click()
el2 = driver.find_element_by_id("com.xueqiu.android:id/tv_login")
el2.click()
el3 = driver.find_element_by_id("com.xueqiu.android:id/tv_login_by_phone_or_others")
el3.click()
el4 = driver.find_element_by_id("com.xueqiu.android:id/register_phone_number")
el4.send_keys("123456789") driver.quit()

FAQ

1.使用python执行脚本,抱如下错误

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/Users/chenshanju/Library/Android/sdk/platform-tools/adb -P 5037 -s 406e8f3 install /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v1.18.0.apk' exited with code 1'; Stderr: 'adb: failed to install /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v1.18.0.apk: Failure [INSTALL_FAILED_USER_RESTRICTED: Install canceled by user]'; Code: '1'

小米手机,需要在开发者模式里允许USB调试

2.selenium.common.exceptions.InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported for this session

不要使用Appium Desktop,使用Appium Server解决

3.selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

添加延时即可

from appium import webdriver
from time import sleep
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "domo"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["newCommandTimeout"] = 600
caps["automationName"] = "UiAutomator2" driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
driver.implicitly_wait(20)
sleep(20)
print(driver.session_id)
def test_for_element(a):
try:
driver.find_element_by_id(a).click()
except Exception as e:
print(e)
finally:
print(driver.session_id)
print(a)
sleep(3)
test_for_element("com.xueqiu.android:id/agree")
test_for_element("com.xueqiu.android:id/user_profile_icon")
test_for_element("com.xueqiu.android:id/tv_login")
test_for_element("com.xueqiu.android:id/tv_login_by_phone_or_others")
driver.find_element_by_id("com.xueqiu.android:id/register_phone_number").send_keys("123456789")
sleep(3)
print(driver.session_id)
driver.quit()

最新文章

  1. Single-page app(SPA)
  2. vld使用
  3. 阿里巴巴笔试整理系列 Session2 中级篇
  4. spring提供的解决中文乱码方案
  5. codeforces 359D 二分答案+RMQ
  6. django 简单的邮件系统
  7. POJ 2528 Mayor's posters (线段树区间更新+离散化)
  8. HDFS 的可靠性
  9. 三个流行MySQL分支的对比
  10. Web技术导论复习大纲
  11. [Linux]root默认密码问题
  12. tomcat 设置session 时间
  13. android Activity之间数据传递 Parcelable和Serializable接口的使用
  14. HBuilder 插件开发(openinstall 集成)
  15. python类型转换convert实例分析
  16. 微信小程序开发05-日历组件的实现
  17. ABP框架系列之十三:(Authorization-授权)
  18. DLNg[结构化ML项目]第二周迁移学习+多任务学习
  19. zhuan 常用图像数据集:标注、检索
  20. 【数据库】jdbc详解

热门文章

  1. 用UILabel实现文字滚动播放(跑马灯)效果
  2. C#foreach的用法
  3. UI基础:UITableView表视图
  4. Word2007:如何在竖版(纵向)页面中间插入横版(横向)页面
  5. BZOJ4899: 记忆的轮廓【概率期望DP】【决策单调性优化DP】
  6. 带CookieContainer进行post
  7. HDU 4647 Another Graph Game 想法类
  8. centos下安装必要组件(相当于apt-get install install build-essential)
  9. 《DSP using MATLAB》Problem 3.7
  10. LG4455 【[CQOI2018]社交网络】