出處:http://testerhome.com/topics/1034
創(chuàng)新互聯(lián)建站服務(wù)項目包括冷水江網(wǎng)站建設(shè)、冷水江網(wǎng)站制作、冷水江網(wǎng)頁制作以及冷水江網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,冷水江網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到冷水江省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
最近 Appium 引入了一個新的 find element
方法:python client
為例
def find_element_by_accessibility_id(self, id): """Finds an element by accessibility id. :Args: - id - a string corresponding to a recursive element search using the Id/Name that the native Accessibility options utilize :Usage: driver.find_element_by_accessibility_id() """ return self.find_element(by=By.ACCESSIBILITY_ID, value=id)
文檔里是這樣說的:
Allows for elements to be found using the "Accessibility ID". The methods take a
string representing the accessibility id or label attached to a given element, e.g., for iOS the accessibility identifier and for Android the content-description. Adds the methodsdriver.find_element_by_accessibility_id
andfind_elements_by_accessibility_id
.
意思就是可以使用 "Accessibility ID" 來定位元素。對于 iOS 而言就是 accessibility identifier。
對于 Android 就是 content-description
。
content-description
呢?官方是這樣說的:
http://developer.android.com/training/accessibility/accessible-app.html
Android has several accessibility-focused features baked into the platform, which make it easy to optimize your application for those with visual or physical disabilities. However, it's not always obvious what the correct optimizations are, or the easiest way to leverage the framework toward this purpose. This lesson shows you how to implement the strategies and platform features that make for a great accessibility-enabled Android application.
這個屬性,主要是為了一些有殘障的人士準(zhǔn)備的,方便他們使用程序,所以這個警告前面會有一個[Accessbility]。
舉個例子,比如你有個 ImageView
放一張圖片,這個圖片可能包含很多物體和顏色,一些色弱或者色盲的人,他們可能會分不清這個圖到底畫的什么東西,所以這個時候 contentDescription
就會起作用。比如可能 Android 的一些程序可以用聲音告訴使用者這個圖片畫的是什么,他們讀的就是你 contentDescription
的內(nèi)容。
這其實和 iOS 的 accessibility identifier
是一樣的。
給一些需要加 contentDescription 的控件加 contentDescription 是一個良好的編程習(xí)慣,事實上 , ADT 的 Lint 檢測也會提示你:
[Accessibility] Missing contentDescription attribute on image
所以給你的控件加上 android:contentDescription="@string/desc
, 這樣也可以讓 Appium 來定位。
myView.setContentDescription(desc);
appium sample-code 里面的 android_complex.py 實際上得用 https://github.com/appium/android-apidemos 這個project 來導(dǎo)出 apk 來測試。
def test_find_elements(self): # pause a moment, so xml generation can occur sleep(2) els = self.driver.find_elements_by_xpath('//android.widget.TextView') self.assertEqual('API Demos', els[0].text) el = self.driver.find_element_by_xpath('//android.widget.TextView[contains(@text, "Animat")]') self.assertEqual('Animation', el.text) el = self.driver.find_element_by_accessibility_id("App") el.click() els = self.driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)') # there are more, but at least 10 visible self.assertLess(10, len(els)) # the list includes 2 before the main visible elements self.assertEqual('Action Bar', els[2].text) els = self.driver.find_elements_by_xpath('//android.widget.TextView') self.assertLess(10, len(els)) self.assertEqual('Action Bar', els[1].text)
試用了下 genymotion, 非常好用,用來做 Appium 實驗很棒。
使用模擬器的時候遇到了個問題:
java.lang.IllegalArgumentException: eglChooseConfig failed EGL_NOT_INITIALIZED 03-29 13:21:34.556: E/AndroidRuntime(4458): FATAL EXCEPTION: main 03-29 13:21:34.556: E/AndroidRuntime(4458): Process: com.example.news, PID: 4458 03-29 13:21:34.556: E/AndroidRuntime(4458): java.lang.IllegalArgumentException: eglChooseConfig failed EGL_NOT_INITIALIZED 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.HardwareRenderer$GlRenderer.chooseEglConfig(HardwareRenderer.java:1173) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.HardwareRenderer$GlRenderer.loadEglConfig(HardwareRenderer.java:1135) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.HardwareRenderer$GlRenderer.initializeEgl(HardwareRenderer.java:1117) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:1057) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1550) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.Choreographer.doFrame(Choreographer.java:544) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.os.Handler.handleCallback(Handler.java:733) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.os.Handler.dispatchMessage(Handler.java:95) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.os.Looper.loop(Looper.java:136) 03-29 13:21:34.556: E/AndroidRuntime(4458): at android.app.ActivityThread.main(ActivityThread.java:5017) 03-29 13:21:34.556: E/AndroidRuntime(4458): at java.lang.reflect.Method.invokeNative(Native Method) 03-29 13:21:34.556: E/AndroidRuntime(4458): at java.lang.reflect.Method.invoke(Method.java:515) 03-29 13:21:34.556: E/AndroidRuntime(4458): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 03-29 13:21:34.556: E/AndroidRuntime(4458): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 03-29 13:21:34.556: E/AndroidRuntime(4458): at dalvik.system.NativeStart.main(Native Method)
Google了一下,關(guān)聯(lián)到了opengl es,這個了解過,初步懷疑不是我應(yīng)用的問題,最后查得居然是模擬器的問題,重啟后解決問題。
分享名稱:[content-description]find_element_by_accessibility_id在android中的詳解
鏈接URL:http://jinyejixie.com/article8/psheop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、云服務(wù)器、網(wǎng)站設(shè)計、網(wǎng)站導(dǎo)航、搜索引擎優(yōu)化、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)