Example usage for org.openqa.selenium WebDriver quit

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

Introduction

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

Prototype

void quit();

Source Link

Document

Quits this driver, closing every associated window.

Usage

From source file:com.automationpractice.tests.SortBy.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "D:\\selenium test lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://automationpractice.com");

    //this codes is for automated test "sort product" in page "DRESSES" 
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("price:asc");
    driver.navigate().back();// w w w . j a  v a 2s .co m
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("price:desc");
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("name:asc");
    driver.navigate().back();
    driver.findElement(By.xpath(".//*[@id='block_top_menu']/ul/li[2]/a")).click();
    driver.findElement(By.xpath(".//*[@id='selectProductSort']")).sendKeys("name:desc");
    driver.quit();
}

From source file:com.bitbreeds.webrtc.signaling.BrowserTest.java

License:Open Source License

@Test
public void testFull() throws Exception {

    String firefoxPath = System.getProperty("firefox.path");
    //OS X * /Firefox.app/Contents/MacOS/firefox
    System.setProperty("com.bitbreeds.keystore", "./src/test/resources/ws2.jks");
    System.setProperty("com.bitbreeds.keystore.alias", "websocket");
    System.setProperty("com.bitbreeds.keystore.pass", "websocket");

    if (firefoxPath != null) {
        SimpleSignalingExample.main();/* w ww .  j  ava 2 s.com*/

        File fl = new File(".././web/index.html");

        String url = "file://" + fl.getAbsolutePath();
        System.out.println(url);
        FirefoxBinary binary = new FirefoxBinary(new File(firefoxPath));
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        WebDriver driver = new FirefoxDriver(binary, firefoxProfile);
        driver.get(url);

        (new WebDriverWait(driver, 20)).until((ExpectedCondition<Boolean>) d -> {
            assert d != null;
            return d.findElement(By.id("status")).getText().equalsIgnoreCase("ONMESSAGE");
        });

        driver.quit();
    }

}

From source file:com.booleanworks.kryptopterus.selenium.testsuite001.BaseWelcomePageTest.java

