APP自动化--Appium

环境搭建:https://www.cnblogs.com/fnng/p/4540731.html

 

 pip install Appium_Python_Client

 

1 下载安装node.js

https://nodejs.org/en/download/

链接: https://pan.baidu.com/s/1gf8fWNT 密码: vgqh

 

安装完成,打开Windows 命令提示符,敲入“npm”命令回车看是否安装成功。

npm是一个node包管理和分发工具,已经成为了非官方的发布node模块(包)的标准。有了npm,可以很快的找到特定服务要使用的包,进行下载、安装以及管理已经安装的包。

 

2.1 通过 npm 安装 appium

C:\Users\Lin>npm install -g appium

 

2.2 可以在Appium官方网站上下载操作系统相应的Appium版本。(下载最新版即可)

https://bitbucket.org/appium/appium.app/downloads/

http://pan.baidu.com/s/1jGvAISu

链接: https://pan.baidu.com/s/1dFHD0QH 密码: gkpd

 

3 安装好后双击打开,如提示要安装NET按提示跳过去下载即可

https://www.microsoft.com/net/download/dotnet-framework-runtime/net471?utm_source=getdotnet&utm_medium=referral

链接: https://pan.baidu.com/s/1o8MeQvg 密码: kzx8

 

 

安装安卓SDK

http://www.cnblogs.com/fnng/p/4552438.html

http://blog.csdn.net/dr_neo/article/details/49870587

设置变量:

 

下面设置环境变量:

 

“我的电脑”右键菜单--->属性--->高级--->环境变量--->系统变量-->新建..

 

变量名:ANDROID_HOME

 

变量值:D:\android\android-sdk-windows

 

找到path变量名—>“编辑”添加:

 

变量名:PATH

 

变量值:;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;

 

 

 

 

Appium 真机 测试

Appium环境配置好后

1 手机usb连接电脑查看设备名称

2 查看包名,Activity.

3 启动appium输入设备名

4 编写python代码

5 运行

注意:安卓机要开启usb调试模式

 

1 查看设备名称 在cmd下输入

adb devices

 

2 查看包名,Activity.

连接手机 打开手机要测的app

cmd输入下面命令

adb shell dumpsys window | findstr mCurrentFocus

 

在此记下包名和activity

 

3 启动appium输入设备名

在appium左上角安卓图标单击----选择对应的安卓版本(platform version),在name栏打勾并输入设备名(第一步),-----单击appium右上角三角运行图标。

 

4 编写python代码 并运行

#coding=utf-8
# adb shell dumpsys window | findstr mCurrentFocus
from appium import webdriver
import time


desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '76UABLGXXD67'
desired_caps['appPackage'] = 'com.meizu.flyme.calculator'
desired_caps['appActivity'] ='com.meizu.flyme.calculator.Calculator'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)


time.sleep(0.5)
driver.find_element_by_id("com.meizu.flyme.calculator:id/clear_simple").click()
driver.find_element_by_id("com.meizu.flyme.calculator:id/clear_simple").click()

driver.find_element_by_name("2").click()
driver.find_element_by_name("0").click()
driver.find_element_by_name(".").click()
driver.find_element_by_name("8").click()

driver.find_element_by_id("com.meizu.flyme.calculator:id/mul").click()

driver.find_element_by_name("2").click()
driver.find_element_by_name("5").click()

driver.find_element_by_id("com.meizu.flyme.calculator:id/eq").click()
time.sleep(0.5)
driver.find_element_by_id("com.meizu.flyme.calculator:id/clear_simple").click()

l=[1,3,1,4]
for i in l: 
	driver.find_element_by_name(str(i)).click()


driver.find_element_by_id("com.meizu.flyme.calculator:id/eq").click()
driver.quit()
	driver.find_element_by_name(str(i)).click()


driver.find_element_by_id("com.meizu.flyme.calculator:id/eq").click()
driver.quit()


点击元素定位可以借助SDK带的 uiautomatorviewer.bat 工具

 

resource-id  即 

driver.find_element_by_id("com.meizu.flyme.calculator:id/clear_simple").click()

text 即

driver.find_element_by_name("8").click()

其它详细看帮助文档

python ---  appium 帮助文档

#coding=utf-8
# adb shell dumpsys window | findstr mCurrentFocus
from appium import webdriver
import time

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '76UABLGXXD67'
desired_caps['appPackage'] = 'com.meizu.flyme.calculator'
desired_caps['appActivity'] ='com.meizu.flyme.calculator.Calculator'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)




Help on WebDriver in module appium.webdriver.webdriver object:

class WebDriver(selenium.webdriver.remote.webdriver.WebDriver)
 |  Method resolution order:
 |      WebDriver
 |      selenium.webdriver.remote.webdriver.WebDriver
 |      __builtin__.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False)
 |  
 |  activate_ime_engine(self, engine)
 |      Activates the given IME engine on the device.
 |      Android only.
 |      
 |      :Args:
 |       - engine - the package and activity of the IME engine to activate (e.g.,
 |          'com.android.inputmethod.latin/.LatinIME')
 |  
 |  app_strings(self, language=None, string_file=None)
 |      Returns the application strings from the device for the specified
 |      language.
 |      
 |      :Args:
 |       - language - strings language code
 |       - string_file - the name of the string file to query
 |  
 |  background_app(self, seconds)
 |      Puts the application in the background on the device for a certain
 |      duration.
 |      
 |      :Args:
 |       - seconds - the duration for the application to remain in the background
 |  
 |  close_app(self)
 |      Stop the running application, specified in the desired capabilities, on
 |      the device.
 |  
 |  create_web_element(self, element_id)
 |      Creates a web element with the specified element_id.
 |      Overrides method in Selenium WebDriver in order to always give them
 |      Appium WebElement
 |  
 |  deactivate_ime_engine(self)
 |      Deactivates the currently active IME engine on the device.
 |      Android only.
 |  
 |  drag_and_drop(self, origin_el, destination_el)
 |      Drag the origin element to the destination element
 |      
 |      :Args:
 |       - originEl - the element to drag
 |       - destinationEl - the eleme
  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值