Java+appium Automatic test Framework (ii) Positioning method

Source: Internet
Author: User

Package com.appium.test;

/**

* @author Yufeifei

* @version November 15, 2017 11:41:21

* Class Description

* Split key and value according to the Read configuration file

* Re-divides value into positioning type (Locatortype) and Element (Locatorvalue) by split

*/

Import Org.openqa.selenium.By;

public class Getbylocatortest {

public static by GetLocator (String key) {

Proutiltest properties = new Proutiltest ("./configs/test1.properties");

The/** property Locator is obtained by key value*/

String locator = Properties.getprop (key);

/** Property Locatortype Gets the value in the data ==id, name, etc. separated by split >

String Locatortype = Locator.split (">") [0];

/** Property Locatortype Gets the value of the data that is separated by split in the > = element */

String Locatorvalue = Locator.split (">") [1];

System.out.println ("Get the positioning Type:" + Locatortype + "\ t gets the element is:" + locatorvalue);

/** return to positioning mode depending on the positioning type */

if (Locatortype.tolowercase (). Equals ("id"))//tolowercase () converts uppercase characters to lowercase

Return By.id (Locatorvalue);

else if (locatortype.tolowercase (). Equals ("name"))

Return By.name (Locatorvalue);

else if (locatortype.tolowercase (). Equals ("classname"))

Return By.classname (Locatorvalue);

else if (locatortype.tolowercase (). Equals ("TagName"))

Return By.tagname (Locatorvalue);

else if (locatortype.tolowercase (). Equals ("Linktext"))

Return By.linktext (Locatorvalue);

else if (locatortype.tolowercase (). Equals ("Cssselector"))

Return By.cssselector (Locatorvalue);

else if (locatortype.tolowercase (). Equals ("XPath"))

Return By.xpath (Locatorvalue);

Else

try{

throw new Exception ("The input locatortype is not defined in the preset program:" + Locatortype + "Please check getbylocatortest this class");

}catch (Exception e) {

E.printstacktrace ();

}

return null;

}

/** Test */

public static void Main (String agrs[]) {

Getbylocatortest test2 = new Getbylocatortest ();

System.out.println (Test2.getlocator ("Lg_name_phone"));

}


}


Java+appium Automatic test Framework (ii) Positioning method

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.