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