手机自动化测试:appium源码分析之bootstrap八
手機(jī)自動(dòng)化測試:appium源碼分析之bootstrap八
?poptest是國內(nèi)唯一一家培養(yǎng)測試開發(fā)工程師的培訓(xùn)機(jī)構(gòu),以學(xué)員能勝任自動(dòng)化測試,性能測試,測試工具開發(fā)等工作為目標(biāo)。如果對(duì)課程感興趣,請(qǐng)大家咨詢qq:908821478,今天是移動(dòng)端測試開發(fā)課程開課,學(xué)員們學(xué)習(xí)熱情很高。我們發(fā)現(xiàn)測試培訓(xùn)一個(gè)有趣的特點(diǎn),周末學(xué)習(xí)提高的女孩子多,就業(yè)培訓(xùn)參加的男孩子比例高,
概念:pinchIn和pinchOut
a.2個(gè)手指同時(shí)按住A和B,同時(shí)將A滑向A1,B滑向B1,稱為pinchIn
b.2個(gè)手指同時(shí)按住A1和B1,同時(shí)將A1滑向A,B1滑向B,成為pinchOut.
?
那么Pinch類就是接受這一指令的,傳入的參數(shù)有方向direction,percent代表滑到對(duì)角線百分之幾停止,steps代表滑到時(shí)間,一個(gè)step代表5毫秒。根據(jù)direction來判斷是調(diào)用UiObject.pinchIn和UiObject.pinchOut.
?
Pinch代碼:
package io.appium.android.bootstrap.handler;
?
import com.android.uiautomator.core.UiObjectNotFoundException;
import io.appium.android.bootstrap.*;
import org.json.JSONException;
?
import java.util.Hashtable;
?
/**
?* This handler is used to pinch in/out elements in the Android UI.
?*
?* Based on the element Id, pinch in/out that element.
?*
?*/
public class Pinch 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)
?? */
? @Override
? public AndroidCommandResult execute(final AndroidCommand command)
????? throws JSONException {
??? final Hashtable<String, Object> params = command.params();
?
??? AndroidElement el;
??? final String direction = params.get("direction").toString();
??? final Integer percent = (Integer) params.get("percent");
??? final Integer steps = (Integer) params.get("steps");
??? try {
????? el = command.getElement();
????? if (el == null) {
??????? return getErrorResult("Could not find an element with elementId: "
??????????? + params.get("elementId"));
????? }
??? } catch (final Exception e) { // JSONException, NullPointerException, etc.
????? return getErrorResult("Unknown error:" + e.getMessage());
??? }
?
??? Logger.debug("Pinching " + direction + " " + percent.toString() + "%"
??????? + " with steps: " + steps.toString());
??? boolean res;
??? if (direction.equals("in")) {
????? try {
??????? res = el.pinchIn(percent, steps);
????? } catch (final UiObjectNotFoundException e) {
??????? return getErrorResult("Selector could not be matched to any UI element displayed");
????? }
??? } else {
????? try {
??????? res = el.pinchOut(percent, steps);
????? } catch (final UiObjectNotFoundException e) {
??????? return getErrorResult("Selector could not be matched to any UI element displayed");
????? }
??? }
?
??? if (res) {
????? return getSuccessResult(res);
??? } else {
????? return getErrorResult("Pinch did not complete successfully");
??? }
? }
}
轉(zhuǎn)載于:https://www.cnblogs.com/poptest/p/4950606.html
總結(jié)
以上是生活随笔為你收集整理的手机自动化测试:appium源码分析之bootstrap八的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《从零开始学Swift》学习笔记(Day
- 下一篇: 20151110