1. 程式人生 > >Appium 用了 AppiumDriver 後,WebDriverWait 中無法使用 AppiumDriver 特有的方法

Appium 用了 AppiumDriver 後,WebDriverWait 中無法使用 AppiumDriver 特有的方法

用了AppiumDriver後,WebDriverWait中無法使用AppiumDriver特有的方法,比如findElementsByAndroidUIAutomator等。這是由於

WebDriverWait繼承與FluentWait,而WebDriver介面是沒有定義findElementsByAndroidUIAutomator的,所以如果想用類似WebDriverWait的功能,就必須做些封裝。

package com.merlini.app.common;

import io.appium.java_client.AppiumDriver;

import java.util.concurrent.TimeUnit
; import org.openqa.selenium.NotFoundException; import org.openqa.selenium.support.ui.Clock; import org.openqa.selenium.support.ui.FluentWait; import org.openqa.selenium.support.ui.Sleeper; import org.openqa.selenium.support.ui.SystemClock; import org.openqa.selenium.support.ui.WebDriverWait; import
com.merlini.common.Config; public class AppiumDriverWait extends FluentWait<AppiumDriver>{ //預設輪詢時間(毫秒) public final static long DEFAULT_POLLINGEVERY_TIMEMILLS = Integer.parseInt(Config.getConfBykey("wait.sleepInMillis")); public final static long DEFAULT_TIMEOUT_INSECONDS = Integer
.parseInt(Config.getConfBykey("wait.TimeOutInSeconds")); /** * Wait will ignore instances of NotFoundException that are encountered (thrown) by default in * the 'until' condition, and immediately propagate all others. You can add more to the ignore * list by calling ignoring(exceptions to add). * * @param driver The AppiumDriver instance to pass to the expected conditions * @see WebDriverWait#ignoring(java.lang.Class) */ public AppiumDriverWait(AppiumDriver driver) { this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, DEFAULT_TIMEOUT_INSECONDS, DEFAULT_POLLINGEVERY_TIMEMILLS); } /** * Wait will ignore instances of NotFoundException that are encountered (thrown) by default in * the 'until' condition, and immediately propagate all others. You can add more to the ignore * list by calling ignoring(exceptions to add). * * @param driver The AppiumDriver instance to pass to the expected conditions * @param timeOutInSeconds The timeout in seconds when an expectation is called * @see WebDriverWait#ignoring(java.lang.Class) */ public AppiumDriverWait(AppiumDriver driver, long timeOutInSeconds) { this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, timeOutInSeconds, DEFAULT_POLLINGEVERY_TIMEMILLS); } /** * Wait will ignore instances of NotFoundException that are encountered (thrown) by default in * the 'until' condition, and immediately propagate all others. You can add more to the ignore * list by calling ignoring(exceptions to add). * * @param driver The WebDriver instance to pass to the expected conditions * @param timeOutInSeconds The timeout in seconds when an expectation is called * @param sleepInMillis The duration in milliseconds to sleep between polls. * @see WebDriverWait#ignoring(java.lang.Class) */ public AppiumDriverWait(AppiumDriver driver, long timeOutInSeconds, long sleepInMillis) { this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, timeOutInSeconds, sleepInMillis); } protected AppiumDriverWait(AppiumDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds, long sleepTimeOut) { super(driver, clock, sleeper); withTimeout(timeOutInSeconds, TimeUnit.SECONDS); pollingEvery(sleepTimeOut, TimeUnit.MILLISECONDS); ignoring(NotFoundException.class); } }
轉載於:TesterHome https://testerhome.com/topics/1206
package com.merlini.app.common;

import io.appium.java_client.AppiumDriver;

import com.google.common.base.Function;

public interface AppiumExpectedCondition<T> extends Function<AppiumDriver,T>{

}

這樣就可以 AppiumDriverWait 代替WebDriverWait
如:

