method one:
That is the familiar you install Android sdk E: \ Android \ uiautomatorviewer.bat under android-sdk \ tools directory can simply double-click to open the phone positioning elements
There is a problem:
(1) adb version can not be too low
(2) For the high version of Android phone (Android 9.0 I encountered life and death Rom), unable to connect unable to locate
Second way:
Premise: you need to install java jdk
(1) installed SDK
Download Android SDK (need to install sdk):
http://tools.android-studio.org/index.php/sdk
You need to add environment variables in the system variable (is new)
ANDROID_HOME D: \ android \ Android \ sdk (do not write their own copy of the address)
(2) Installation appium-server
https://bitbucket.org/appium/appium.app/downloads/ installation package Address:
Installed in the command window: appium-doctor inspection environment (prior to installation to ensure that two or more java jdk installed)
Appear all checks were successful is correct
1, the installation WEditor: enter cmd, enter PIP the install --pre --upgrade weditor
2, open WEditor: In cmd, enter python -m weditor, this time will automatically open the default browser
weditor problems may be installed on python2.7
Three ways:
appiun-desk
Add your startup configuration click on the + sign after the start
For chestnut:
{
"PlatformName": "Android", # phone system
"platformVersion": "9", # Android version
"deviceName": "2f7e2ac9", #devices name to get adb devices can be found in
"noReset": "true", # regardless
"packageName": "com.oppopay.payments", the name of the package to be tested, application #
"app": absolute path: "E \\ Apitest \\ Finshell_memory \\ Finshell_15_11_2019_UAT_v25.apk", # test application
"automationName": "uiautomator" # start
}
After everything is ok click start session (appium need to start this before starting) This thing is to appium services must first be opened.
元素三种定位工具都讲完了,试下吧。。。
ps 关于滑动操作:
(1)才用appium时
分享一个公共函数:
# coding=utf-8
# 跳过浏览器引导
import time
class swipe(object):
def __init__(self, driver):
self.driver = driver
self.width = self.driver.get_window_size()['width']
self.height = self.driver.get_window_size()['height']
def swipetoUp(self):
time.sleep(10)
self.driver.swipe(self.width / 2, self.height * 3 / 4,
self.width / 2, self.height / 4, 0)
def swipetoDown(self):
time.sleep(5)
self.driver.swipe(self.width / 2, self.height / 3,
self.width / 2, self.height * 3 / 4, 0)
def swipetoLeft(self):
time.sleep(5)
self.driver.swipe(self.width * 0.9, self.height / 2,
self.width * 0.1, self.height / 2, 0)
def swipetoRight(self):
time.sleep(5)
self.driver.swipe(self.width * 0.1, self.height / 2,
self.width * 0.9, self.height / 2, 0)
appium启动应用 时:
# -*- coding: utf-8 -*-
from appium import webdriver
class startSession(object):
def __init__(self,desired_caps):
self.desired_caps = desired_caps
def run(self):
print '******* StartSession ******'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.desired_caps)
return self.driver
def desired_caps():
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7.1.1'
desired_caps['automationName'] = "uiautomator2"
desired_caps['deviceName'] ='2f7e2ac9'#YDBUJNYL8SNNPZGE 2f7e2ac9
desired_caps['noReset'] = 'true'
desired_caps['appActivity'] ='com.pay.payments.ui.activity.SplashActivity'
desired_caps['androidDeviceReadyTimeout'] = '180'
desired_caps['appPackage'] ='com.pay.payments'
return desired_caps
拿封装两个函数来启动
具体使用就是:
要导入这两个函数进来
driver = startSession(desired_caps()).run()
一行就搞定了启动应用
下面就是u2了
个人感觉做ui自动化 u2简单多了
启动应用
import uiautomator2 as u2
d = u2.connect()
# d.app_start('com.pay.payments') # 第二种启动app的方式
d.session('com.pay.payments') # 第三种启动app的方式
一句话就启动了应用对于appium 优势很明显。
但是u2对于appium 滑动操作比较麻烦:
d = u2.connect()
d(scrollable=True).scroll.to(text='Next')
这是我找到一个很好方式 滑动这个指定 内容的地方 以上就是滑动到Next 这里 页面会首先向上 然后向下找。