Архитектура. Основные элементы.
.properties — текстовый формат и одноименное расширение имени файла, применяемое для сохранения конфигурационных параметровLoginPage.title=Login Page
LoginPage.userNameInput=id=Login
LoginPage.userPassInput=id=Password
LoginPage.loginButton=css=input[value=Login]
Grid.FieldFrom=xpath=.//input[contains(@placeholder,'From')]
Grid.Datepicker=css=.datepicker
HomePage.title=Gamespublic class Locators {
private static final Properties locators;
private enum LocatorType{
id, name, css, xpath, tag, text, partText;
}
static {
locators = new Properties();
InputStream is = Locators.class.getResourceAsStream("/locators.properties");
try {
locators.load(is);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static String title(String pageName) {
return locators.getProperty(pageName);
}
public static By get(String locatorName) {
String propertyValue = locators.getProperty(locatorName);
return getLocator(propertyValue);
}
public static By get(String locatorName, String parameter) {
String propertyValue = locators.getProperty(locatorName);
return getLocator(String.format(propertyValue, parameter));
}
private static By getLocator(String locator){
String[] locatorItems = locator.split("=",2);
LocatorType locatorType = LocatorType.valueOf(locatorItems[0]);
switch(locatorType) {
case id :{
return By.id(locatorItems[1]);
}
case name:{
return By.name(locatorItems[1]);
}
case css:{
return By.cssSelector(locatorItems[1]);
}
case xpath:{
return By.xpath(locatorItems[1]);
}
case tag:{
return By.tagName(locatorItems[1]);
}
case text:{
return By.linkText(locatorItems[1]);
}
case partText:{
return By.partialLinkText(locatorItems[1]);
}
default:{
throw new IllegalArgumentException("No such locator type: " + locatorItems[0]);
}
}
}Last updated