青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

專職C++

不能停止的腳步

  C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
  163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

常用鏈接

留言簿(28)

我參與的團隊

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

使用appium輸入中文,發現好慢!至少5秒以上,如果在這樣的情況下做測試,這就好悲劇了。 
從appium(1.6.3)代碼上來看,沒有什么問題,直接是通過boostrap的setText的方法。說是就下載了appium-bootstrap的代碼看,從這里開發找到的代碼,都是java的代碼,找到 io.appium.android.bootstrap.handler.SetText 
在new Clear().execute(command);時間長達5秒(打日志發現),不管文本框有沒有內容,都會執行
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * You may obtain a copy of the License at
 *
 *     
http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 
*/

package io.appium.android.bootstrap.handler;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.*;
import io.appium.android.bootstrap.exceptions.ElementNotFoundException;
import io.appium.android.bootstrap.handler.Find;
import org.json.JSONException;

import java.util.Hashtable;

/**
 * This handler is used to set text in elements that support it.
 *
 
*/
public class SetText 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 {
    AndroidElement el = null;
    if (command.isElementCommand()) {
      el = command.getElement();
      Logger.debug("Using element passed in: " + el.getId());
    } else {
      try {
        AndroidElementsHash  elements = AndroidElementsHash.getInstance();
        el = elements.getElement(new UiSelector().focused(true), "");
        Logger.debug("Using currently-focused element: " + el.getId());
      } catch (ElementNotFoundException e) {
        Logger.debug("Error retrieving focused element: " + e);
        return getErrorResult("Unable to set text without a focused element.");
      }
    }
    try {
      final Hashtable<String, Object> params = command.params();
      boolean replace = Boolean.parseBoolean(params.get("replace").toString());
      String text = params.get("text").toString();
      boolean pressEnter = false;
      if (text.endsWith("\\n")) {
        pressEnter = true;
        text = text.replace("\\n", "");
        Logger.debug("Will press enter after setting text");
      }
      boolean unicodeKeyboard = false;
      if (params.get("unicodeKeyboard") != null) {
        unicodeKeyboard = Boolean.parseBoolean(params.get("unicodeKeyboard").toString());
      }
      String currText = el.getText();
      new Clear().execute(command); //不管有沒有,這里都會執行
      if (!el.getText().isEmpty()) {
        // clear could have failed, or we could have a hint in the field
        
// we'll assume it is the latter
        Logger.debug("Text not cleared. Assuming remainder is hint text.");
        currText = "";
      }
      if (!replace) {
        text = currText + text;
      }
      final boolean result = el.setText(text, unicodeKeyboard);
      if (!result) {
        return getErrorResult("el.setText() failed!");
      }
      if (pressEnter) {
        final UiDevice d = UiDevice.getInstance();
        d.pressEnter();
      }
      return getSuccessResult(result);
    } catch (final UiObjectNotFoundException e) {
      return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
          e.getMessage());
    } catch (final Exception e) { // handle NullPointerException
      return getErrorResult("Unknown error");
    }
  }
}
然后,我們再看Clear的代碼

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * You may obtain a copy of the License at
 *
 *     
http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 
*/

package io.appium.android.bootstrap.handler;

import android.graphics.Rect;
import android.os.SystemClock;
import android.view.InputDevice;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.WDStatus;
import io.appium.uiautomator.core.InteractionController;
import io.appium.uiautomator.core.UiAutomatorBridge;
import org.json.JSONException;

import java.lang.reflect.InvocationTargetException;

/**
 * This handler is used to clear elements in the Android UI.
 *
 * Based on the element Id, clear that element.
 *
 * UiAutomator method clearText is flaky hence overriding it with custom implementation.
 
*/
public class Clear extends CommandHandler {

