Example usage for org.openqa.selenium WebDriver close

List of usage examples for org.openqa.selenium WebDriver close

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver close.

Prototype

void close();

Source Link

Document

Close the current window, quitting the browser if it's the last window currently open.

Usage

From source file:com.twiceagain.mywebdriver.startup.DemoBasicWebPageVisualizeElements.java

License:Open Source License

/**
 * @param args the command line arguments
 * @throws java.lang.InterruptedException
 *//*from  w ww.  ja  va2 s  .  c o m*/
public static void main(String[] args) throws InterruptedException {
    WebDriver wd = Drivers.getDriver();
    wd.get("https://news.google.com");
    //Thread.sleep(2000);
    List<WebElement> lwe = wd.findElements(By.xpath(".//div[@class='esc-body']"));
    Drivers.highlightElements(wd, lwe, "article");
    Thread.sleep(5000);// wait 5 secs
    wd.close();
}

From source file:com.twiceagain.mywebdriver.startup.DemoPagesBlanches.java

License:Open Source License

/**
 * @param args the command line arguments
 *///from  w ww.j  av a  2s.  c om
public static void main(String[] args) {

    WebDriver wd = Drivers.getDriver(Drivers.Config.defaultLocalFirefox());

    PagesBlanches page = new PagesBlanches(wd);
    page.setLimiter(new LimiterBasic(null, 200, 6, null));
    page.init("dupont", "sceaux");

    page.processDocuments(new DocumentPrinter());

    wd.close();

}

From source file:com.twiceagain.rservejavademo.webaccess.BasicDriverTest.java

/**
 * Test of _getDriver method, of class BasicDriver.
 * @throws java.lang.InterruptedException
 *//*from w ww .  ja v a 2s.c om*/
@Test
public void testGetDriver() throws InterruptedException {
    System.out.println("getDriver");
    WebDriver expResult = null;
    WebDriver wd = BasicDriver.getDriver();
    wd.get("http://www.google.fr");
    Thread.sleep(1000);
    assert (wd.getTitle().contains("Google"));
    WebElement searchBox = wd.findElement(By.name("q"));
    searchBox.sendKeys("ChromeDriver test");
    searchBox.submit();
    Thread.sleep(5000); // Let the user actually see something!
    wd.close();
}

From source file:com.twiceagain.rservejavademo.webaccess.BasicDriverTest.java

@Test
public void testAttributes() {
    WebDriver wd = BasicDriver.getDriver();
    wd.get("http://www.google.fr");
    WebElement we = wd.findElement(By.tagName("input"));
    System.out.println("Listing attributes : " + BasicDriver.getAttributes(wd, we));
    wd.close();

}

From source file:com.vaadin.testbench.TestBenchDriverTest.java

@Test
public void testTestBenchDriverActsAsProxy() {
    FirefoxDriver mockDriver = createMock(FirefoxDriver.class);
    mockDriver.close();//from   ww w  .j  a  va  2  s  .co  m
    expectLastCall().once();
    WebElement mockElement = createNiceMock(WebElement.class);
    expect(mockDriver.findElement(isA(By.class))).andReturn(mockElement);
    List<WebElement> elements = Arrays.asList(mockElement);
    expect(mockDriver.findElements(isA(By.class))).andReturn(elements);
    mockDriver.get("foo");
    expectLastCall().once();
    expect(mockDriver.getCurrentUrl()).andReturn("foo");
    expect(mockDriver.getPageSource()).andReturn("<html></html>");
    expect(mockDriver.getTitle()).andReturn("bar");
    expect(mockDriver.getWindowHandle()).andReturn("baz");
    Set<String> handles = new HashSet<String>();
    expect(mockDriver.getWindowHandles()).andReturn(handles);
    Options mockOptions = createNiceMock(Options.class);
    expect(mockDriver.manage()).andReturn(mockOptions);
    Navigation mockNavigation = createNiceMock(Navigation.class);
    expect(mockDriver.navigate()).andReturn(mockNavigation);
    mockDriver.quit();
    expectLastCall().once();
    expect(((JavascriptExecutor) mockDriver).executeScript(anyObject(String.class))).andStubReturn(true);
    TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class);
    expect(mockDriver.switchTo()).andReturn(mockTargetLocator);
    replay(mockDriver);

    // TestBenchDriverProxy driver = new TestBenchDriverProxy(mockDriver);
    WebDriver driver = TestBench.createDriver(mockDriver);
    driver.close();
    By mockBy = createNiceMock(By.class);
    assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands);
    assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands);
    driver.get("foo");
    assertEquals("foo", driver.getCurrentUrl());
    assertEquals("<html></html>", driver.getPageSource());
    assertEquals("bar", driver.getTitle());
    assertEquals("baz", driver.getWindowHandle());
    assertEquals(handles, driver.getWindowHandles());
    assertEquals(mockOptions, driver.manage());
    assertEquals(mockNavigation, driver.navigate());
    driver.quit();
    assertEquals(mockTargetLocator, driver.switchTo());

    verify(mockDriver);
}

From source file:com.zaizi.automation.abfts.core.info.TestCaseProperties.java

License:Open Source License

/**
 * @param oldDriver
 */
public static void closeDriver(WebDriver oldDriver) {
    oldDriver.close();
    driver = null;
}

From source file:com.zaizi.sensefymobile.ios.core.info.TestCaseProperties.java

License:Open Source License

public static void closeDriver(WebDriver oldDriver) {
    oldDriver.close();
    driver = null;
}

From source file:de.meethub.adapters.eventbrite.EventbriteAdapterServlet.java

License:Open Source License

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    final WebDriver d = new HtmlUnitDriver();
    try {/*from   w w  w .ja v a2s.co  m*/
        d.get(this.baseUrl);
        new WebDriverWait(d, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.className("js-event-list-container")));
        final List<WebElement> eventElements = d.findElements(By.className("event-card__description"));
        final Calendar calendar = this.convertToCalendar(eventElements);
        final CalendarOutputter outputter = new CalendarOutputter();
        response.setContentType("text/calendar;charset=UTF-8");
        outputter.output(calendar, response.getWriter());
    } catch (final ValidationException | ParseException e) {
        throw new ServletException(e);
    } finally {
        d.close();
    }

}

From source file:de.meethub.adapters.hannoverjs.HjsAdapterServlet.java

License:Open Source License

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    final WebDriver d = new HtmlUnitDriver(true);
    try {/*from w w w.  j  a va 2s.com*/
        d.get(this.baseUrl);
        final WebElement dateElement = new WebDriverWait(d, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.className("ng-binding")));
        final Calendar calendar = convertToCalendar(dateElement);
        final CalendarOutputter outputter = new CalendarOutputter();
        response.setContentType("text/calendar;charset=UTF-8");
        outputter.output(calendar, response.getWriter());
    } catch (final ValidationException | ParseException e) {
        throw new ServletException(e);
    } finally {
        d.close();
    }

}

From source file:de.meethub.adapters.xing.XingAdapterServlet.java

License:Open Source License

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    final WebDriver d = new HtmlUnitDriver(true);
    try {/*  w w w. j  av  a 2s .  c  o m*/
        d.get(this.baseUrl);
        new WebDriverWait(d, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.className("event-preview")));
        final Calendar calendar = this.convertToCalendar(d);
        final CalendarOutputter outputter = new CalendarOutputter();
        response.setContentType("text/calendar;charset=UTF-8");
        outputter.output(calendar, response.getWriter());
    } catch (final ValidationException | ParseException e) {
        throw new ServletException(e);
    } finally {
        d.close();
    }
}