標籤:appium
package com.appium.test;
/**
* @author YuFeifei
* @version 2017年11月15日 上午11:41:21
* 類說明
* 根據讀取的設定檔,將key和value拆分
* 再通過split將value分成定位類型(locatorType)和元素(locatorValue)
*/
import org.openqa.selenium.By;
public class GetByLocatorTest {
public static By getLocator(String key){
ProUtilTest properties = new ProUtilTest("./configs/test1.properties");
/**屬性locator 是通過key擷取的value*/
String locator = properties.getProp(key);
/**屬性locatorType 擷取的value中通過split分離出的>前面的資料==id、name等*/
String locatorType = locator.split(">")[0];
/**屬性locatorType 擷取的value中通過split分離出的>後面的資料==元素*/
String locatorValue = locator.split(">")[1];
System.out.println("擷取的定位類型:" + locatorType + "\t擷取的元素是:" + locatorValue);
/**根據定位類型,返回定位方式*/
if (locatorType.toLowerCase().equals("id"))//toLowerCase()將大寫字元轉換為小寫
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("輸入的locatorType未在預設程式中被定義:" + locatorType + "請檢查GetByLocatorTest這個類");
}catch (Exception e){
e.printStackTrace();
}
return null;
}
/**測試*/
public static void main(String agrs[]){
GetByLocatorTest test2 = new GetByLocatorTest();
System.out.println(test2.getLocator("LG_NAME_PHONE"));
}
}
Java+Appium自動化測試架構(二) 定位方式