Appium: Page element initialization at the operation layer, and appium Initialization

Source: Internet
Author: User

Appium: Page element initialization at the operation layer, and appium Initialization

Page element Initialization is encapsulated into a class. You only need to initialize the page element once for the first time, and the data is stored in ArrayList.

The Code is as follows:

Package com. datas. api; import com. appium. api. log; import org. openqa. selenium. by; import java. util. arrayList; import java. util. hashMap; import io. appium. java_client.android.AndroidDriver;/*** Created by kitwit on 0011. * initialize the page element */public class InitTestPage {public AndroidDriver driver; private String pageName; private LocaterPaser locaterPaser = new LocaterPaser (); private HashMap
 
  
LocatorMap; InitTestPage () {}/ *** initialize a page object, create a LocaterPaser, and HashMap * parameter: Page name * return none **/public InitTestPage (String pageName) {locatorMap = locaterPaser. getLocator (pageName); this. pageName = pageName;}/*** multiple constructors are provided for selection * parameter: Page name and drive object * return none **/public InitTestPage (AndroidDriver driver, String pageName) {locatorMap = locaterPaser. getLocator (pageName); this. driver = driver; this. pageName = pageName;}/*** get button information * parameter: itemName needs to read the information of the button, * return By type **/public By getBy (String buttonName) {ArrayList valueList = getXmlDatas (buttonName); Locator. byType idType = (Locator. byType) valueList. get (0); String value = (String) valueList. get (1); By = null; switch (idType) {case xpath: by =. xpath (value); break; case id: by =. id (value); break; case name: by =. name (value); break; case className: by =. className (value); break; default: by =. id (value);} return by;}/*** get the value information of the button * parameter: itemName needs to read the information of the button, * return By type **/public String getButtonTypeValue (String buttonName) {ArrayList valueList = getXmlDatas (buttonName); // Locator. byType idType = (Locator. byType) valueList. get (0); return (String) valueList. get (1);}/*** read data from the specified page * locatorMap is the Map that stores the page element data, and the value of String is key (the button name is used here ), the Locator object stores the value and type of the key * parameter: itemName needs to read the information of the button, * Find the returned ArrayList type, idType and value information are stored. **/private ArrayList getXmlDatas (String buttonName) {ArrayList valueList = new ArrayList (); Locator. byType idType; String value; Log.info ("start to search for page elements in HashMap... "); for (String key: locatorMap. keySet () {if (key. equals (buttonName) {idType = locatorMap. get (key ). getByType (); value = locatorMap. get (key ). getButtonValue (); valueList. add (idType); valueList. add (value); Log.info ("locate the required key in the database, and return the button type and value of the key... "); return valueList ;}}
 

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.