Search in sources :

Example 1 with FactoryRuntimeException

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");
}
Also used : MalformedURLException(java.net.MalformedURLException) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FactoryRuntimeException(ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException) URL(java.net.URL)

Example 2 with FactoryRuntimeException

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");
}
Also used : Method(java.lang.reflect.Method) FactoryRuntimeException(ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with FactoryRuntimeException

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);
}
Also used : JDILogger(com.epam.jdi.uitests.core.logger.JDILogger) IOException(java.io.IOException) FactoryRuntimeException(ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException)

Example 4 with FactoryRuntimeException

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() + "'");
}
Also used : NoSuchActionError(ru.sbtqa.tag.pagefactory.exceptions.NoSuchActionError) Method(java.lang.reflect.Method) FactoryRuntimeException(ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with FactoryRuntimeException

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
 * '-&gt;' 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));
}
Also used : HtmlElement(ru.yandex.qatools.htmlelements.element.HtmlElement) Method(java.lang.reflect.Method) FactoryRuntimeException(ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

FactoryRuntimeException (ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)2 JDILogger (com.epam.jdi.uitests.core.logger.JDILogger)1 AndroidDriver (io.appium.java_client.android.AndroidDriver)1 IOSDriver (io.appium.java_client.ios.IOSDriver)1 IOException (java.io.IOException)1 SelenoidCapabilitiesParser (ru.sbtqa.tag.pagefactory.capabilities.SelenoidCapabilitiesParser)1 NoSuchActionError (ru.sbtqa.tag.pagefactory.exceptions.NoSuchActionError)1 AppiumVideoRecorder (ru.sbtqa.tag.pagefactory.mobile.utils.AppiumVideoRecorder)1 HtmlElement (ru.yandex.qatools.htmlelements.element.HtmlElement)1