日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

手机自动化测试:appium源码分析之bootstrap十二

發布時間:2024/10/12 编程问答 77 豆豆
生活随笔 收集整理的這篇文章主要介紹了 手机自动化测试:appium源码分析之bootstrap十二 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

手機自動化測試:appium源碼分析之bootstrap十二

?

? poptest是國內唯一一家培養測試開發工程師的培訓機構,以學員能勝任自動化測試,性能測試,測試工具開發等工作為目標。如果對課程感興趣,請大家咨詢qq:908821478。

ScrollTo

package io.appium.android.bootstrap.handler;

?

import com.android.uiautomator.core.UiObject;

import com.android.uiautomator.core.UiObjectNotFoundException;

import com.android.uiautomator.core.UiScrollable;

import com.android.uiautomator.core.UiSelector;

import io.appium.android.bootstrap.*;

import org.json.JSONException;

?

import java.util.Hashtable;

?

/**

?* This handler is used to scroll to elements in the Android UI.

?*

?* Based on the element Id of the scrollable, scroll to the object with the

?* text.

?*

?*/

public class ScrollTo extends CommandHandler {

?

? /*

?? * @param command The {@link AndroidCommand}

?? *

?? * @return {@link AndroidCommandResult}

?? *

?? * @throws JSONException

?? *

?? * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.

?? * bootstrap.AndroidCommand)

?? */

? @Override

? public AndroidCommandResult execute(final AndroidCommand command)

????? throws JSONException {

??? if (!command.isElementCommand()) {

????? return getErrorResult("A scrollable view is required for this command.");

??? }

?

??? try {

????? Boolean result;

????? final Hashtable<String, Object> params = command.params();

????? final String text = params.get("text").toString();

????? final String direction = params.get("direction").toString();

?

????? final AndroidElement el = command.getElement();

?

????? if (!el.getUiObject().isScrollable()) {

??????? return getErrorResult("The provided view is not scrollable.");

????? }

?

????? final UiScrollable view = new UiScrollable(el.getUiObject().getSelector());

?

????? if (direction.toLowerCase().contentEquals("horizontal")

????????? || view.getClassName().contentEquals(

????????????? "android.widget.HorizontalScrollView")) {

??????? view.setAsHorizontalList();

????? }

????? view.scrollToBeginning(100);

????? view.setMaxSearchSwipes(100);

????? result = view.scrollTextIntoView(text);

????? view.waitForExists(5000);

?

????? // make sure we can get to the item

????? UiObject listViewItem = view.getChildByInstance(

????????? new UiSelector().text(text), 0);

?

????? // We need to make sure that the item exists (visible)

????? if (!(result && listViewItem.exists())) {

??????? return getErrorResult("Could not scroll element into view: " + text);

????? }

????? return getSuccessResult(result);

??? } catch (final UiObjectNotFoundException e) {

????? return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());

??? } catch (final NullPointerException e) { // el is null

????? return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());

??? } catch (final Exception e) {

????? return new AndroidCommandResult(WDStatus.UNKNOWN_ERROR, e.getMessage());

??? }

? }

}

在uiautomator中有時候需要在一個滾動的list中找到某一個item,而這個item的位置又不定,這個時候我們可以通過UiScrollable的scrollTo來找到特定text的控件。而bootstrap的這個ScrollTo就是封裝這樣一種需求的。

?

首先判斷控件是否是可以滾動的,然后創建UiScrollable對象,因為默認的滾動方式是垂直方向的,如果需要的是水平方向的的話,還要設置方向為水平。

?

view.setAsHorizontalList();

然后將滾動控件滾到最開始的地方,然后設置最大的搜索范圍為100次,因為不可能永遠搜索下去。然后開始調用

view.scrollTextIntoView(text);

開始滾動,最后確認是否滾動到制定目標:

view.waitForExists(5000);

因為有可能有刷新到時間,所以調用方法到時候傳入了時間5秒鐘。

UiObject listViewItem = view.getChildByInstance(

????????? new UiSelector().text(text), 0);

最后檢查結果,獲取制定text的對象,判斷其是否存在然后返回相應結果給客戶端。

轉載于:https://www.cnblogs.com/poptest/p/4950625.html

總結

以上是生活随笔為你收集整理的手机自动化测试:appium源码分析之bootstrap十二的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。