List of usage examples for org.openqa.selenium WebDriver getCurrentUrl
String getCurrentUrl();
From source file:net.atf4j.webdriver.BrowserFactoryTest.java
License:Open Source License
/** * Verify that verify page loaded.//from w w w. j a v a2 s . c om * * @param webDriver the web driver */ private void verifyPageLoaded(final WebDriver webDriver) { webDriver.get(TEST_URL); final String currentUrl = webDriver.getCurrentUrl(); this.log.info(currentUrl); final String pageTitle = webDriver.getTitle(); this.log.info(pageTitle); }
From source file:net.continuumsecurity.web.drivers.DriverFactory.java
License:Open Source License
private static WebDriver getDriver(String type, boolean isProxyDriver) { WebDriver retVal = instance().findOrCreate(type, isProxyDriver); try {/*w w w . j a v a2s . c o m*/ if (!retVal.getCurrentUrl().equals("about:blank")) { retVal.manage().deleteAllCookies(); } } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } return retVal; }
From source file:OnlineStore.StepDefinitions.java
@And("I click the Product Category") public void clickButton() { WebElement element = driver.findElement(By.xpath("//*[@id=\"menu-item-33\"]/a")); element.click();/*from w w w . j ava 2s . c o m*/ driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); ExpectedCondition e = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return (!d.getCurrentUrl().endsWith(".com/")); } }; wait.until(e); }
From source file:OnlineStore.StepDefinitions.java
@And("^I click the iphone5 picture in the homepage$") public void iClickTheIphonePictureInTheHomepage() { // Write code here that turns the phrase above into concrete actions // String s = driver.findElement(By.xpath("//*[@id=\"footer\"]/section[2]/ul/li[1]/a[1]")).getText(); driver.findElement(By.xpath("//*[@id=\"footer\"]/section[2]/ul/li[1]/a[2]/img")).click(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); ExpectedCondition e = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return (!d.getCurrentUrl().endsWith(".com/")); }// w ww . j av a2 s. com }; wait.until(e); }
From source file:org.alfresco.po.share.cmm.FactoryShareCMMPage.java
License:Open Source License
public HtmlPage getPage(final WebDriver driver) throws PageException { HtmlPage page = resolvePage(driver); // check for Share Error Popup if (page instanceof UnknownSharePage) { try {//from ww w . j a v a2 s .c o m List<WebElement> shareDialogues = driver.findElements(By.cssSelector("div.dijitDialogTitleBar")); for (WebElement shareDialogue : shareDialogues) { if (shareDialogue.isDisplayed()) { if (logger.isDebugEnabled()) { logger.debug(shareDialogue.getText()); } return resolveShareCMMDialoguePage(driver, page); } } } catch (Exception e) { } // check for SharePage if (driver.getCurrentUrl().contains(TPG_HASH)) { return instantiatePage(driver, pages.get("ManageTypesAndAspects")); } else if (driver.getCurrentUrl().contains(PROPERTIES_HASH)) { return instantiatePage(driver, pages.get("ManageProperties")); } else if (driver.getCurrentUrl().contains(FORM_EDITOR_HASH)) { return instantiatePage(driver, pages.get("FormEditor")); } else if (driver.getCurrentUrl().contains(CMM_URL)) { return instantiatePage(driver, pages.get("ModelManager")); } else if (page instanceof AdminConsolePage) { return instantiatePage(driver, AdminConsolePage.class); } } // check for SharePage if (driver.getCurrentUrl().contains(TPG_HASH)) { return instantiatePage(driver, pages.get("ManageTypesAndAspects")); } else if (driver.getCurrentUrl().contains(PROPERTIES_HASH)) { return instantiatePage(driver, pages.get("ManageProperties")); } else if (driver.getCurrentUrl().contains(FORM_EDITOR_HASH)) { return instantiatePage(driver, pages.get("FormEditor")); } else if (driver.getCurrentUrl().endsWith(CMM_URL) || driver.getCurrentUrl().endsWith(VIEW_MODELS_HASH)) { return instantiatePage(driver, pages.get("ModelManager")); } else if (page instanceof AdminConsolePage) { return instantiatePage(driver, AdminConsolePage.class); } else { return page; } }
From source file:org.alfresco.po.share.FactorySharePage.java
License:Open Source License
/** * Creates the appropriate page object based on the current page the {@link WebDriver} is on. * * @param driver WebDriver Alfresco unmanned web browser client * @return SharePage the page object response * @throws PageException/*ww w . ja v a 2s . co m*/ */ public HtmlPage resolvePage(final WebDriver driver) throws PageException { // Determine if user is logged in if not return login page // if (driver.getTitle().toLowerCase().contains(driver.getLanguageValue("login.title"))) if (driver.getTitle().toLowerCase().contains("login")) { return instantiatePage(driver, LoginPage.class); } else { // Share Error PopUp try { WebElement errorPrompt = driver.findElement(By.cssSelector(FAILURE_PROMPT)); if (errorPrompt.isDisplayed()) { return instantiatePage(driver, SharePopup.class); } } catch (NoSuchElementException nse) { } // Check for Share Dialogue try { WebElement shareDialogue = driver.findElement(By.cssSelector(SHARE_DIALOGUE)); if (shareDialogue.isDisplayed() || !driver.findElements(COPY_MOVE_DIALOGUE_SELECTOR).isEmpty()) { HtmlPage response = resolveShareDialoguePage(driver); if (response != null) { return response; } } } catch (NoSuchElementException n) { } // Determine what page we're on based on url return getPage(driver.getCurrentUrl(), driver); } }
From source file:org.alfresco.po.share.FactorySharePage.java
License:Open Source License
@SuppressWarnings("unchecked") /**//from ww w .ja v a 2 s . c om * Instantiates the page object matching the argument. * @param <T> * * @param z {@link WebDriver} * @param pageClassToProxy expected Page object * @return {@link SharePage} page response * @throws Exception */ public <T> T instantiatePage(WebDriver driver, Class<T> pageClassToProxy) throws PageException { if (driver == null) { throw new IllegalArgumentException("WebDriver is required"); } if (pageClassToProxy == null) { throw new IllegalArgumentException("Page object is required for url: " + driver.getCurrentUrl()); } try { //We first create the page object. Page page = (Page) pageClassToProxy.newInstance(); page.setWebDriver(driver); //Wrap it with a decorator to provide htmlelements with webdriver power. WebDriverAwareDecorator decorator = new WebDriverAwareDecorator(driver); //Init HtmlElements with webdriver power. initElements(decorator, page); //Wire spring into page. ac.getAutowireCapableBeanFactory().autowireBean(page); return (T) page; } catch (Exception e) { throw new PageException(CREATE_PAGE_ERROR_MSG, e); } }
From source file:org.alfresco.po.share.FactorySharePage.java
License:Open Source License
public PageElement instantiatePageElement(WebDriver driver, Class<?> pageClassToProxy) { if (driver == null) { throw new IllegalArgumentException("WebDriver is required"); }//from w w w.java 2 s . c o m if (pageClassToProxy == null) { throw new IllegalArgumentException("Page object is required for url: " + driver.getCurrentUrl()); } try { WebDriverAwareDecorator decorator = new WebDriverAwareDecorator(driver); PageElement pageElement = (PageElement) pageClassToProxy.newInstance(); pageElement.setWebDriver(driver); PageFactory.initElements(decorator, pageElement); //Wire spring into page elements. ac.getAutowireCapableBeanFactory().autowireBean(pageElement); return pageElement; } catch (InstantiationException e) { throw new PageException(CREATE_PAGE_ERROR_MSG, e); } catch (IllegalAccessException e) { throw new PageException(CREATE_PAGE_ERROR_MSG, e); } }
From source file:org.alfresco.po.share.ShareUtil.java
License:Open Source License
/** * Methods for navigation bulk import page * * @param driver/*from w ww .j a v a 2s. c o m*/ * @param inPlace * @param userInfo * @return */ public HtmlPage navigateToBulkImport(final WebDriver driver, boolean inPlace, final String... userInfo) { String currentUrl = driver.getCurrentUrl(); String protocolVar = PageUtils.getProtocol(currentUrl); String consoleUrlVar = PageUtils.getAddress(currentUrl); if (inPlace) { currentUrl = String.format("%s%s:%s@%s/" + BULK_IMPORT_IN_PLACE_PAGE, protocolVar, userInfo[0], userInfo[1], consoleUrlVar); logger.info("Property 'currentUrl' is: " + currentUrl); } else { currentUrl = String.format("%s%s:%s@%s/" + BULK_IMPORT_PAGE, protocolVar, userInfo[0], userInfo[1], consoleUrlVar); logger.info("Property 'currentUrl' is: " + currentUrl); } try { logger.info("Navigate to 'currentUrl': " + currentUrl); driver.navigate().to(currentUrl); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Following exception was occurred" + e + ". Param systemUrl was " + currentUrl); } } return factoryPage.getPage(driver).render(); }
From source file:org.alfresco.po.share.ShareUtil.java
License:Open Source License
/** * Base helper method that extracts the url to required alfresco admin location. * Once extracted it formats it with the username and password to allow access to the page. * @param driver//from ww w. j av a2 s.c o m * @param path * @param userInfo * @return * @throws Exception */ public HtmlPage navigateToAlfresco(final WebDriver driver, final String path, final String... userInfo) throws Exception { PageUtils.checkMandatoryParam("WebDriver", driver); PageUtils.checkMandatoryParam("Path", path); PageUtils.checkMandatoryParam("Username and password", userInfo); String currentUrl = driver.getCurrentUrl(); String protocolVar = PageUtils.getProtocol(currentUrl); String consoleUrlVar = PageUtils.getAddress(currentUrl); currentUrl = String.format("%s%s:%s@%s/" + path, protocolVar, userInfo[0], userInfo[1], consoleUrlVar); driver.navigate().to(currentUrl); return factoryPage.getPage(driver).render(); }