Java+Appium Automated Test Framework (2) Positioning method
Package com.appium.test
/ * *
* @ author YuFeifei
* @ version 11:41:21 on November 15, 2017
* Class description
* split key and value based on the read configuration file
* value is then divided into location type (locatorType) and element (locatorValue) through split
, /
Import org.openqa.selenium.By
Public class GetByLocatorTest {
Public static By getLocator (String key) {
ProUtilTest properties = new ProUtilTest (". / configs/test1.properties")
/ * * attribute locator is the value*/ obtained through key
String locator = properties.getProp (key)
/ * * data separated by split in value obtained by attribute locatorType > previous data = = id, name, etc. * /
String locatorType = locator.split (">") [0]
/ * * data separated by split in value obtained by attribute locatorType = = element * /
String locatorValue = locator.split (">") [1]
System.out.println ("Type of location acquired:" + locatorType + "\ t gets the element:" + locatorValue)
/ * * return the positioning method according to 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 locatorType entered is not defined in the default program:" + locatorType + "Please check the class GetByLocatorTest")
} 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"))
}
}