博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Appium
阅读量:6995 次
发布时间:2019-06-27

本文共 6524 字,大约阅读时间需要 21 分钟。

appium的安装

官网:

http://appium.io

下载地址:

https://github.com/appium/appium-desktop/releases/tag/v1.8.2

linux,mac配置环境变量:

sudo vim /etc/hosts

export ANDROID_HOME=/Users/seancheney/Library/Android/sdk

export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH

 

python安装appium api:

pip install Appium-Python-Client

adb查看设备名:

adb devices -l
bb43c0d0 device product:kenzo model:Redmi_Note_3

WiFi连接手机

开启端口(端口不能被占用)
adb -s bb43c0d0 tcpip 5556
开启连接
adb connect 192.168.2.181:5556

adb命令查看包名:

adb shell pm list packages

package:com.pandavisa 

package:com.qrd.omadownload 
package:com.android.providers.telephony

 

# 查看appActivity

1、cmd命令中输入:adb shell 进入shell命令模式
2、shell中输入:logcat | grep ActivityManager 真机运行应用,可以实时 查看当前正在运行的Activity;

 

appium的使用

初始化

# Android environment

from appium import webdriver

desired_caps = {}

desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.1'
desired_caps['automationName'] = 'uiautomator2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')

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

 

# 查找元素

el = self.driver.find_element_by_android_uiautomator('new UiSelector().description("Animation")')
els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')

el = self.driver.find_element_by_android_viewtag('a tag name')

els = self.driver.find_elements_by_android_viewtag('a tag name')

# 点击
tap()
click()

# 动作链

el = self.driver.find_element_by_accessibility_id('Animation')
action = TouchAction(self.driver)
action.tap(el).perform()

# 多动作
els = self.driver.find_elements_by_class_name('listView')
a1 = TouchAction()
a1.press(els[0]) \
.move_to(x=10, y=0).move_to(x=10, y=-75).move_to(x=10, y=-600).release()

a2 = TouchAction()

a2.press(els[1]) \
.move_to(x=10, y=10).move_to(x=10, y=-300).move_to(x=10, y=-600).release()

ma = MultiAction(self.driver, els[0])

ma.add(a1, a2)
ma.perform();

# 拖动
driver.swipe

FLICK_START_X = 300

FLICK_START_Y = 300
FLICK_DISTANCE = 700

def scroll(self):

while True:
self.driver.swipe(FLICK_START_X, FLICK_START_Y + FLICK_DISTANCE, FLICK_START_X, FLICK_START_Y)
sleep(2)

 

appium

Appium是一个开源测试自动化框架,可用于原生,混合和移动Web应用程序测试。 它使用WebDriver协议驱动iOS,Android应用程序。

 

C:\Users\Administrator\AppData\Local\Android\Sdk\build-tools\28.0.3>aapt.exe dump badging G:\安装包!!!!!!!!!!!!!!!!!!!!\安卓\app\com.tal.kaoyan_3.3.5.2_liqucn.com.apk

 

或者

第二个方法

然后启动app

{  "platformName": "Android",  "deviceName": "127.0.0.1:62001",  "platformVersion": "5.1.1",  "appPackage": "com.tal.kaoyan",  "appActivity": "ui.activity.SplashActivity",  "noReset": true}

怎么使用Uiautomatorviewer获取元素的xpath

http://www.bubuko.com/infodetail-2259722.html uiautomatorviewer.bat 关闭appium后才能进去

 

 

 

 

appium的应用,进入新闻app并不断下滑

先在模拟机设置里 清空app的数据

