List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:org.mifos.server.workspace.SeleniumTest.java
License:Open Source License
@Test public void testSearchMifosOnGoogle() throws Exception { WebDriver wd = new FirefoxDriver(); try {/* w w w. j av a 2 s . c o m*/ wd.get("http://www.google.com"); WebElement element = wd.findElement(By.name("q")); element.sendKeys("Mifos"); element.submit(); } finally { wd.quit(); } }
From source file:org.mifos.server.workspace.WorkspaceServerLauncherTest.java
License:Open Source License
@Test public void testLogin() throws Exception { WebDriver wd = new FirefoxDriver(); wd.get(getAppURL());//from ww w . j ava2 s . c om wd.findElement(By.id(UID)).sendKeys("mifos"); wd.findElement(By.id(PWD)).sendKeys("testmifos"); wd.findElement(By.id(BTN)).click(); Assert.assertTrue(wd.getPageSource().contains("Mifos")); Assert.assertTrue(wd.getPageSource().contains("Home")); Assert.assertTrue(wd.getPageSource().contains("Search")); wd.quit(); }
From source file:org.mozilla.zest.core.v1.ZestClientWindowClose.java
License:Mozilla Public License
@Override public String invoke(ZestRuntime runtime) throws ZestClientFailException { WebDriver wd = runtime.getWebDriver(this.getWindowHandle()); if (wd == null) { // No point throwing an exception as we were going to close it anyway return null; }/*from w w w . ja va 2 s. c o m*/ // Wait for the specified number of seconds, unless the window closes by itself if (this.sleepInSeconds > 0) { int sleepInMs = this.sleepInSeconds * 1000; while (sleepInMs > 0) { wd = runtime.getWebDriver(this.getWindowHandle()); if (wd == null) { break; } try { Thread.sleep(200); } catch (InterruptedException e) { // Ignore } sleepInMs -= 200; } } if (wd != null) { try { wd.close(); } catch (Exception e) { // Ignore, it might have already closed } runtime.removeWebDriver(getWindowHandle()); if (runtime.getWebDrivers().size() == 0 && this.getNext() == null) { // We've closed all of the windows and this is the last statement // Explicitly quit - currently needed for the phantomjs driver, otherwise it never returns :/ wd.quit(); } } return null; }
From source file:org.musetest.selenium.steps.OpenBrowser.java
License:Open Source License
@Override public StepExecutionResult executeImplementation(StepExecutionContext context) throws MuseExecutionError { // find the provider WebDriverProviderConfiguration provider = getValue(_provider, context, false, WebDriverProviderConfiguration.class); final StepExpressionContext expression_context = new StepExpressionContext(_project, getConfiguration()); if (provider == null) { ValueSourceConfiguration provider_config = getConfiguration().getSource(PROVIDER_PARAM); throw new StepConfigurationError("Unable to locate WebdriverProvider from source: " + context.getProject().getValueSourceDescriptors().get(provider_config) .getInstanceDescription(provider_config, expression_context)); }/*w w w .j a v a 2s . co m*/ SeleniumBrowserCapabilities capabilities = getValue(_browser, context, false, SeleniumBrowserCapabilities.class); if (capabilities == null) { ValueSourceConfiguration browser_config = getConfiguration().getSource(PROVIDER_PARAM); throw new StepConfigurationError("Unable to locate SeleniumBrowserCapabilities from source: " + context.getProject().getValueSourceDescriptors().get(browser_config) .getInstanceDescription(browser_config, expression_context)); } WebDriver driver = provider.getDriver(capabilities, context); if (driver == null) { ValueSourceConfiguration provider_config = getConfiguration().getSource(PROVIDER_PARAM); throw new StepConfigurationError(String.format( "The WebdriverProvider (%s) was not able to provide a browser matching the specified capabilities (%s).", context.getProject().getValueSourceDescriptors().get(provider_config).getInstanceDescription( provider_config, expression_context), capabilities.toDesiredCapabilities().toString())); } BrowserStepExecutionContext.putDriver(driver, context); context.registerShuttable(() -> { try { driver.quit(); } catch (Exception e) { LOG.error("Exception encountered while cleaning up the driver", e); } }); return new BasicStepExecutionResult(StepExecutionStatus.COMPLETE); }
From source file:org.netbeans.modules.jackpot30.web.ui.test.OverallTest.java
License:Open Source License
@Test public void overallTest() throws Exception { // WebDriver driver = new FirefoxDriver(); WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_10); ((HtmlUnitDriver) driver).setJavascriptEnabled(true); try {//from w w w.j a v a2 s . c om driver.get("http://localhost:" + System.getProperty("PORT", "9998") + "/index/ui/index.html"); //wait for the page to be rendered: new WebDriverWait(driver, 20).until(new Predicate<WebDriver>() { public boolean apply(WebDriver t) { List<WebElement> cb = t.findElements(By.id("projectCheckBox-data")); return !cb.isEmpty() && cb.get(0).isDisplayed(); } }); WebElement searchInput = driver.findElements(By.id("search-input")).get(0); searchInput.sendKeys("ClassA"); searchInput.submit(); WebElement link = new WebDriverWait(driver, 20).until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver t) { List<WebElement> cb = t.findElements(By.tagName("a")); for (WebElement we : cb) { String href = we.getAttribute("href"); if (href != null && href.contains("goto=CLASS:org.netbeans.modules.jackpot30.example.ClassA")) return we; } return null; } }); link.click(); WebElement methodIdentifierSpan = new WebDriverWait(driver, 20) .until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver t) { List<WebElement> cb = t.findElements(By.tagName("span")); for (WebElement we : cb) { String href = we.getAttribute("jpt30pos"); if (href != null && href.equals("88")) return we; } return null; } }); String classes = methodIdentifierSpan.getAttribute("class"); Assert.assertTrue(classes.contains("identifier") && classes.contains("method") && classes.contains("declaration") && classes.contains("public")); methodIdentifierSpan.click(); Assert.assertEquals( Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java", "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"), usagesList(driver)); findCheckbox(driver, "showUsages").click(); //uncheck Assert.assertEquals(Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java"), usagesList(driver)); findCheckbox(driver, "showUsages").click(); //check Assert.assertEquals( Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java", "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"), usagesList(driver)); findCheckbox(driver, "showSubtypes").click(); //uncheck Assert.assertEquals(Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"), usagesList(driver)); findCheckbox(driver, "showSubtypes").click(); //uncheck Assert.assertEquals( Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java", "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"), usagesList(driver)); } finally { driver.quit(); } }
From source file:org.nsesa.editor.gwt.an.it.SeleniumIT.java
License:EUPL
public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://localhost:8080/editor/amendment.html?documentID=1"); final String title = driver.getTitle(); new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() { @Override// w w w . j a va 2 s . c o m public Boolean apply(WebDriver input) { return input.getTitle().toLowerCase().contains("document 1"); } }); Assert.assertEquals("Document 1 - Nsesa Editor", driver.getTitle()); driver.quit(); }
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(/*from w ww. j av a2 s .c om*/ "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.openlmis.functional.ChromeTest.java
License:Open Source License
@Test public void testGoogleSearch() { // Optional, if not specified, WebDriver will search your path for chromedriver. System.setProperty("webdriver.chrome.driver", "/home/mesh/Programs/chromedriver"); WebDriver driver = new ChromeDriver(); driver.get("http://www.google.com/xhtml"); WebElement searchBox = driver.findElement(By.name("q")); searchBox.sendKeys("ChromeDriver"); searchBox.submit();/*from ww w .j a v a 2s.co m*/ driver.quit(); }
From source file:org.openqa.grid.e2e.DemoTmp.java
License:Apache License
@Test(invocationCount = 3, threadPoolSize = 3) public void test() throws MalformedURLException, InterruptedException { WebDriver driver = null; try {/* w w w. ja v a 2 s .c o m*/ DesiredCapabilities ff = DesiredCapabilities.firefox(); driver = new RemoteWebDriver(new URL("http://" + hubIp + ":4444/grid/driver"), ff); driver.get("http://" + hubIp + ":4444/grid/console"); Assert.assertEquals(driver.getTitle(), "Grid overview"); } finally { driver.quit(); } }
From source file:org.openqa.grid.e2e.misc.GridDistributionTest.java
License:Apache License
private static void stopDrivers(List<WebDriver> drivers) { for (WebDriver driver : drivers) { try {//from www. jav a2 s . c o m driver.quit(); } catch (Exception e) { System.out.println(e.toString()); } } drivers.clear(); }