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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

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

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

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

? ?poptest是國內唯一一家培養測試開發工程師的培訓機構,以學員能勝任自動化測試,性能測試,測試工具開發等工作為目標。poptest測試開發工程師就業培訓請大家咨詢qq:908821478)移動端自動化測試是未來的測試工程師的技術要求,我們需要打好基礎。

Drag

package io.appium.android.bootstrap.handler;

?

import com.android.uiautomator.core.UiDevice;

import com.android.uiautomator.core.UiObjectNotFoundException;

import io.appium.android.bootstrap.*;

import io.appium.android.bootstrap.exceptions.InvalidCoordinatesException;

import io.appium.android.bootstrap.utils.Point;

import org.json.JSONException;

import org.json.JSONObject;

?

import java.util.Hashtable;

?

/**

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

?*

?*/

public class Drag extends CommandHandler {

?

? /*

?? * @param command The {@link AndroidCommand} used for this handler.

?? *

?? * @return {@link AndroidCommandResult}

?? *

?? * @throws JSONException

?? *

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

?? * bootstrap.AndroidCommand)

?? */

?

? private static class DragArguments {

?

??? public AndroidElement el;

??? public AndroidElement destEl;

??? public final Point??? start;

??? public final Point??? end;

??? public final Integer? steps;

?

??? public DragArguments(final AndroidCommand command) throws JSONException {

?

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

?

????? try {

? ??????if (params.get("elementId") != JSONObject.NULL) {

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

??????? }

????? } catch (final Exception e) {

??????? el = null;

????? }

?

????? try {

??????? if (params.get("destElId") != JSONObject.NULL) {

????????? destEl = command.getDestElement();

??????? }

????? } catch (final Exception e) {

??????? destEl = null;

????? }

????? start = new Point(params.get("startX"), params.get("startY"));

????? end = new Point(params.get("endX"), params.get("endY"));

? ????steps = (Integer) params.get("steps");

??? }

? }

?

? private AndroidCommandResult drag(final DragArguments dragArgs) {

??? Point absStartPos = new Point();

??? Point absEndPos = new Point();

??? final UiDevice device = UiDevice.getInstance();

?

??? try {

????? absStartPos = getDeviceAbsPos(dragArgs.start);

????? absEndPos = getDeviceAbsPos(dragArgs.end);

??? } catch (final InvalidCoordinatesException e) {

????? return getErrorResult(e.getMessage());

??? }

?

??? Logger.debug("Dragging from " + absStartPos.toString() + " to "

??????? + absEndPos.toString() + " with steps: " + dragArgs.steps.toString());

??? final boolean rv = device.drag(absStartPos.x.intValue(),

??????? absStartPos.y.intValue(), absEndPos.x.intValue(),

??????? absEndPos.y.intValue(), dragArgs.steps);

??? if (!rv) {

????? return getErrorResult("Drag did not complete successfully");

??? }

??? return getSucce***esult(rv);

? }

?

? private AndroidCommandResult dragElement(final DragArguments dragArgs) {

??? Point absEndPos = new Point();

?

??? if (dragArgs.destEl == null) {

????? try {

??????? absEndPos = getDeviceAbsPos(dragArgs.end);

????? } catch (final InvalidCoordinatesException e) {

??????? return getErrorResult(e.getMessage());

????? }

?

????? Logger.debug("Dragging the element with id " + dragArgs.el.getId()

????????? + " to " + absEndPos.toString() + " with steps: "

????????? + dragArgs.steps.toString());

????? try {

??????? final boolean rv = dragArgs.el.dragTo(absEndPos.x.intValue(),

??????????? absEndPos.y.intValue(), dragArgs.steps);

??????? if (!rv) {

????????? return getErrorResult("Drag did not complete successfully");

??????? } else {

????????? return getSucce***esult(rv);

??????? }

????? } catch (final UiObjectNotFoundException e) {

??????? return getErrorResult("Drag did not complete successfully"

??????????? + e.getMessage());

????? }

??? } else {

????? Logger.debug("Dragging the element with id " + dragArgs.el.getId()

????????? + " to destination element with id " + dragArgs.destEl.getId()

????????? + " with steps: " + dragArgs.steps);

????? try {

??????? final boolean rv = dragArgs.el.dragTo(dragArgs.destEl.getUiObject(),

??????????? dragArgs.steps);

??????? if (!rv) {

????????? return getErrorResult("Drag did not complete successfully");

??????? } else {

????????? return getSucce***esult(rv);

??????? }

????? } catch (final UiObjectNotFoundException e) {

??????? return getErrorResult("Drag did not complete successfully"

??????????? + e.getMessage());

????? }

??? }

?

? }

?

? @Override

? public AndroidCommandResult execute(final AndroidCommand command)

????? throws JSONException {

??? // DragArguments is created on each execute which prevents leaking state

??? // across executions.

??? final DragArguments dragArgs = new DragArguments(command);

?

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

????? return dragElement(dragArgs);

??? } else {

????? return drag(dragArgs);

??? }

? }

}

首先來看DragArguments對象。該類為Drag中的私有類,它的構造方法回去解析傳入的command,然后獲得并存儲一些drag方法用到的參數。例如拖拽控件時,被拖拽的控件對象,拖拽到的控件對象。坐標拖拽時,起始點坐標、終點坐標、步驟。所以就把它看成一個實體類就行了。然后分控件和坐標分別調用dragElement()和drag()方法。

dragElement()

如果拖拽到的控件不存在,那么就要用到結束坐標。如果拖拽到的控件存在,那么就用該控件計算拖拽到坐標,調用UiObject.dragTo()方法來執行命令。

drag()

直接調用UiObject.dragTo來執行


轉載于:https://blog.51cto.com/10988776/1726823

總結

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

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