  /*
   * Trying to select entire text with correctLongClick and increasing time intervals.
   * Checking if element still has text in them and and if true falling back on UiAutomator clearText
   *
   * @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()) {
      try {
        final AndroidElement el = command.getElement();

        // first, try to do native clearing
        Logger.debug("Attempting to clear using UiObject.clearText().");
        el.clearText();  //無條件都會執行這塊。然后再分析clearText
        if (el.getText().isEmpty()) {
          return getSuccessResult(true);
        }

        // see if there is hint text
        if (hasHintText(el)) {
          Logger.debug("Text remains after clearing, "
              + "but it appears to be hint text.");
          return getSuccessResult(true);
        }

        // next try to select everything and delete
        Logger.debug("Clearing text not successful. Attempting to clear " +
                "by selecting all and deleting.");
        if (selectAndDelete(el)) {
          return getSuccessResult(true);
        }

        // see if there is hint text
        if (hasHintText(el)) {
          Logger.debug("Text remains after clearing, "
              + "but it appears to be hint text.");
          return getSuccessResult(true);
        }

        // finally try to send delete keys
        Logger.debug("Clearing text not successful. Attempting to clear " +
                "by sending delete keys.");
        if (sendDeleteKeys(el)) {
          return getSuccessResult(true);
        }

        if (!el.getText().isEmpty()) {
          // either there was a failure, or there is hint text
          if (hasHintText(el)) {
            Logger.debug("Text remains after clearing, " +
                    "but it appears to be hint text.");
            return getSuccessResult(true);
          } else if (!el.getText().isEmpty()) {
            Logger.debug("Exhausted all means to clear text but '" +
                    el.getText() + "' remains.");
            return getErrorResult("Clear text not successful.");
          }
        }
        return getSuccessResult(true);
      } catch (final UiObjectNotFoundException e) {
        return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
            e.getMessage());
      } catch (final Exception e) { // handle NullPointerException
        return getErrorResult("Unknown error clearing text");
      }
    }
    return getErrorResult("Unknown error");
  }

  private boolean selectAndDelete(AndroidElement el)
      throws UiObjectNotFoundException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {
    Rect rect = el.getVisibleBounds();
    // Trying to select entire text.
    TouchLongClick.correctLongClick(rect.left + 20, rect.centerY(), 2000);
    UiObject selectAll = new UiObject(new UiSelector().descriptionContains("Select all"));
    if (selectAll.waitForExists(2000)) {
      selectAll.click();
    }
    // wait for the selection
    SystemClock.sleep(500);
    // delete it
    UiAutomatorBridge.getInstance().getInteractionController().sendKey(KeyEvent.KEYCODE_DEL, 0);

    return el.getText().isEmpty();
  }

  private boolean sendDeleteKeys(AndroidElement el)
      throws UiObjectNotFoundException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {
    String tempTextHolder = "";

    // Preventing infinite while loop.
    while (!el.getText().isEmpty() && !tempTextHolder.equalsIgnoreCase(el.getText())) {
      // Trying send delete keys after clicking in text box.
      el.click();
      // Sending delete keys asynchronously, both forward and backward
      for (int key : new int[] { KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_FORWARD_DEL }) {
        tempTextHolder = el.getText();
        final int length = tempTextHolder.length();
        final long eventTime = SystemClock.uptimeMillis();
        KeyEvent deleteEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN,
                key, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
                InputDevice.SOURCE_KEYBOARD);
        for (int count = 0; count < length; count++) {
          UiAutomatorBridge.getInstance().injectInputEvent(deleteEvent, false);
        }
      }
    }

    return el.getText().isEmpty();
  }

  private boolean hasHintText(AndroidElement el)
      throws UiObjectNotFoundException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {
    // to test if the remaining text is hint text, try sending a single
    
// delete key and testing if there is any change.
    
// ignore the off-chance that the delete silently fails and we get a false
    
// positive.
    String currText = el.getText();

    try {
      if (!el.getBoolAttribute("focused")) {
        Logger.debug("Could not check for hint text because the element is not focused!");
        return false;
      }
    } catch (final Exception e) {
      Logger.debug("Could not check for hint text: " + e.getMessage());
      return false;
    }

    InteractionController interactionController = UiAutomatorBridge.getInstance().getInteractionController();
    interactionController.sendKey(KeyEvent.KEYCODE_DEL, 0);
    interactionController.sendKey(KeyEvent.KEYCODE_FORWARD_DEL, 0);

    return currText.equals(el.getText());
  }
}
再看看AndroidElement.clearText是什么樣的
  public void clearText() throws UiObjectNotFoundException {
    el.clearTextField();
  }
這個都就是com.android.uiautomator.core.UiObject.clearTextField 
于是找再找到uiautomator的代碼再來分析(這個代碼需要下載andriod sdk,在對應android版本的目錄下,會有源碼,也有uiautomator的源代碼),我這里的路徑是: 
Android\sdk\sources\android-19\com\android\uiautomator\core 
在UiObject.java找到clearTextField實現
/**
     * Clears the existing text contents in an editable field.
     *
     * The {
@link UiSelector} of this object must reference a UI element that is editable.
     *
     * When you call this method, the method first sets focus at the start edge of the field.
     * The method then simulates a long-press to select the existing text, and deletes the
     * selected text.
     *
     * If a "Select-All" option is displayed, the method will automatically attempt to use it
     * to ensure full text selection.
     *
     * Note that it is possible that not all the text in the field is selected; for example,
     * if the text contains separators such as spaces, slashes, at symbol etc.
     * Also, not all editable fields support the long-press functionality.
     *
     * 
@throws UiObjectNotFoundException
     * 
@since API Level 16
     
*/
    public void clearTextField() throws UiObjectNotFoundException {
        Tracer.trace();
        // long click left + center
        AccessibilityNodeInfo node = findAccessibilityNodeInfo(mConfig.getWaitForSelectorTimeout());
        if(node == null) {
            throw new UiObjectNotFoundException(getSelector().toString());
        }
        Rect rect = getVisibleBounds(node);
        getInteractionController().longTapNoSync(rect.left + 20, rect.centerY()); //長按
        
// check if the edit menu is open
        UiObject selectAll = new UiObject(new UiSelector().descriptionContains("Select all"));
        if(selectAll.waitForExists(50))
            selectAll.click();
        // wait for the selection
        SystemClock.sleep(250); //這里等250ms
        
// delete it
        getInteractionController().sendKey(KeyEvent.KEYCODE_DEL, 0);
    }
相信大家,可以找到慢的原因了。這里做一次長按,然再再做全選,然后再sleep(250),還有一個selectAll.waitForExists(50), 這些都是耗費時間的。
再找一下UiObject.java中setText的實現