import timefrom appium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECserver = 'http://localhost:4723/wd/hub'desired_caps = {    "platformName": "Android",    "deviceName": "Redmi_Note_3",    "appPackage": "com.android36kr.app",    "appActivity": ".ui.MainActivity"}print('111')driver = webdriver.Remote(server, desired_caps)print('222')wait = WebDriverWait(driver,30)print('333')kuaixun = wait.until(EC.presence_of_element_located((By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[1]/android.view.ViewGroup/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.TextView[3]')))kuaixun.click()FLICK_START_X = 300FLICK_START_Y = 300FLICK_DISTANCE = 700while True:    driver.swipe(FLICK_START_X, FLICK_START_Y + FLICK_DISTANCE, FLICK_START_X, FLICK_START_Y)    time.sleep(2)

模拟登陆app并滑动

#需要安装客户端的包#pip3 install Appium-Python-Clientimport timefrom appium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitcap = {  "platformName": "Android",  "deviceName": "127.0.0.1:62001",  "platformVersion": "5.1.1",  "appPackage": "com.tal.kaoyan",  "appActivity": "ui.activity.SplashActivity",  "noReset": True}driver = webdriver.Remote("http://localhost:4723/wd/hub",cap)def get_size():    x = driver.get_window_size()['width']    y = driver.get_window_size()['height']    return(x,y)try:    #是否跳过    if WebDriverWait(driver,3).until(lambda x:x.find_element_by_xpath("//android.widget.TextView[@resource-id='com.tal.kaoyan:id/tv_skip']")):        driver.find_element_by_xpath("//android.widget.TextView[@resource-id='com.tal.kaoyan:id/tv_skip']").click()except:    passtry:    if WebDriverWait(driver,3).until(lambda x:x.find_element_by_xpath("//android.widget.EditText[@resource-id='com.tal.kaoyan:id/login_email_edittext']")):        driver.find_element_by_xpath("//android.widget.EditText[@resource-id='com.tal.kaoyan:id/login_email_edittext']").send_keys("a349553119")        driver.find_element_by_xpath("//android.widget.EditText[@resource-id='com.tal.kaoyan:id/login_password_edittext']").send_keys("a123456")        driver.find_element_by_xpath("//android.widget.Button[@resource-id='com.tal.kaoyan:id/login_login_btn']").click()except:    passtry:    #隐私协议    if WebDriverWait(driver,3).until(lambda x:x.find_element_by_xpath("//android.widget.TextView[@resource-id='com.tal.kaoyan:id/tv_title']")):        driver.find_element_by_xpath("//android.widget.TextView[@resource-id='com.tal.kaoyan:id/tv_agree']").click()        driver.find_element_by_xpath("//android.support.v7.widget.RecyclerView[@resource-id='com.tal.kaoyan:id/date_fix']/android.widget.RelativeLayout[3]").click()except:    pass#点击研讯if WebDriverWait(driver,3).until(lambda x:x.find_element_by_xpath("//android.support.v7.widget.RecyclerView[@resource-id='com.tal.kaoyan:id/date_fix']/android.widget.RelativeLayout[3]/android.widget.LinearLayout[1]/android.widget.ImageView[1]")):    driver.find_element_by_xpath("//android.support.v7.widget.RecyclerView[@resource-id='com.tal.kaoyan:id/date_fix']/android.widget.RelativeLayout[3]/android.widget.LinearLayout[1]/android.widget.ImageView[1]").click()    l = get_size()    x1 = int(l[0]*0.5) #滑动位置    y1 = int(l[1]*0.75) #从哪滑动    y2 = int(l[1]*0.25) #滑到哪个位置    #滑动操作    while True:        driver.swipe(x1,y1,x1,y2)        time.sleep(0.5)

  

 

Android studio安装与配置

https://www.jianshu.com/p/3aac8eace376

转载于:https://www.cnblogs.com/du-jun/p/10487838.html

你可能感兴趣的文章
我的友情链接
查看>>
Z字形扫描(201412-2)
查看>>
linux rpm安装webmin
查看>>
DDOS***原理与防护
查看>>
懒加载 与 富文本编辑器 的 相爱相杀
查看>>
我的友情链接
查看>>
java转换是json需要的jar包导致的问题,
查看>>
mac安装brew和nginx
查看>>
技术博客
查看>>
关于ssh远程登录太慢的解决方法
查看>>
子类化QMainWindows
查看>>
Windows完成端口 IOCP模型(一)
查看>>
修改roo的密码 虚拟机vmware8.04 Centos 6.3
查看>>
Struts2 注解
查看>>
有关xerosploit运行报错问题的有效解决方案
查看>>
ABP官方文档翻译 1.4 启动配置
查看>>
js框架简明
查看>>
Java volatile 关键字
查看>>
http 头信息详解
查看>>
ATS项目更新(4) 更新DLL到远程服务器
查看>>