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");
}
Aggregations