Waitforidle & Clear for bootstrap

Source: Internet
Author: User
Tags appium

(Only after the previous article is written can we find that the correct order is correct, but it is not in order to look back.) waitforidle is the first one. Ah, it's old, and the back of the head won't work.


Waitforidle


package io.appium.android.bootstrap.handler;import com.android.uiautomator.core.UiDevice;import io.appium.android.bootstrap.AndroidCommand;import io.appium.android.bootstrap.AndroidCommandResult;import io.appium.android.bootstrap.CommandHandler;import org.json.JSONException;import java.util.Hashtable;/** * This handler is used to clear elements in the Android UI. *  * Based on the element Id, clear that element. *  */public class WaitForIdle 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 {    final Hashtable<String, Object> params = command.params();    long timeout = 10;    if (params.containsKey("timeout")) {      timeout = (Integer) params.get("timeout");    }    UiDevice d = UiDevice.getInstance();    d.waitForIdle(timeout);    return getSuccessResult(true);  }}

The code above is easy to process. First, it gets the parameters in the command, and then initializes a private timeout variable. If the parameter does not contain time, the default time is used. Then call the waitforidle () method in the uidevice object of uiautomator. This method does not perform any other operations on the interface within the timeout time and is idle. This encapsulates the waitforidle method of the uidevice.


Clear


package io.appium.android.bootstrap.handler;import com.android.uiautomator.core.UiObjectNotFoundException;import io.appium.android.bootstrap.*;import org.json.JSONException;/** * This handler is used to clear elements in the Android UI. *  * Based on the element Id, clear that element. *  */public class Clear 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()) {      try {        final AndroidElement el = command.getElement();        el.clearText();        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");  }}

For the clear method, see the e1.cleartext () method. Other methods are involved in the click method.


private final UiObject el;public void clearText() throws UiObjectNotFoundException {    el.clearTextField();  }

In fact, uiobject. cleartextfield () in uiautomator is called to understand the content in the text box.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.