/**
     * 根據控制元件description抓取批量元素
     * @param elementType
     * @param desc
     * @return
     */
    public List<WebElement> findElementsByDescription(final String elementType,final String desc){
        AppiumDriverWait wait=new AppiumDriverWait(driver);
        List<WebElement> ele= wait.until( new AppiumExpectedCondition<List<WebElement>>(){
            public List<WebElement> apply(AppiumDriver driver){
                return driver.findElementsByAndroidUIAutomator("new UiSelector().className(\"android.widget."+elementType+"\").description(\""+desc+"\")");
            }
        });
        return ele;//driver.findElementsByAndroidUIAutomator("new UiSelector().className(\"android.widget."+elementType+"\").description(\""+desc+"\")"); 
    }

相關推薦

Appium AppiumDriver WebDriverWait 無法使用 AppiumDriver 特有方法

用了AppiumDriver後,WebDriverWait中無法使用AppiumDriver特有的方法,比如findElementsByAndroidUIAutomator等。這是由於 WebDriverWait繼承與FluentWait,而WebDriver介面是沒有

安裝jdk原先jdk無法使用的情況

錯誤:weblogic.server is not support jdk less than 1.7錯誤。由於專案問題,原先開發環境的jdk版本是1.8,後來安裝了jdk1..7.安裝完成之後,系統為jdk1.7。想切回1.8,環境變數都沒有問題。通過查詢發現如下,成功。

資料庫Timestamp格式String接收尾巴多.0

資料庫中為:欄位:time   值:2016-06-06 16:13:12 java中用String接收後顯示為:2016-06-06 16:13:12.0 解決方法: 1、select 語句中對欄位使用函式DATE_FORMAT,如下: select 

WPF自定義控制元件使用RadioButton多次使用該控制元件出現的死迴圈解決方法

最近在專案中需要用到RadioButton,所以在自定義控制元件中使用了一組RadioButton,使用一個預設的groupname,也就是這個goupname給後來的問題埋下了地雷。 定義大致如下: <Grid> <Label Height ="50" W

