List of usage examples for org.openqa.selenium WebDriver getWindowHandle
String getWindowHandle();
From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java
License:Apache License
public void focusInFrameIndex(int... frames) { driver.switchTo().window(driver.getWindowHandle()); for (final int frame : frames) { new WebDriverWait(driver, 60).until(new ExpectedCondition<WebDriver>() { public WebDriver apply(WebDriver driver) { try { return driver.switchTo().frame(frame); } catch (NoSuchFrameException e) { return null; }//from w w w .j ava2 s .co m } public String toString() { return "frame index " + frame + " to be present"; } }); } waitForScript(); }
From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java
License:Apache License
public void waitForFrameToClose(final String frameName) { driver.switchTo().window(driver.getWindowHandle()); if (frameName != null) { try {//www . j a va 2 s . co m driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); new WebDriverWait(driver, 60).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return driver.findElements(By.name(frameName)).isEmpty(); } public String toString() { return "frame " + frameName + " to be absent"; } }); } finally { driver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS); } } waitForScript(); }
From source file:org.jboss.arquillian.graphene.context.TestGrapheneProxyHandler.java
License:Open Source License
@Test public void test_webDriver_methods_which_should_not_return_proxy() { IsNotProxyable isNotProxyable = new IsNotProxyable(); // when/* www . ja va2s . c o m*/ WebDriver driver = Mockito.mock(WebDriver.class, isNotProxyable); Options options = mock(Options.class, isNotProxyable); Navigation navigation = mock(Navigation.class, isNotProxyable); ImeHandler ime = mock(ImeHandler.class, isNotProxyable); Logs logs = mock(Logs.class, isNotProxyable); // then try { driver.toString(); driver.close(); driver.equals(new Object()); driver.get(""); driver.getClass(); driver.getCurrentUrl(); driver.getPageSource(); driver.getTitle(); driver.getWindowHandle(); driver.hashCode(); driver.quit(); driver.toString(); options.addCookie(mock(Cookie.class)); options.deleteAllCookies(); options.deleteCookie(mock(Cookie.class)); options.deleteCookieNamed(""); options.getCookieNamed(""); navigation.back(); navigation.forward(); navigation.to(""); navigation.to(new URL("http://localhost/")); ime.activateEngine(""); ime.deactivate(); ime.getActiveEngine(); ime.isActivated(); logs.get(""); } catch (Exception e) { throw new RuntimeException(e); } assertEquals(Arrays.asList(), isNotProxyable.getViolations()); }
From source file:org.kuali.kra.test.infrastructure.KcSeleniumHelper.java
License:Educational Community License
/** * Asserts that the Expanded Text Area is providing a popup window in which to change its value. Verifies that the that this is working properly by * performing the following://from w ww. j ava2s . co m * <ol> * <li>The text area is set to the {@code originalText} value</li> * <li>The pencil button is clicked on, opening in a popup window</li> * <li>The text in the popup window is examined to verify that it is equal to {@code originalText}</li> * <li>The popup window text area is changed to {@code expandedAreaText}</li> * <li>The "Continue" button is clicked on, closing the popup window</li> * <li>The resulting web page is examined to verify that the text area has changed to the value of {@code expandedAreaText}</li> * </ol> * * @param textAreaId identifies the text area * @param originalText the string to set the original text area to * @param expandedAreaText the string to set in the popup window text area */ public final void assertExpandedTextArea(final String textAreaId, final String originalText, final String expandedAreaText) { set(textAreaId, originalText); String parentWindowHandle = driver.getWindowHandle(); final String textAreaButtonLocator = "//input[starts-with(@name,'methodToCall.updateTextArea') and contains(@name, '" + textAreaId + "')]"; WebElement textAreaButton = new ElementExistsWaiter("Expand button for " + textAreaId + " not found") .until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { return getElementByXPath(textAreaButtonLocator); } }); textAreaButton.click(); switchToPopupWindow(parentWindowHandle); assertEquals(originalText, get(textAreaId)); set(textAreaId, expandedAreaText); final String continueButtonLocator = "methodToCall.postTextAreaToParent"; WebElement continueButton = new ElementExistsWaiter("Continue button for " + textAreaId + " not found") .until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { WebElement element = null; List<WebElement> elements = getActiveElementsByName(continueButtonLocator, false); if (!elements.isEmpty()) { element = elements.get(0); } return element; } }); continueButton.click(); driver.switchTo().window(parentWindowHandle); assertEquals(expandedAreaText, get(textAreaId)); }
From source file:org.kuali.rice.krad.labs.transactional.LabsLookupTravelAuthorizationDocumentCloseActionAft.java
License:Educational Community License
public void testTravelAuthorizationDocumentLookupAndClose() throws Exception { final String xpathExpression = "//iframe[1]"; driver.switchTo().frame(driver.findElement(By.xpath(xpathExpression))); // search based on document type waitAndTypeLabeledInput("Document Type:", "TravelAuthorization"); // click the search button jGrowl("Click the Search button"); final String imgXpath = "//input[contains(@src,'/kr/static/images/buttonsmall_search.gif')]"; waitAndClick(By.xpath(imgXpath));//from w w w . j av a 2 s . co m // click on the first item returned. jGrowl("Click on the first result in status SAVED returned from the search."); String windowHandle = driver.getWindowHandle(); waitAndClick(By.xpath("//td[contains(text(),'SAVED')]/../td[1]/a")); // wait for the new window to pop up new WebDriverWait(driver, 10).until(new ExpectedCondition<Object>() { @Override public Object apply(WebDriver driver) { //Wait until we have at least two windows. return driver.getWindowHandles().size() > 1; } }); // switch focus to the new handle for (String handle : driver.getWindowHandles()) { if (!handle.equals(windowHandle)) { driver.switchTo().window(handle); break; } } // click the close button waitAndClickButtonByText("Close", WebDriverUtils.configuredImplicityWait() * 10); waitAndClickCancelSaveOnClose(); waitForTextPresent("Development made easy"); }
From source file:org.mozilla.zest.core.v1.ZestClientWindowHandle.java
License:Mozilla Public License
@Override public String invoke(ZestRuntime runtime) throws ZestClientFailException { WebDriver window; Pattern p = null;/*from w w w . ja v a2 s .com*/ String runUrl = runtime.replaceVariablesInString(this.url, true); if (this.isRegex()) { p = Pattern.compile(runUrl); } boolean found = false; for (WebDriver wd : runtime.getWebDrivers()) { for (String wh : wd.getWindowHandles()) { window = wd.switchTo().window(wh); if (this.isRegex()) { if (p.matcher(window.getCurrentUrl()).matches()) { runtime.addWebDriver(this.windowHandle, wd); runtime.debug( "Matched window " + window.getWindowHandle() + " url: " + window.getCurrentUrl()); found = true; break; } else { runtime.debug("Didnt match window " + window.getWindowHandle() + " url: " + window.getCurrentUrl()); } } else { if (window.getCurrentUrl().equals(runUrl)) { runtime.addWebDriver(this.windowHandle, wd); runtime.debug( "Matched window " + window.getWindowHandle() + " url: " + window.getCurrentUrl()); found = true; break; } else { runtime.debug("Didnt match window " + window.getWindowHandle() + " url: " + window.getCurrentUrl()); } } } } if (!found) { runtime.output("Failed to find window " + this.getUrl() + " regex=" + this.isRegex()); throw new ZestClientFailException(this, "Failed to find window " + this.getUrl() + " regex=" + this.isRegex()); } return this.windowHandle; }
From source file:org.qe4j.web.OpenWebDriverTest.java
License:Open Source License
@Test public void getWindowHandle() throws IOException { Properties properties = getProperties(); WebDriver driver = new OpenWebDriver(properties); driver.get(URL);/* ww w . ja v a 2s .c om*/ Assert.assertEquals(Integer.valueOf(driver.getWindowHandle()).getClass(), Integer.class, "valid window handle"); }
From source file:org.richfaces.photoalbum.ftest.webdriver.utils.PhotoalbumUtils.java
License:Open Source License
public static void loginWithSocial(Class<? extends SocialLoginPage> pageClass, final WebDriver browser, WebElement loginLink, boolean workaroundGplusAccInChache) { String originalWindow = browser.getWindowHandle(); Graphene.guardAjax(loginLink).click(); Graphene.waitAjax().until(new Predicate<WebDriver>() { @Override/* www . j ava 2 s . c o m*/ public boolean apply(WebDriver input) { return browser.getWindowHandles().size() == 2; } @Override public String toString() { return "2 windows should be opened, but have: " + browser.getWindowHandles().size(); } }); Set<String> windowHandles = browser.getWindowHandles(); windowHandles.remove(originalWindow); try { WebDriver window = browser.switchTo().window(windowHandles.iterator().next()); Graphene.waitModel().until().element(By.tagName("body")).is().visible(); Graphene.createPageFragment(pageClass, window.findElement(By.tagName("body"))) .login("rf.photoalbum@gmail.com", "rf.photoalbumrf.photoalbum"); } finally { browser.switchTo().window(originalWindow); PhotoalbumUtils.waitFor(5000);// FIXME: replace with some wait condition Graphene.waitModel().until(new Predicate<WebDriver>() { @Override public boolean apply(WebDriver input) { return browser.getWindowHandles().size() == 1; } @Override public String toString() { return "Only one window should be opened, but have: " + browser.getWindowHandles().size(); } }); } }
From source file:org.richfaces.photoalbum.ftest.webdriver.utils.PhotoalbumUtils.java
License:Open Source License
public static void loginWithSocial(Class<? extends SocialLoginPage> pageClass, final WebDriver browser, WebElement loginLink) {// w ww . j ava 2 s . c om // in case this incovation targets G+ login, check if G+ credentials were provided; if not then throw IllegalArgumentException if (GPlusLoginPage.class.equals(pageClass) && (System.getProperty("googlePlus.username").equals("undefined") || System.getProperty("googlePlus.password").equals("undefined"))) { throw new IllegalArgumentException( "G+ login was invoked but no login parameters were provided. Please specify them via -DgooglePlus.username and -DgooglePlus.password!"); } String originalWindow = browser.getWindowHandle(); Graphene.guardAjax(loginLink).click(); Graphene.waitModel().until(new Predicate<WebDriver>() { @Override public boolean apply(WebDriver input) { return browser.getWindowHandles().size() == 2; } @Override public String toString() { return "2 windows should be opened, but have: " + browser.getWindowHandles().size(); } }); Set<String> windowHandles = browser.getWindowHandles(); windowHandles.remove(originalWindow); try { WebDriver window = browser.switchTo().window(windowHandles.iterator().next()); Graphene.waitModel().until().element(By.tagName("body")).is().visible(); SocialLoginPage loginPage = Graphene.createPageFragment(pageClass, window.findElement(By.tagName("body"))); if (GPlusLoginPage.class.equals(pageClass)) { //G+ credential are extracted from system property loginPage.login(System.getProperty("googlePlus.username"), System.getProperty("googlePlus.password")); } else { //FCB test account credentials are hardcoded and usable by anyone, should not result in acc being locked loginPage.login("vocfryc_wongwitz_1429527192@tfbnw.net", "12345"); } } finally { browser.switchTo().window(originalWindow); PhotoalbumUtils.waitFor(5000);// FIXME: replace with some wait condition Graphene.waitModel().until(new Predicate<WebDriver>() { @Override public boolean apply(WebDriver input) { return browser.getWindowHandles().size() == 1; } @Override public String toString() { return "Only one window should be opened, but have: " + browser.getWindowHandles().size(); } }); } }
From source file:org.safs.selenium.SeleniumGUIUtilities.java
License:Open Source License
/** * selects a window to send future commands to * @param selenium Current Selenium object * @param id windowId--can be null/*from ww w . j a v a 2s . co m*/ * @param timeout how long to wait for the window in seconds * @return whether window was found */ public boolean selectWindow(Selenium selenium, String id, long timeout) { // workaround Selenium.selectWindow deadlock defect // ThreadedSelectWindow selectWindow = new ThreadedSelectWindow(Thread.currentThread(), selenium, id, timeout); try { selectWindow.start(); Thread.sleep((timeout * 1000) + 1000); //backup timeout for deadlocks } catch (Exception e) { } if (selectWindow.isSearching()) { Log.debug("SGU: selectWindow thread may have deadlocked after " + selectWindow.searchSeconds() + " seconds."); } // hasten cleanup boolean found = selectWindow.isSelected(); selectWindow = null; if (!found) { WebDriver driver = null; try { if (selenium instanceof com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium) { //WebDriver driver = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver(); driver = ((com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium) selenium) .getWrappedDriver(); } } catch (Throwable noclass) { Log.debug( "SGU: selectWindow handling older selenium install " + noclass.getClass().getSimpleName()); /** WebDriverBackedSelenium version 37 move to com.thoughtworks.selenium.webdriven in 42 selenium version try{ if(selenium instanceof org.openqa.selenium.WebDriverBackedSelenium){ driver = ((org.openqa.selenium.WebDriverBackedSelenium) selenium).getWrappedDriver(); } }catch(Throwable ignore){ Log.debug("SGU: selectWindow ignoring newer selenium install "+ ignore.getClass().getSimpleName()); } **/ } if (driver != null) { driver.switchTo().window(driver.getWindowHandle()); found = true; } } Log.info("SGU: selectWindow found window? " + found); return found; }