    public boolean setText(String text) throws UiObjectNotFoundException {
        Tracer.trace(text);
        clearTextField();
        return getInteractionController().sendText(text);
    }
發現這里又調用了一次clearTextField,這樣算來,設一次文本,都會清理兩次文本,于是,這時間就長了。 
優化:只需要將io.appium.android.bootstrap.handler.SetText中的new Clear().execute(command)去掉就可以了。

posted on 2017-05-27 17:35 冬瓜 閱讀(1889) 評論(0)  編輯 收藏 引用 所屬分類: 原創 、appium
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            黄色精品免费| 国产精品久久久久9999吃药| 国产精品免费aⅴ片在线观看| 亚洲精品中文在线| 欧美国产日韩视频| 免费成人高清| 国产精品丝袜白浆摸在线| 亚洲综合视频1区| 久久亚洲精品一区| 久久免费视频一区| 在线日韩av永久免费观看| 久久天天躁夜夜躁狠狠躁2022| 欧美一区二区三区久久精品茉莉花| 国产农村妇女精品一区二区| 久久riav二区三区| 久久精品中文| 亚洲国产精品免费| 欧美高清hd18日本| 欧美久久精品午夜青青大伊人| av成人福利| 一区二区三区**美女毛片| 国产精品视频一| 欧美一区二区三区啪啪| 亚洲第一区色| 欧美日韩精品综合在线| 欧美亚洲免费电影| 鲁大师成人一区二区三区| 亚洲欧美激情视频在线观看一区二区三区| 欧美日韩一区二区三区在线看 | 欧美成人一区在线| 日韩性生活视频| 亚洲专区欧美专区| 国产欧美一区二区精品婷婷| 久久爱www.| 久久久www成人免费精品| 91久久久一线二线三线品牌| 一区二区三区视频在线| 136国产福利精品导航网址| 亚洲激情不卡| 国产一区久久久| 亚洲日本一区二区| 在线观看国产成人av片| 亚洲美女免费精品视频在线观看| 国产欧美日韩一区| 亚洲国产导航| 黄色亚洲在线| 亚洲一区bb| 亚洲最快最全在线视频| 久久久国产91| 欧美一区二区三区免费在线看| 欧美国产精品一区| 久久久久欧美精品| 国产精品久久久一区二区三区| 欧美日韩亚洲国产精品| 欧美大香线蕉线伊人久久国产精品| 国产精品theporn88| 欧美高清视频在线观看| 国产精品入口66mio| 亚洲看片免费| 亚洲黄色在线视频| 久久三级福利| 久久激情综合| 国产精品视频久久| 免费在线播放第一区高清av| 国产精品国产三级国产专播品爱网 | 欧美高清在线精品一区| 国产欧美日韩综合一区在线观看| 亚洲电影免费在线观看| 激情一区二区三区| 亚洲精品视频在线观看免费| 亚洲国产日韩欧美一区二区三区| 久久国内精品自在自线400部| 先锋影音国产精品| 欧美视频一区二| 亚洲理伦电影| 亚洲午夜免费视频| 欧美激情精品久久久久久免费印度 | 欧美h视频在线| 免费在线看一区| 在线观看精品视频| 久久久国产午夜精品| 久久这里只精品最新地址| 国产在线观看一区| 久久精品国产清自在天天线| 午夜精品久久久久久久| 欧美日本视频在线| 亚洲精品偷拍| 亚洲尤物视频网| 国产精品乱人伦一区二区| 亚洲欧美日韩精品一区二区| 欧美在线免费| 在线成人激情| 欧美福利视频在线| 一区二区三区视频在线看| 性欧美暴力猛交另类hd| 精品999网站| 欧美成人午夜免费视在线看片| 亚洲精品久久久久久久久久久久久 | 中文在线资源观看网站视频免费不卡 | 欧美一区二区观看视频| 国产亚洲一区二区三区| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲高清123| 亚洲在线播放| 有坂深雪在线一区| 欧美精品成人91久久久久久久| 一区二区三区欧美亚洲| 久久综合色影院| 日韩视频在线免费观看| 欧美午夜精品| 午夜老司机精品| 亚洲成人在线网| 午夜国产欧美理论在线播放| 亚洲高清色综合| 国产精品久久久久久户外露出| 久久国产精品99久久久久久老狼| 欧美国产亚洲视频| 亚洲一区二区三区四区视频 | 久久久亚洲国产美女国产盗摄| 亚洲黄色av一区| 久久国产一区二区三区| 99精品久久免费看蜜臀剧情介绍| 欧美日韩亚洲高清| 久久三级视频| 亚洲欧美99| 亚洲人成网站影音先锋播放| 久久av红桃一区二区小说| 亚洲激情在线观看| 欧美系列一区| 久久综合伊人| 中文欧美在线视频| 亚洲高清在线观看| 免费日韩av片| 欧美一区二区在线免费观看| 99国产精品久久久| 亚洲电影在线看| 国产色综合久久| 欧美视频在线不卡| 欧美另类videos死尸| 久久亚洲高清| 久久久久成人网| 亚洲一区二区三区涩| 99在线精品视频| 亚洲国产精品悠悠久久琪琪| 久久精品视频免费| 午夜伦理片一区| 亚洲男女自偷自拍| 亚洲伊人一本大道中文字幕| 99视频在线观看一区三区| 亚洲日本激情| 亚洲精品日韩综合观看成人91| 狠狠色狠狠色综合| 激情久久婷婷| 一区二区在线视频观看| 黄色成人精品网站| 国产精品综合av一区二区国产馆| 欧美日韩精品免费看| 欧美日韩国产一区二区三区| 欧美久久久久久久| 欧美日韩国产综合视频在线| 欧美日本三级| 国产精品h在线观看| 国产日韩在线一区二区三区| 有码中文亚洲精品| 在线一区二区日韩| 久久精品免视看| 亚洲大片免费看| 亚洲一二三区精品| 久久久久国产精品一区二区| 欧美精品激情| 国产亚洲一区二区在线观看| 91久久久久久久久久久久久| 亚洲综合色网站| 女人色偷偷aa久久天堂| 一区电影在线观看| 久久婷婷av| 国产精品视频精品| 亚洲精品乱码久久久久久按摩观| 亚洲综合色视频| 欧美激情中文字幕一区二区| 亚洲一区二区成人| 奶水喷射视频一区| 国产伦精品一区二区三| 亚洲精品乱码| 久久一区精品| 在线视频亚洲欧美| 久久综合中文| 国产亚洲午夜| 亚洲欧美不卡| 亚洲精品视频在线播放| 久久久噜噜噜久久人人看| 国产精品盗摄久久久| 亚洲美洲欧洲综合国产一区| 欧美与黑人午夜性猛交久久久| 亚洲日本中文字幕| 免费在线亚洲| 影音先锋成人资源站| 欧美在线视屏| 中文在线资源观看网站视频免费不卡| 久久综合久久久|