use of ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException in project page-factory-2 by sbtqa.
the class TagMobileDriver method createDriver.
private static void createDriver() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", PROPERTIES.getAppiumDeviceName());
capabilities.setCapability("platformVersion", PROPERTIES.getAppiumDevicePlatform());
capabilities.setCapability("appPackage", PROPERTIES.getAppiumAppPackage());
capabilities.setCapability("appActivity", PROPERTIES.getAppiumAppActivity());
capabilities.setCapability("autoGrantPermissions", "true");
capabilities.setCapability("unicodeKeyboard", "true");
capabilities.setCapability("resetKeyboard", "true");
LOG.info("Capabilities are {}", capabilities);
URL url;
try {
url = new URL(PROPERTIES.getAppiumUrl());
} catch (MalformedURLException e) {
throw new FactoryRuntimeException("Could not parse appium url. Check 'appium.url' property", e);
}
PageFactory.setAspectsEnabled(false);
LOG.debug("Aspect disabled");
mobileDriver = new AndroidDriver<>(url, capabilities);
LOG.info("Mobile driver created {}", mobileDriver);
deviceUdId = (String) mobileDriver.getSessionDetails().get("deviceUDID");
}
use of ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException in project page-factory-2 by sbtqa.
the class PageFactoryUtils method executeMethodByTitle.
/**
* Find method with corresponding title on current page, and execute it
*
* @param page the page on which the method is executing
* @param title title of the method to call
* @param param parameters that will be passed to method
* @throws java.lang.NoSuchMethodException if required method couldn't be
* found
*/
public static void executeMethodByTitle(Page page, String title, Object... param) throws NoSuchMethodException {
List<Method> methods = getDeclaredMethods(page.getClass());
for (Method method : methods) {
if (isRequiredAction(method, title)) {
try {
method.setAccessible(true);
MethodUtils.invokeMethod(page, method.getName(), param);
return;
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new FactoryRuntimeException("Error while executing action '" + title + "' on " + method.getDeclaringClass().getSimpleName() + " . See the caused exception below", ExceptionUtils.getRootCause(e));
}
}
}
throw new NoSuchMethodException("There is no '" + title + "' method on '" + page.getTitle() + "' page object");
}
use of ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException in project page-factory-2 by sbtqa.
the class JDIUtils method setJDIConfig.
public static void setJDIConfig(Supplier<WebDriver> driverSupplier) {
try {
WebSettings.initFromProperties();
WebSettings.logger = new JDILogger();
} catch (IOException e) {
throw new FactoryRuntimeException("Exception occurred during setting jdi", e);
}
driverName = WebSettings.useDriver(driverSupplier);
}
use of ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException in project page-factory-2 by sbtqa.
the class DefaultReflection method executeMethodByTitle.
@Override
public void executeMethodByTitle(Object context, String title, Object... param) {
List<Method> methods = getDeclaredMethods(context.getClass());
for (Method method : methods) {
if (isRequiredAction(method, title) && isArgumentsIdentical(method, param)) {
try {
method.setAccessible(true);
method.invoke(context, param);
return;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new FactoryRuntimeException("Error while executing action '" + title + "' on " + method.getDeclaringClass().getSimpleName() + " . See the caused exception below", ExceptionUtils.getRootCause(e));
}
}
}
throw new NoSuchActionError("There is no '" + title + "' method with parameters ['" + Arrays.stream(param).map(s -> s.getClass().toString()).collect(Collectors.joining(", ")) + "'] on page '" + context.getClass() + "'");
}
use of ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException in project page-factory-2 by sbtqa.
the class PageReflectUtil method executeMethodByTitleInBlock.
/**
* Execute method with one or more parameters inside of the given block
* element !BEWARE! If there are several elements found by specified block
* path, a first one will be used!
*
* @param page the page on which the method will be executed
* @param blockPath block title, or a block chain string separated with
* '->' symbols
* @param actionTitle title of the action to execute
* @param parameters parameters that will be passed to method
* @throws NoSuchMethodException if required method couldn't be
* found
*/
public static void executeMethodByTitleInBlock(Page page, String blockPath, String actionTitle, Object... parameters) throws NoSuchMethodException {
HtmlElement block = findBlock(page, blockPath);
Method[] methods = block.getClass().getMethods();
for (Method method : methods) {
if (isRequiredAction(method, actionTitle)) {
try {
method.setAccessible(true);
if (parameters == null || parameters.length == 0) {
MethodUtils.invokeMethod(block, method.getName());
} else {
MethodUtils.invokeMethod(block, method.getName(), parameters);
}
return;
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new FactoryRuntimeException(String.format("Failed to execute method '%s' in the following block: '%s'", actionTitle, blockPath), e);
}
}
}
isUsedBlock = true;
usedBlock = block;
List<Method> methodList = getDeclaredMethods(page.getClass());
for (Method method : methodList) {
if (isRequiredAction(method, actionTitle)) {
try {
method.setAccessible(true);
MethodUtils.invokeMethod(page, method.getName(), parameters);
return;
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new FactoryRuntimeException(String.format("Failed to execute method '%s' in the following block: '%s'", actionTitle, blockPath), e);
}
}
}
throw new NoSuchMethodException(String.format("There is no '%s' method in block '%s'", actionTitle, blockPath));
}
Aggregations