List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:com.saucelabs.selenium.client.htmlunit.HtmlUnitTest.java
License:Open Source License
public void testWebDriver() { WebDriver s = SeleniumFactory.createWebDriver("htmlunit:", "http://www.google.com/"); assertEquals("Google", s.getTitle()); s.quit(); }
From source file:com.saucelabs.selenium.client.logging.LoggingSeleniumTest.java
License:Open Source License
public void testWebDriver() { WebDriver s = SeleniumFactory.createWebDriver("log:embedded-rc:*firefox", "http://www.google.com/"); LoggingSelenium ls = (LoggingSelenium) s; Logger l = Logger.getAnonymousLogger(); ls.setLogger(l);//from w w w . ja va2s . co m l.addHandler(new Handler() { @Override public void publish(LogRecord record) { logs.add(record); } @Override public void flush() { } @Override public void close() throws SecurityException { } }); s.get("http://www.google.com/"); assertEquals("Google", s.getTitle()); s.quit(); verifyLog(); }
From source file:com.seleniumtests.driver.WebUIDriver.java
License:Apache License
public static void cleanUp() { IWebDriverFactory iWebDriverFactory = getWebUIDriver().webDriverBuilder; if (iWebDriverFactory != null) { iWebDriverFactory.cleanUp();//from w ww . j a v a 2s .c o m } else { WebDriver driver = driverSession.get(); if (driver != null) { try { driver.quit(); } catch (WebDriverException ex) { ex.printStackTrace(); } driver = null; } } driverSession.remove(); uxDriverSession.remove(); }
From source file:com.sios.stc.coseng.util.Run.java
License:Open Source License
public synchronized void quitDriver() { for (final WebDriver driver : Common.driverCollector) { driver.quit(); }// w w w . j a v a 2 s . c om }
From source file:com.smartqa.utils.WebDriverUtils.java
License:Apache License
/** * close web drvier properly/*from w ww . j av a2s.com*/ * * @param driver */ public static void closeWebDriver(WebDriver driver) { if (driver == null) return; try { String current = driver.getWindowHandle(); Set<String> otherWins = driver.getWindowHandles(); for (String winId : otherWins) if (winId.equals(current)) continue; else driver.switchTo().window(winId).close(); } catch (Exception ex) { LOG.warn("Error happen when close web driver: " + ex.getMessage()); } finally { try { driver.quit(); } catch (Exception ex) { } } }
From source file:com.smash.revolance.ui.model.user.User.java
License:Open Source License
public void stopBot() throws Exception { if (isBrowserActive()) { WebDriver browser = getBrowser(); if (browser != null) { browser.quit(); }//from w ww. j av a 2 s . c o m DriverService driverService = getDriverService(); if (driverService != null) { driverService.stop(); } setBrowserActive(false); } }
From source file:com.spambot.invisicow.SeleniumDriver.java
public void drive(int opt) throws InterruptedException { WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://findtheinvisiblecow.com"); WebElement body = driver.findElement(By.tagName("body")); new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(body)); //start game WebElement button = driver.findElement(By.xpath("//div[@id='loader']//button")); new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(button)); button.click();/*from w ww . j a v a 2 s . c o m*/ for (int i = 0; i < opt - 1; i++) { //so the user sees something Thread.sleep(2500); //win game if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("find.gameStop(true);"); } //again? WebElement congrats = driver.findElement(By.id("modal-congratulations")); new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOf(congrats)); Thread.sleep(1500); WebElement again = driver.findElement(By.xpath("//div[@id='modal-congratulations']//button")); again.click(); } Thread.sleep(2500); //win game one last time if (driver instanceof JavascriptExecutor) { ((JavascriptExecutor) driver).executeScript("find.gameStop(true);"); } Thread.sleep(3000); JOptionPane.showMessageDialog(null, "Goodbye!"); driver.quit(); }
From source file:com.spambot.invisicow.SeleniumDriver.java
public void driveExample() { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new FirefoxDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();//w w w . j a va 2 s . com // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.technophobia.webdriver.substeps.runner.DefaultWebDriverFactory.java
License:Open Source License
public void shutdownWebDriver(WebDriverContext webDriverContext) { LOG.debug("Shutting WebDriver down"); WebDriver webDriver = webDriverContext.getWebDriver(); if (webDriver != null) { webDriver.manage().deleteAllCookies(); webDriver.quit(); }/*from w ww .j ava 2 s . co m*/ }
From source file:com.thoughtworks.selenium.corerunner.Main.java
License:Apache License
public static void main(String[] args) { // java -jar selenium-server-standalone-<version-number>.jar -htmlSuite "*firefox" // "http://www.google.com" "c:\absolute\path\to\my\HTMLSuite.html" // "c:\absolute\path\to\my\results.html" if (args.length < 5) { throw new RuntimeException("Not enough arguments"); }//from w ww . jav a2s .c o m if (!"-htmlSuite".equals(args[0])) { throw new RuntimeException("Apparently not running a test suite"); } WebDriver driver; switch (args[1]) { case "*chrome": case "*firefox": case "*firefoxproxy": case "*firefoxchrome": case "*pifirefox": DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability(MARIONETTE, false); driver = new FirefoxDriver(caps); break; case "*iehta": case "*iexplore": case "*iexploreproxy": case "*piiexplore": driver = new InternetExplorerDriver(); break; case "*googlechrome": driver = new ChromeDriver(); break; case "*MicrosoftEdge": driver = new EdgeDriver(); break; case "*opera": case "*operablink": driver = new OperaDriver(); break; case "*safari": case "*safariproxy": driver = new SafariDriver(); break; default: throw new RuntimeException("Unrecognized browser: " + args[1]); } try { Results results = new Results(); CoreTest test = new CoreTest(args[3]); test.run(results, driver, new WebDriverBackedSelenium(driver, args[2])); } finally { driver.quit(); } }