Example #1
0
  /**
   * Initializes and returns page class instance
   *
   * @param page - page class
   * @throws PageObjectException
   */
  protected <T extends AbstractPageObject> T initPage(T page) throws PageObjectException {
    // get locators
    Locale locale;
    try {
      locale = new Locale(AutomationMain.getConfigProperties().getContentLanguage());
    } catch (AutomationFrameworkException e) {
      throw new PageObjectException("Main factory initialization exception.", e);
    }

    try {
      Browser browser = Browser.getCurrentBrowser();
      LOG.info("Current URL: " + getCurrentUrl());
      if (StringUtils.isNotBlank(page.getPageUrl())
          && !browser.getCurrentUrl().contains(page.getPageUrl())) {
        LOG.error("Navigate to URL: " + page.getPageUrl());
        throw new PageObjectException(
            "Page validation exception. Expected page URL is "
                + page.getPageUrl()
                + "  URL in fact "
                + getCurrentUrl());
      }
      page.setPageFactory(this);
      page.init(browser, locale);
      LOG.info(page.getClass().getName() + " page created.");
    } catch (Exception e) {
      throw new PageObjectException(
          "Unable initialize "
              + page.getClass().getName()
              + " page by URL: "
              + page.getPageUrl()
              + "\n"
              + e.getMessage(),
          e);
    }
    return page;
  }
Example #2
0
 public String getFormId() {
   return StringUtils.substringAfterLast(browser.getCurrentUrl(), "/");
 }