from appium import webdriver
import datetime
import os
#模拟app,实现下棋,截图保存,apk地址https://github.com/Hesh233/java-demo/blob/master/Buttontest02/app/app-release.apk
def appinumTest():#设置手机设备信息desired_caps = {}desired_caps['platformName']='Android' #系统平台desired_caps['deviceName']='127.0.0.1:62001' #移动设备名称desired_caps['platformVersion']='5.1.1' #系统版本desired_caps['appPackage']='com.example.administrator.AndroidWZQ' #app包名desired_caps['appActivity']='Main2Activity' #app活动的活动名称desired_caps['app']=r'E:\git\java-demo\Buttontest02\app\app-release.apk' #应用程序的包#desired_caps['noReset']='True'  #不要停止应用程序,不要清除应用程序数据,也不要卸载apkdriver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)driver.implicitly_wait(2)  # 等待2秒driver.find_element_by_id('com.example.administrator.AndroidWZQ:id/btn1').click() #点击事件#xpath有点长,有id尽量用iddriver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[1]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.Button').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.support.v7.widget.LinearLayoutCompat/android.widget.FrameLayout/android.widget.ListView/android.widget.TextView[1]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[2]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[31]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[3]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[41]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[4]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[51]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[5]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[61]').click()driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageButton[6]').click()takeScreenShot(driver)
#带日期截图函数
def takeScreenShot(driver,name = "ScreenShot"):'''method explain:获取当前屏幕的截图parameter explain:【name】 截图的名称Usage:device.take_screenShot(u"个人主页")   #实际截图保存的结果为:2019-01-13_17_10_58_ScreenShot.png'''day = datetime.datetime.now().strftime("%Y-%m-%d")fq = "screenShots\\"+day  #fq =os.getcwd()[:-4] +'screenShots\\'+day    根据获取的路径,然后截取路径保存到自己想存放的目录下tm = datetime.datetime.now().strftime("%Y-%m-%d_%H_%M_%S")type = '.png'filename = ""if os.path.exists(fq):filename = fq+"\\"+tm+"_"+name+typeprint(filename+"exists")else:os.makedirs(fq)filename = fq+"\\"+tm+"_"+name+typeprint(filename+"else")#实际截图apidriver.get_screenshot_as_file(filename)
if __name__=='__main__':appinumTest()

python+appium例子相关推荐

  1. Python+Appium自动化测试之toast定位

    目录 一. 前言 二. 环境 三. toast定位准备与定位方法 1. 准备 2. 定位方法 四. 示例代码 一. 前言 在app自动化测试的过程中经常会遇到需要对toast进行定位,最常见的就是定位 ...

  2. [Spark][Python]sortByKey 例子

    [Spark][Python]sortByKey 例子: [training@localhost ~]$ hdfs dfs -cat test02.txt 00002 sku010 00001 sku ...

  3. ​【Python基础】告别枯燥,60 秒学会一个 Python 小例子(文末下载)

    本文推荐一个python的傻瓜式的学习资源,内容简单易懂,让人可以在60 秒学会一个 Python 小例子 当前库已有 300多 个实用的小例子 本文来源:https://github.com/jac ...

  4. 告别刷抖音!30秒一个Python小例子,总有一款适合你

    小编每天上班坐地铁,不是刷抖音就是煲电视剧,不是我不想学习,主要是短视频太好看了,30秒一个,刷刷刷的不停啊.如果Python也有30秒学习的小例子,我也一定会看呢. 于是小编收录整理了一些30秒一个 ...

  5. 安卓模拟器运行python_利用python+Appium 之 如何在设备(模拟器)上自动安装并启动APP...

    大家都知道,要测试模拟用户在手机端安装一个APP, 首先会考虑到,在什么设备下安装,设备版本是啥,设备名称是啥,我要安装啥APP.安装完毕以后我要启动和登录APP. 那如何利用python + app ...

  6. [Spark][Python]groupByKey例子

    Spark Python 索引页 [Spark][Python]sortByKey 例子 的继续: [Spark][Python]groupByKey例子 In [29]: mydata003.col ...

  7. python写appium_案例分享,Python +appium做登录功能

    原标题:案例分享,Python +appium做登录功能 Appium 是一个自动化测试开源工具,支持 iOS 平台和 Android 平台上的原生应用,同时又是一个跨平台的工具:它允许测试人员在不同 ...

  8. fasttext的基本使用 java 、python为例子

    fasttext的基本使用 java .python为例子 今天早上在地铁上看到知乎上看到有人使用fasttext进行文本分类,到公司试了下情况在GitHub上找了下,最开始是c++版本的实现,不过有 ...

  9. 告别刷抖音!30秒一个Python小例子,总有一款适合你,赶紧收藏!

    小编每天上班坐地铁,不是刷抖音就是煲电视剧,不是我不想学习,主要是短视频太好看了,30秒一个,刷刷刷的不停啊.如果Python也有30秒学习的小例子,我也一定会看呢. 于是小编收录整理了一些30秒一个 ...

最新文章

  1. 为什么使用HashMap需要重写hashcode和equals方法_为什么要重写 hashcode 和 equals 方法?...
  2. 如何知道刚刚插入数据库那条数据的id
  3. 填充磁盘空间的工具和方法
  4. 基于Pytorch再次解析AlexNet现代卷积神经网络
  5. 计算机专业的个人实习报告范文,大学计算机专业的个人实习报告范文
  6. 做出的一个图片的自动展示效果(JS版本)
  7. SAP Commerce Cloud Spartacus UI footer 区域的设计模型
  8. 嵌入式软件工程师2021面试指南【转】
  9. 编译性语言、解释性语言和脚本语言
  10. 打印n×n数字方阵python_2020华为春招amp;#8211;N阶方阵旋转(python) - 易采站长站
  11. java适配器模式_适配器模式的设计,你get到了吗?
  12. 【java笔记】File类(3):FileFilter文件过滤器原理和使用
  13. 【转】理清基本的git(github)流程
  14. 编译Android源码:Exception in thread main java.lang.UnsupportedClassVersionError:报错解决
  15. php l框架,一个很简单的PHP框架lyue
  16. stc单片机id加密c语言,STC单片机使用加密芯片SMEC98SP的加密实例源码
  17. html常见基础标签大汇总
  18. 博弈论 | 博弈论简谈、常见的博弈定律、巴什博弈
  19. 李学龙当选美国计算机杰出科学家的报道,我校李学龙教授当选美国医学与生物工程院会士...
  20. 怎样将优酷网站下载的视频KUX转MP4格式

热门文章

  1. OPPO救砖通用:oppo A33T(移动定制版)黑砖救砖
  2. 行政公益诉讼与民事公益诉讼可相互转化
  3. 【从入门到精通 项目1】项目经理带你-零基础学习C/C++
  4. 《“通用语”与“兽人语”互译手册》(全集)
  5. 6.3 Faddeev-Leverrier算法求特征多项式
  6. Python整数进制间转换
  7. 二度云抢先成为首批工信部(.vip/.xyz/.club)域名注册管理机构
  8. 闪光灯 flash 问题
  9. Flutter第一部分(UI)第五篇:为Widget添加交互
  10. 【mmaction2 入门教程 01】 slowfast训练配置 日志分析 测试结果分析