码迷,mamicode.com
首页 > 移动开发 > 详细

Appium

时间:2019-03-07 10:21:44      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:dev   lap   官网   list   path   desktop   配置环境   anim   地址   

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)

 

import time
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

server = ‘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 = 300
FLICK_START_Y = 300
FLICK_DISTANCE = 700

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

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

Appium

标签:dev   lap   官网   list   path   desktop   配置环境   anim   地址   

原文地址:https://www.cnblogs.com/du-jun/p/10487838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!