檔案屬性改不(解決完病毒屬性的隱藏灰色選不

開始---執行裡輸入--- CMD, 在彈出的命令提示符內輸入: attrib -r -h 路徑(你要修改的檔案或資料夾) 例如:你要修改的D:\a attrib -r -h D:\a 如果修改所有檔案可以 attrib -r -h D:\*

使用express搭建框架multer處理post請求傳的檔案或圖片注意的問題

node中處理post請求,只有body-parser是不夠的,當上傳的是圖片或者是檔案時,就要用multer來處理 注意的問題: 1.如果在app.js中引入multer,如法根據請求的路由分別處理,所以要在路由配置中,根據需要使用multer 首先引入

在pfsense設置多WAN網銀無法登陸的解決!

pfsense 多wan 網銀 無法訪問在pfsense中設置多WAN後,網銀登陸一般會失效。出現這個問題原因大多是網銀的安全機制問題 ,銀行網站訪問不允許登陸用戶的IP地址短時間發生變化。解決辦法是指定網銀訪問的443端口流量走某一個固定的網關。下面以pfsense2.34的設置為例:設置好的規則如下:20

TCPL對C C++書籍的一些想法

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

電腦一開機記憶體(共8G)就70%以上工作管理員裡面檢視沒有佔用記憶體很高的程序原來是驅動問題

現象描述:        出現兩次這個問題,都是長時間開機後,出現記憶體佔用很高,重啟還是記憶體佔用很高,而且工作管理員裡面檢視,實際沒有程序佔用那麼高。 曾經試過很多種辦法,但是一樣的現象卻有不同的原因。 比如試過停掉superf

appium 連結真機執行程式碼但是APP並沒有啟動

要淡定,連結真機後,問題一下多出來這麼多,還沒有啟動程式,就碰到接二連三的問題。 爽到家了。慢慢解決吧。 具體問題是這樣的: # coding=utf-8from appium import webdriverimport timefrom selenium.common.exceptions impo

SpringBoot專案攔截器通過流獲取Request請求物件的引數控制器@RequestBody註解引數獲取不到

一、場景     第一次搭建專案開發環境,需要在專案中實現日誌攔截器,用來獲取使用者請求引數日誌,以便在後期維護中出現BUG時能夠快速定位錯誤發生的場景。請求引數一般通過GET和POST方式進行傳遞,GET請求引數獲取通過request.getParameterMap()獲

OneNote OneNote是一款由微軟推出最好的筆記軟體。 這麼久沒有任何廣告功能

OneNote OneNote是一款由微軟推出最好用的筆記軟體。 用了這麼久,沒有任何廣告,功能特別強大,當然印象筆記也不錯,但小編跟傾向於OneNote,它支援插入圖片,檔案,表格,流程圖,連結,錄音等等,就像你自己拿了一支筆隨意畫一樣,它還有簡潔的Word 功能,給新增的內容修改字型樣式,顏色,大

Python這麼多年總結出超實用的功能和特點

在使用Python這麼久,時不時就會發現了一些過去不知道的功能和特性。一些可以說是非常有用,但卻沒有充分利用。本篇文章總結出你應該瞭解的Python功能特色,希望大家在學習過程中,少走彎路,善用技巧! 帶任意數量引數的函式 你可能已經知道了Python允許你定義可選引數。但還有一個方法,可以定義函式任

【雜談與亂碼】學程式設計重新看世界

有句二三十年前的古話,工具決定思維。 說得可真棒。 閒談? 開始我們以直觀的肉眼看世界,只知道所見即所得,這又點像最早期的一起低階語言直接操作機器。 學習過語言和邏輯之後,面向過程的思考方式在我們心中紮下了根。至今,只要聽到一、全體肅立,我們就會在腦中自然的補充出,二的內容

藍圖裝飾並註冊url_map沒有相關路由

問題背景:寫一個小demo,模組較多,需要藍圖管理。 專案結構大致如下: ├── app │ ├── auth │ │ ├── __init__.py │ │ └── views.py └── app.py 問題描述:在auth/__init__.py中定義了藍圖

STM32 IAP韌體更新bootloader起始地址偏移程式碼還需設定中斷向量的偏移。

在 stm32f10x_flash.icf 中設定ROM的起始結束地址 /*-Specials-*/ define symbol __ICFEDIT_intvec_start__ = 0x08004000; /*-Memory Regions-*/ define symbo

Ubuntu16.04 過landeng每次都要開啟才能訪問網路

今天用了一下landeng,然後退出後發現無法連線網路,重啟無果。 當我們開啟landeng的時候,landeng開啟了本地代理,使用的是landeng的代理。關閉landeng的時候,或者是直接關機的時候,代理設定沒有修改回來,所以我們要手動修改回來。 解決方法: s

Android的訊息機制Android執行緒間通訊的Message機制AndroidHandler的使用方法

轉自:http://www.cnblogs.com/-OYK/archive/2011/08/03/2126657.html Android的訊息機制(一)   android 有一種叫訊息佇列的說法,這裡我們可以這樣理解:假如一個隧道就是一個訊息佇列,那麼裡

SQLUnion的排序問題

最近使用SQL語句進行UNION查詢,驚奇的發現:SQL沒問題,UNION查詢也沒問題,都可以得到想要的結果,可是在對結果進行排序的時候,卻出問題了。1.UNION查詢沒問題 SELECT `id`

SpringBoot攔截器或過濾器使用流讀取引數controller註解讀取不到引數

今天出現這樣一個問題: 現在開發的專案是基於SpringBoot的maven專案,有個需求就是要加一個攔截器和過濾器,在攔截器中我需要獲取到前端傳過來的json資料,按照常理來說,獲取請求引數使用request.getParameter()方法就可以,但是不知