List of usage examples for org.openqa.selenium WebDriver switchTo
TargetLocator switchTo();
From source file:org.mozilla.zest.core.v1.ZestClientWindowHandle.java
License:Mozilla Public License
@Override public String invoke(ZestRuntime runtime) throws ZestClientFailException { WebDriver window;//w w w. j ava 2s . c o m Pattern p = null; 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.nuxeo.ftest.cap.ITRichfileUploadTest.java
License:Apache License
protected void removeFirstUploadedItem() { Locator.waitUntilGivenFunctionIgnoring(new Function<WebDriver, Boolean>() { @Override/*from ww w . j a v a 2s .c om*/ public Boolean apply(WebDriver driver) { try { driver.switchTo().alert().dismiss(); log.warn("Modal dialog present"); } catch (NoAlertPresentException e) { // Expected } List<WebElement> uploadedFiles = driver.findElements(By.xpath(NX_UPLOADED_FILES_XPATH)); Locator.waitUntilEnabledAndClick(uploadedFiles.get(0).findElements(By.tagName("a")).get(0)); Alert confirmRemove = driver.switchTo().alert(); confirmRemove.accept(); return true; } }, StaleElementReferenceException.class); }
From source file:org.nuxeo.functionaltests.fragment.GadgetsContainerFragment.java
License:Open Source License
public WebElement waitForGadgetsLoad(final String mandatoryElements) { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(AbstractTest.LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS).pollingEvery(5, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class); return wait.until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver driver) { WebElement container = getElement(); // iterate through all frames, and ensure opensocial ones are // loaded, and expect at least one opensocial frame boolean oneFound = false; List<WebElement> framesList = driver.findElements(By.xpath("//iframe")); if (framesList != null && !framesList.isEmpty()) { List<String> mandatory = Arrays.asList(mandatoryElements.split(",")); for (WebElement frame : framesList) { String frameName = frame.getAttribute("name"); if (frameName == null || !frameName.startsWith("open-social")) { continue; }/* w w w .ja v a2 s .c o m*/ log.debug(String.format("Found one GWT gadget frame named '%s' ", frameName)); oneFound = true; boolean loaded = false; driver.switchTo().defaultContent(); driver.switchTo().frame(frame); for (String mand : mandatory) { try { driver.findElement(By.id(mand)); loaded = true; log.debug(String.format("Gadget frame '%s' mandatory element '%s' loaded", frameName, mand)); } catch (NoSuchElementException e) { loaded = false; log.debug(String.format( "Gadget frame '%s' not loaded yet, " + "mandatory element '%s' not found", frameName, mand)); break; } } if (!loaded) { log.debug(String.format("Gadget frame '%s' not loaded yet", frameName)); driver.switchTo().defaultContent(); return null; } log.debug(String.format("Gadget frame '%s' loaded", frameName)); driver.switchTo().defaultContent(); } } if (oneFound) { return container; } log.debug("No gadget frame loaded yet"); return null; } }); }
From source file:org.nuxeo.functionaltests.fragment.GadgetsContainerFragment.java
License:Open Source License
public boolean isTaskGadgetEmpty(String gadgetTitle) { WebDriver driver = switchToFrame(gadgetTitle); boolean res = driver.findElement(By.id("nxDocumentListData")).getText() .contains("Your dashboard is empty. There are no tasks that require your intervention."); // switch back to parent page after that driver.switchTo().defaultContent(); return res;//from w w w . j a v a 2 s .c o m }
From source file:org.nuxeo.qa.webdriver.WebdriverSample.java
License:Open Source License
public static void main(String[] args) throws Exception { WebDriver driver = new FirefoxDriver(); LoginPage loginPage = LoginPage.getLoginPage(driver, "http://localhost:8080/nuxeo"); loginPage.login("Administrator", "Administrator", "English (United States)"); driver.findElement(By.linkText("Workspaces")).click(); driver.findElement(By.linkText("test")).click(); driver.findElement(By.id(/* ww w . java2 s . com*/ "document_content:nxl_document_listing_ajax:nxw_listing_ajax_selection_box_with_current_document")) .click(); boolean wait = true; while (wait) { try { driver.findElement(By.id("document_content:clipboardActionsTable_0_0:3:clipboardActionsButton")) .isEnabled(); wait = false; } catch (Exception e) { e.printStackTrace(); } } driver.findElement(By.id("document_content:clipboardActionsTable_0_0:3:clipboardActionsButton")).click(); driver.switchTo().alert().accept(); driver.quit(); }
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/*from w w w. j a va2s. 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) {/* ww w.ja v a2 s.com*/ // 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.richfaces.tests.page.fragments.impl.editor.RichFacesEditor.java
License:Open Source License
/** * Types into the editor given text./*from ww w . j a v a 2s . c om*/ * * @author Jan Papousek * @param text */ public void typeTextToEditor(String text) { WebDriver driver = GrapheneContext.getProxy(); try { // driver.switchTo().frame(page.editorFrame); driver.switchTo().frame(0);// must be this way WebElement activeArea = driver.findElement(By.tagName("body")); activeArea.click(); activeArea.sendKeys(text); } finally { driver.switchTo().defaultContent(); } }
From source file:org.richfaces.tests.showcase.editor.TestAdvancedConfiguration.java
License:Open Source License
@Test public void testUserFocusAutomaticallyOnEditor() { WebDriver driver = GrapheneContext.getProxy(); try {/*from w w w. ja v a2 s.c o m*/ driver.switchTo().frame(0); WebElement activeArea = driver.findElement(By.tagName("body")); String expected = "Test String"; activeArea.sendKeys(expected); assertTrue(activeArea.getText().contains(expected), "The text should be writen to editor without explicit previos focusing!"); } finally { driver.switchTo().defaultContent(); } }
From source file:org.rstudio.studio.selenium.DialogTestUtils.java
License:Open Source License
public static void waitForFocusedInput(final WebDriver driver, final WebElement dialog) { (new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elements = dialog.findElements(By.tagName("input")); if (elements.size() > 0 && driver.switchTo().activeElement().equals(elements.get(0))) { return true; }// w w w . j av a 2s .c om return false; } }); }