Appium_desktop
tags (space delimited): Appium_desktop
A appium_desktop_v1.2.6
1.appium_desktop on GitHub Latest: Appium Desktop version Address
2. All-in-a-kind installation is good:
3. Then click the Search button (upper right corner)
Three Inspector
1. Element positioning detector, in desired capabilitis the table input parameter configuration information:
"platformName": "Android", "deviceName": "8681-M02-0x253b1876", "platformVersion": "5.1", "appPackage": "com.zhan.toefltom", "appActivity": "com.zhan.toefltom.SplashActivity", "app": "F:\\特殊处理包H5\\toefl_V2.1.0_071610_release.apk"
2. After the configuration of the parameters can be saved, connect the phone, and then click the Start Session button to locate the element
3. Use the arrow buttons in the navigation bar to locate the element properties of the app on the left
Four pop-up boxes of pits
1. There is a pit where the elements of this popup cannot be located and need the UI Automator viewer tool to navigate to
Five-contrast analysis
Inspector Advantages
Appium with the inspector can see the XPath path, compared to the XPath unfamiliar classmates can be very good to help
Inspector Disadvantages
1. Some popup elements cannot be located in the
2. Overly dependent tools matching XPath will make you lazy and become dependent on the tool.
Summary: XPath is actually the next way of positioning, can not use as much as possible, and do not have to copy the XPath paste, that to you to locate a little help is not, want to use the XPath classmate, learn more grammar, write to yourself!
Six: If the positioning process you use all the tricks are unable to locate the element:
So: it is necessary to use coordinates to locate the
Seven: positioning coordinates
We can see the properties of the corresponding coordinates
Android-specific wait_activity properties
When you start the app, if you do the next click, you will often get an error, so we will add sleep when the boot is complete.
So the question is, how much is this sleep time setting? Set long, waste time, set short, will not find the element error, this time we can use wait_activity syntax, wait until you want to click on the page activity appeared, and then click, you can effectively save time.
- Wait_activity (self, activity, timeout, interval=1):
Waits for the specified activity to appear until time-out, interval to scan interval of 1 seconds
That is, every few seconds to get the current activity, Android-specific
True or False to return
Activity-the target activity to be waited on
- Timeout-Maximum time-out, unit is s
- Interval-Cycle query time
Usage: driver.wait_activity ('. Activity.xxx ', 5,2)
- Ii. acquisition of Current_activity
1. After opening the app, sleep10 seconds, and so on, the app completely starts to go to the main page, then gets the activity of the current interface.
from appium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitimport timefrom time import sleepimport datetimedesired_caps = { "platformName": "Android", "deviceName": "8681-M02-0x253b1876", "platformVersion": "5.1", "appPackage": "com.zhan.toefltom", "appActivity": "com.zhan.toefltom.SplashActivity"}driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)ac =driver.current_activityprint(ac)
Waiting for activity
1. Use sleep too wasted time, and do not know when to start the completion, so try not to sleep
2. The previous step has been obtained when the main page of activity, then you can use wait_activity wait for it to appear, and then do the next click action
The new version of Appium does not support name positioning:
- First, name location error
1. The latest version of Appium V1.7 with name, error:
Selenium.common.exceptions.InvalidSelectorException:Message:Locator strategy ' name ' is not supported for this session
2. This error means that the "name" method is currently unsupported because Appium has abandoned the location method of name since the 1.5 version.
- Second, XPath positioning
1. Since the name positioning is abandoned, it means that there is a more advanced positioning instead of it, in fact, the XPath location contains the name of the positioning method.
- 2. Usually used selenium, when positioning the text on the page, you should know this XPath syntax:
//*[text()='页面text文本']
The XPath syntax inside the appium is a little different from the selenium:
//*[@text='页面text文本']
- Third, the Text property
1. The above XPath syntax is appropriate for this text property on the page, so it's only right to navigate directly to it, so the question is: What if there are multiple text properties on the page?
2.xpath syntax inside * is to match any value, in Selenium * is to match any tag, Appium * is to match any class name, if a few text class attribute is different, you can use the following combination:
//android.widget.TextView[@text='小说']
Toast Prompt Message judgment
- 1. View Appium v1.7 version official documentation
2.1.7 of the current Android version can support: Espresso, UiAutomator2, Uiautomator, selendroid four drive modes
UiAutomator2 is now the most stable.
- Second, toast positioning
1. First look at what the toast looks like, such as the pop-up message "Press again to exit", this is toast.
2. To locate a toast prompt:
Need:
from appium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom time import sleepdesired_caps = { 'platformName': 'Android', 'deviceName': '***', 'platformVersion': '4.4.2', 'appPackage': '*****', 'appActivity': '****', 'noReset': 'true', 'automationName': 'Uiautomator2' }driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)# 等主页面activity出现driver.wait_activity(".****", 10)driver.back() # 点返回# 定位toast元素toast_loc = ("xpath", ".//*[contains(@text,'再按一次退出')]")t = WebDriverWait(driver, 10, 0.1).until(EC.presence_of_element_located(toast_loc))print t
Above: * * * Fill in your own content in self-test
3. Printed results, the following information appears, indicating that the toast is located
<appium.webdriver.webelement.webelement (session= "02813cce-9aaf-4754-a532-07ef7aebeb88", element= " 339f72c4-d2e0-4d98-8db0-69be741a3d1b ") >
Encapsulating Toast Judgment:
1. Sometimes we need to encapsulate a method individually to determine if a toast exists, that there is a return of true, that there is no return false
3. Printed results, the following information appears, indicating that the toast is located
def is_toast_exist(driver,text,timeout=30,poll_frequency=0.5):# driver - 传driver#text - 页面上看到的文本内容 #timeout - 最大超时时间,默认30s #poll_frequency - 间隔查询时间,默认0.5s查询一次try: toast_loc = ("xpath", ".//*[contains(@text,'%s')]"%text) WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc)) return True except: return Falseif __name__ == "__main__": driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) # 等主页面activity出现 driver.wait_activity(".base.ui.MainActivity", 10) driver.back() # 点返回 # 判断是否存在toast-'再按一次退出' print is_toast_exist(driver, "再按一次退出")
List locator:
When you locate the element when you find that the page element is not unique, how to do, at this time we can be find_elements and so on the list to get the value of their own desired elements, and then to operate;
Find_element has 13 types of positioning
There are also 13 kinds of find_elements
driver.find_elements_by_id("***")[0].click()
Android_uiautomator
- Appium's predecessor is to encapsulate the Android Uiautomator this framework, so uiautomator some of the positioning methods can also be used;
Text
1. Text positioning syntax
New Uiselector (). Text ("text literal")
2. When the text is longer, you can use textcontains fuzzy matching, as long as the text contains matching content.
New Uiselector (). Textcontains ("contains text")
3.textStartsWith is a match at the beginning of a text
New Uiselector (). Textstartswith ("Start with text text")
4. Regular matching textmatches, this need to match the regular expression, it is not an example.
New Uiselector (). Textmatches ("Regular expression")
#等主页面activity出现driver.wait_activity(".base.ui.MainActivity", 10)loc_text = 'new UiSelector().text("图书")'#text内容driver.find_element_by_android_uiautomator(loc_text).click()loc_textContains = 'new UiSelector().textContains("图")'#textContainsdriver.find_element_by_android_uiautomator(loc_textContains).click()loc_textStart = 'new UiSelector().textStartsWith("图")'#textStartsWithdriver.find_element_by_android_uiautomator(loc_textStart).click()
ClassName
1. The class attribute on the page is generally not unique and is mostly used in complex location. For example, by using the class attribute to position the ' rank ' button subscript is 2.
New Uiselector (). ClassName ("ClassName")
2.className complex positioning loc_class = ' new Uiselector (). ClassName ("Android.widget.TextView") ' Driver.find_elements_by_android _uiautomator (Loc_class) 2.click ()
3.escription
1. Since the Contenet-des property of this app is empty, it is not necessary to demonstrate the code, as in the above method.
New Uiselector (). Description ("Contenet-des property")
Android_uiautomator Positioning Advanced
The previous introduction of Uiautomator is similar to this ' new Uiselector (). XXX ("xxx") ', look very long, I also can't remember, how to remove it?
First, the combination of positioning
1. General combination with Id,class,text these three properties will be a bit better, followed by description This attribute can also be 22 combination
2.id and Text property combination
2.id and Text property combination
# id+textid_text = 'resourceId("com.baidu.yuedu:id/webbooktitle").text("小说")'driver.find_element_by_android_uiautomator(id_text).click()
3.class and Text property combination
sleep(2)#class+textclass_text = 'className("android.widget.TextView").text("图书")'driver.find_element_by_android_uiautomator(class_text).click()
4. Other combinations, Id,class can also be combined with other index,checkable,clickable,password such as these infrequently used attributes.
Second, parent-child positioning Childselector
1. Sometimes it is not possible to directly locate an element, but its parent element is well positioned, this time the parent element is positioned first, the parent element to find the son.
#父子关系childSelectorson = 'resourceId("com.baidu.yuedu:id/rl_tabs").childSelector(text("小说"))'driver.find_element_by_android_uiautomator(son).click()
Iii. positioning of the brothers:
# 兄弟关系fromParentbrother = 'resourceId("com.baidu.yuedu:id/lefttitle").fromParent(text("图书"))'driver.find_element_by_android_uiautomator(brother).click()
Long-Press operation:
Long Press Long_press
1. Long-press operation can be done using the Long_press method in the Touchaction class mentioned above
def long_press(self, el=None, x=None, y=None, duration=1000):? ? ? ? 长按操作,可以传定位的元素对象,也可以传坐标? ? ? ? el 是定位元素的对象? ? ? ? x,y是传坐标? ? ? ? duration是按住的持续时间,默认1000,单位是毫秒??
2. Implementation methods
TouchAction(driver).long_press(el).perform()#长按
el = driver.find_elements_by_id("com.tencent.mm:id/apv")[0]# 长按TouchAction(driver).long_press(el).perform()time.sleep(3)
Appium Desktop version and some automated test party packages