Search in sources :

Example 1 with PageEntry

use of ru.sbtqa.tag.pagefactory.annotations.PageEntry in project page-factory-2 by sbtqa.

the class PageManager method changeUrlByTitle.

/**
 * Redirect to WebElementsPage by WebElementsPage Entry url value
 *
 * @param packageName a {@link java.lang.String} object.
 * @param title a {@link java.lang.String} object.
 * @return a WebElementsPage object.
 * @throws ru.sbtqa.tag.pagefactory.exceptions.PageInitializationException
 * TODO
 */
public static Page changeUrlByTitle(String packageName, String title) throws PageInitializationException {
    Class<?> pageClass = getPageClass(packageName, title);
    if (pageClass == null) {
        return null;
    }
    Annotation annotation = pageClass.getAnnotation(PageEntry.class);
    if (annotation != null && !((PageEntry) annotation).url().isEmpty()) {
        if (PageFactory.getWebDriver().getCurrentUrl() == null) {
            throw new AutotestError("Current URL is null");
        } else {
            try {
                URL currentUrl = new URL(PageFactory.getWebDriver().getCurrentUrl());
                String finalUrl = new URL(currentUrl.getProtocol(), currentUrl.getHost(), currentUrl.getPort(), ((PageEntry) annotation).url()).toString();
                PageFactory.getWebDriver().navigate().to(finalUrl);
            } catch (MalformedURLException ex) {
                LOG.error("Failed to get current url", ex);
            }
        }
        return bootstrapPage(pageClass);
    }
    throw new AutotestError("WebElementsPage " + title + " doesn't have fast URL in PageEntry");
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) MalformedURLException(java.net.MalformedURLException) PageEntry(ru.sbtqa.tag.pagefactory.annotations.PageEntry) Annotation(java.lang.annotation.Annotation) URL(java.net.URL)

Aggregations

Annotation (java.lang.annotation.Annotation)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 PageEntry (ru.sbtqa.tag.pagefactory.annotations.PageEntry)1 AutotestError (ru.sbtqa.tag.qautils.errors.AutotestError)1