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()

python-appium520-2初步使用的更多相关文章

  1. 转来的——python webdriver自动化测试初步印象——转来的

    python webdriver自动化测试初步印象 以下示例演示启动firefox,浏览google.com,搜索Cheese,等待搜索结果,然后打印出搜索结果页的标题 from selenium i ...

  2. 对python编程的初步理解

    一直以来零零散散有听过python,这周终于下定决心学python了.在网上了买个套视频教程,内容分周次学习,有详细的讲解.本人觉得非常好.这里谈谈一下第一周的学习的笔记.望路过的大神给予指正,不胜感 ...

  3. python web架构初步认识

    ---恢复内容开始--- #主入口,Python解释器从这开始执行:if __name__ == '__main__': run() 内部执行过程: #引用socket模块 import socket ...

  4. python写mapReduce初步

    最近在学了python了,从mapReduce开始 ,话不多说了,直接上代码了哈 map阶段,map.py文件 import sys # 标准输入 # 在终端的话,就需要这样了 cat a.txt | ...

  5. Python函数学习——初步认识

    函数使用背景 假设老板让你写一个监控程序,24小时全年无休的监控你们公司网站服务器的系统状况, 当cpu\memory\disk等指标的使用量超过阀值时即发邮件报警, 你掏空了所有的知识量,写出了以下 ...

  6. Python第一弹--------初步了解Python

    Python是一种跨平台的语言,这意味着它能够运行在所有主要的操作系统中. 语法规范几乎同C语言. 字符串: 当像Python输入一个字符串时,首先要输入一个引号.单引号.双引号.三引号三者等价.通常 ...

  7. python小白的初步爬虫

    前序:  最近工作不是很忙,领导突然找我谈话,说是谈话,其实就是分配活呗.果不其然,很快进入正题, 给了我一个网址链接,然后说需要商品的信息...巴拉巴拉.好吧,去做吧. 我当时的内心是崩溃的,pyt ...

  8. python 安装以及初步应用

    官网下载地址: https://www.jetbrains.com/pycharm/ Windows系统安装: https://www.jianshu.com/p/042324342bf4 mac系统 ...

  9. python的requests初步使用

    转自:http://my.oschina.net/yangyanxing/blog/280029 早就听说requests的库的强大,只是还没有接触,今天接触了一下,发现以前使用urllib,urll ...

  10. python面向对象之初步认识

    面向对象 类,用来描述一类事物的相同的特征或者属性.比如说,狗,狗属于一种统称,狗还分有不同的种类,比如,牧羊犬,蝴蝶犬,京巴等等,他们都有相同的特征,一个头,两个耳朵,四条腿,会跑,会吃东西,会汪汪 ...

随机推荐

  1. 对于for循环和while循环,两种形式的优缺点

    1.for循环 一般用于知道循环次数,并且for循环可以节省内存以及代码简洁,在循环语句中定义一个局部变量,循环结束后,局部变量就被释放了. ;val<=;val++) { sum+=val; ...

  2. hibernate一对一关联

    hibernate一对一主键关联 一对一主键关联指的是两个表通过主键形成的一对一映射. 数据表要求:A表的主键也是B表的主键同时B表的主键也是A表的外键 sql: create table peopl ...

  3. ESXi6.5中将虚拟机从厚置备转换为精简置备

    本文来自:https://blog.csdn.net/wangjingkaibear/article/details/77097041 用ESXi做虚拟化,创建了一个原始虚拟机并安装好系统做好基本设置 ...

  4. require('nw.gui') 失效问题

    // gui = global.window.nwDispatcher.requireNwGui() --original // gui = window.require('nw.gui') gui ...

  5. 关于CGI和FastCGI的理解

    在搭建 LAMP/LNMP 服务器时,会经常遇到 PHP-FPM.FastCGI和CGI 这几个概念.如果对它们一知半解,很难搭建出高性能的服务器. 0.CGI的引入 在网站的整体架构中,Web Se ...

  6. TJU Problem 1065 Factorial

    注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要. 原题: 1065.   Factorial Time Limit: 1.0 Seconds   Memory Limit ...

  7. windows dos命令

    dos命令配置环境变量: path=%path%;D:\Installed software\Professional software\Python27   (https://www.cnblogs ...

  8. sublime 自动添加兼容前缀插件autoprefixer

    安装插件autoprefixer步骤: 1.确保Node.js已经安装,未安装请 点击 这里>> 2.下载autoprefixer插件 https://github.com/sindres ...

  9. 推荐 Laravel API 项目必须使用的 8 个扩展包

    如今在现代网络开发中,比较流行的模式是基于 API 开发,可以通过手机或网站来创建服务. Laravel 是创建基于 API 的项目的最佳框架之一,它为世界各地的大型社区提供了高速开发. Larave ...

  10. silverlight 进行本地串口调用的一种可行的解决方法

    silverlight 是一个很不错的开发平台,我们可以设计出很绚丽的界面,用户可以拥有很好的体验,但是就目前来说,进行本地串口的直接调用时不行的,因为安全的原因,有没有相对简单的调用方式呢? 答案是 ...