Mobile phone Automation test: Appium Source analysis of Bootstrap 10

Source: Internet
Author: User

Poptest is the only training institute for developing Test and development engineers in China, aiming at the ability of the trainees to be competent in automated testing, performance testing and testing tools development. If you are interested in the course, please consult qq:908821478. SetText

Package Io.appium.android.bootstrap.handler;

Import Com.android.uiautomator.core.UiDevice;

Import com.android.uiautomator.core.UiObjectNotFoundException;

Import io.appium.android.bootstrap.*;

Import org.json.JSONException;

Import java.util.Hashtable;

/**

* This handler are used to set the text in elements.

*

*/

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 {

if (Command.iselementcommand ()) {

Only makes sense in an element

try {

Final hashtable<string, object> params = Command.params ();

Final androidelement el = command.getelement ();

String Text = params.get ("text"). ToString ();

Boolean Pressenter = false;

if (Text.endswith ("\\n")) {

Pressenter = true;

Text = Text.replace ("\\n", "");

Logger.debug ("would press ENTER after setting text");

}

Final Boolean result = El.settext (text);

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");

}

} else {

Return Geterrorresult ("Unable to set text without an element.");

}

}

}

Write so many articles, above the first few lines of code are familiar with, not like the first article introduced, SetText method is in the editable text box input data, so there is no special place, nothing is called UIObject SetText method, But take a closer look will find that it does some processing, such as the string of the newline character is deleted, after the input is finished press ENTER key to complete the input. Then I write the case before these also need to do, because if you do not press the ENTER key, some input method will be some problems, such as Chinese it is first out of the characters you entered to represent the Chinese character and then you press ENTER it will be correctly displayed in the text box, not as the English input method directly in the input box. So appium considering that this has been done for us.

GetText

Nothing to say, is simply to call the UIObject GetText method to get the data in the edit box.

Mobile phone Automation test: Appium Source analysis of Bootstrap 10

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.