@Test
@Ignore/*from  w ww . ja va2 s  .  co m*/
public void testSimple() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("phantomjs.page.settings.userAgent",
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36");
    capabilities.setCapability("phantomjs.page.settings.localToRemoteUrlAccessEnabled", true);
    capabilities.setCapability("phantomjs.page.settings.browserConnectionEnabled", true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
            "/usr/local/bin/phantomjs");
    capabilities.setCapability("takesScreenshot", true);

    WebDriver driver = new PhantomJSDriver((Capabilities) capabilities);
    driver.manage().window().setSize(new Dimension(1200, 800));
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

    // And now use this to visit NetBeans
    driver.get("http://localhost:8084/kryptopterus/");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.netbeans.org");

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:com.btmatthews.selenium.junit4.runner.WebDriverFactory.java

License:Apache License

/**
 * Stop the {@link WebDriver} by issuing a quit command.
 *
 * @param webDriver The {@link WebDriver} instance.
 * @see SeleniumFactory#stop(Object)//  w w  w  .  j  a v a 2  s  .c  om
 */
public void stop(final WebDriver webDriver) {
    webDriver.quit();
}

From source file:com.ceiwc.compugain.setup.TestBase.java

public void browserQuit(WebDriver driver) {
    try {//from w w w . j  a  v  a  2  s . com
        driver.quit();
        driver = null;
    } catch (Exception e) {
        logger.info("Event Driver is Not Initialized");
    }

}

From source file:com.ceiwc.compugain.setup.TestBase.java

public void eventBrowserQuit(WebDriver secondDriver) {
    if (secondDriver != null) {
        try {/*  w ww . ja  v  a2  s. com*/
            secondDriver.quit();
            secondDriver = null;
            logger.info("browser Killed");
        } catch (Exception e) {
            logger.info("Event Driver is Not Initialized");
        }
    } else
        logger.info("No Driver object");
}

From source file:com.cloudbees.test.SeleniumTest.java

License:Apache License

private void testSeleniumDriver(WebDriver webDriver) {
    System.err.println("");
    System.err.println("#############################");
    System.err.println("# TEST WITH " + webDriver);
    System.err.println("#############################");
    try {/*from  w ww  .  j av a2  s. c om*/
        String url = "https://google.com";
        webDriver.get(url);
        Assert.assertEquals("Unexpected page title requesting " + url + " with selenium driver "
                + webDriver.toString() + " displaying " + webDriver.getCurrentUrl(), "Google",
                webDriver.getTitle());
        System.err.println("SUCCESSFULLY invoked Selenium driver" + webDriver.toString() + " with URL "
                + webDriver.getCurrentUrl() + ", page.title='" + webDriver.getTitle() + "'");
    } finally {
        webDriver.close();
        webDriver.quit();
    }
}

From source file:com.coderoad.automation.core.manager.DriverManager.java

License:Open Source License

/**
 * Close./* www.  j av a 2s  .  c  o m*/
 * 
 * @param webDriver the web driver
 */
public static void close(final WebDriver webDriver) {

    webDriver.manage().deleteAllCookies();
    webDriver.quit();
}

From source file:com.comcast.magicwand.drivers.AbstractPhoenixDriver.java

License:Apache License

/**
 * {@inheritDoc}//from  www.  ja  v a2  s. co m
 */
public void quit() {
    WebDriver driver = this.getDriver();
    if (null != driver) {
        driver.quit();
    }
}

From source file:com.ecofactor.qa.automation.newapp.ThermostatControlEETest.java

License:Open Source License

/**
 * Sets the point reason api./*w w  w  .j  a  v  a2  s. co  m*/
 * @param userName the user name
 * @param password the password
 * @param thermostatId the thermostat id
 */
@Test(groups = { Groups.SANITY1, Groups.BROWSER,
        Groups.ANDROID }, dataProvider = "defaultSavingsEnegry", dataProviderClass = CommonsDataProvider.class, priority = 8)
public void setPointReasonAPI(final String userName, final String password, Integer thermostatId) {

    loadPage(userName, password, true);
    thPageOps.openTstatController();
    Assert.assertTrue(thCtrlOpsPage.isPageLoaded(), "Tstat Control Page is not Opened");
    Assert.assertTrue(thCtrlUIPage.isSavingsEnergyLinkDisplayed(), "Savings Energy Link is not displayed");

    WebDriver driver = null;
    try {
        loginPage.setLoggedIn(false);

        LogUtil.setLogString(LogSection.START, "New Browser verfication starts", true);
        driver = createWebDriver();
        loginPage.setDriver(driver);
        thPageOps.setDriver(driver);
        thPageUI.setDriver(driver);
        thCtrlUIPage.setDriver(driver);
        loadPage(userName, password, true);
        thPageOps.openTstatController();
        Assert.assertTrue(thCtrlOpsPage.isPageLoaded(), "Tstat Control Page is not Opened");
        loginPage.setDriver(null);
        thCtrlOpsPage.setDriver(driver);
        String content = thCtrlOpsPage.getEEapi(
                "https://my-apps-qa.ecofactor.com/ws/v1.0/thermostat/" + thermostatId + "/state", null, 200);
        LogUtil.setLogString("Json result :" + content, true);
        JSONObject jsonObj = new JSONObject(content);
        String setPointReason = jsonObj.get("setpoint_reason").toString();
        LogUtil.setLogString("SetPoint reason :" + setPointReason, true);
        driver.navigate().back();
        Assert.assertTrue(setPointReason.equalsIgnoreCase("ee"), "Setpoint Reason is not EE");
        thPageOps.setDriver(null);
        thCtrlOpsPage.setDriver(null);
        thCtrlUIPage.setDriver(null);
        thPageUI.setDriver(null);
        LogUtil.setLogString(LogSection.END, "New Browser verification ends", true);

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        loginPage.setDriver(null);
        thPageOps.setDriver(null);
        thCtrlOpsPage.setDriver(null);
        thCtrlUIPage.setDriver(null);
        thPageUI.setDriver(null);
        if (driver != null) {
            LogUtil.setLogString("Quit driver for new browser", true);
            driver.quit();
        }
    }
    WaitUtil.mediumWait();
    thCtrlOpsPage.closeThermostatControl();
    Assert.assertTrue(thPageUI.isUnderSavingsEnergy(), "Savings Energy is not displayed");
}