List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:com.mkl.websuites.internal.browser.SwitchBrowserTest.java
License:Apache License
@Override protected void runTest() throws Throwable { runnableForBrowser.runForBrowser(browserName); WebDriver driver = browserController.getWebDriver(); // check if first test, then nothing to close yet, otherwise close: if (driver != null) { driver.quit(); }/*w ww . ja v a2 s. com*/ String closedBrowser = browserController.removeCurrentBrowser(); log.debug("removing browser [ " + closedBrowser + "] from list of browsers to run"); browserController.setNextWebDriver(); }
From source file:com.mycompany.selenium.SeleniumExample.java
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver"); // 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 ChromeDriver(); // System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver"); // 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 av a 2 s. co m*/ // 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.mycompany.seleniumtest.Selenium2Example.java
public static void main(String[] args) { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver"); System.setProperty("webdriver.safari.driver", "/usr/bin/safaridriver"); //WebDriver driver = new ChromeDriver(); WebDriver driver = new ChromeDriver(); // And now use this to visit the cars program driver.get("http://localhost:3000/"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); //verify the page is loaded, wait 10 seconds if it doesn't try {//from www. j a v a2 s.co m driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); System.out.println("Page loaded!"); } catch (Exception e) { System.err.println(e.getMessage()); System.err.println(e.getStackTrace()); } int rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); if (rowCount == 5) { System.out.println(rowCount + " is the row count!"); } else { System.out.println("rowcount should be different!"); } // Find the filter input element by its name WebElement searchFilter = driver.findElement(By.id("filter")); // Enter 2002 to search for searchFilter.sendKeys("2002"); //check if there are two rows left rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); System.out.println("Row count after filter is: " + rowCount); searchFilter.clear(); searchFilter.sendKeys(""); rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size(); System.out.println("Row count after filter is: " + rowCount); //Close the browser driver.quit(); }
From source file:com.mycompany.seliniumtest.Selenium2Example.java
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "/usr/local/Cellar/geckodriver/geckodriver"); // 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(); //WebDriver driver = new ChromeDriver(); WebDriver driver = new FirefoxDriver(); //WebDriver driver = new HtmlUnitDriver(); // 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();//from w ww . ja v a 2s.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.mycompany.webcalculator.OperationsSeleniumTest.java
public void dispose(WebDriver driver) { driver.close(); driver.quit(); }
From source file:com.openones.auto.selen.Sample01.java
License:Apache License
public static void main(String[] args) { // 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(); //WebDriver driver = new InternetExplorerDriver(); // 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();/*from w ww.j av a 2s . co m*/ // 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.qwazr.crawler.web.driver.BrowserDriverBuilder.java
License:Apache License
public BrowserDriver build() throws ReflectiveOperationException, SecurityException { BrowserDriverEnum browserType = BrowserDriverEnum.html_unit; final WebCrawlDefinition.ProxyDefinition proxyDef; DesiredCapabilities capabilities = null; if (crawlDefinition != null) { // Choose a browser type if (crawlDefinition.browser_type != null) browserType = crawlDefinition.browser_type; proxyDef = selectProxy();/*from w w w .j ava 2 s .c o m*/ // Setup the proxy if (proxyDef != null) { capabilities = checkCapabilities(capabilities); org.openqa.selenium.Proxy proxy = new Proxy(); if (proxyDef.http_proxy != null) proxy.setHttpProxy(proxyDef.http_proxy); if (proxyDef.ftp_proxy != null) proxy.setFtpProxy(proxyDef.ftp_proxy); if (proxyDef.ssl_proxy != null) proxy.setSslProxy(proxyDef.ssl_proxy); if (proxyDef.socks_proxy != null) proxy.setSocksProxy(proxyDef.socks_proxy); if (proxyDef.socks_username != null) proxy.setSocksUsername(proxyDef.socks_username); if (proxyDef.socks_password != null) proxy.setSocksPassword(proxyDef.socks_password); if (proxyDef.no_proxy != null) proxy.setNoProxy(proxyDef.no_proxy); if (proxyDef.proxy_autoconfig_url != null) proxy.setProxyAutoconfigUrl(proxyDef.proxy_autoconfig_url); capabilities.setCapability(CapabilityType.PROXY, proxy); } // Setup the language if (crawlDefinition.browser_language != null) { capabilities = checkCapabilities(capabilities); capabilities.setCapability(AdditionalCapabilities.QWAZR_BROWSER_LANGUAGE, crawlDefinition.browser_language); if (browserType == BrowserDriverEnum.phantomjs) capabilities.setCapability( PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", crawlDefinition.browser_language); } // Download images if (crawlDefinition.download_images != null) { capabilities = checkCapabilities(capabilities); if (browserType == BrowserDriverEnum.phantomjs) capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "loadImages", crawlDefinition.download_images); } // Web security if (crawlDefinition.web_security != null) { capabilities = checkCapabilities(capabilities); if (browserType == BrowserDriverEnum.phantomjs) capabilities.setCapability( PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "webSecurityEnabled", crawlDefinition.web_security); } // Choose a browser name if (crawlDefinition.browser_name != null) { capabilities = checkCapabilities(capabilities); capabilities.setBrowserName(crawlDefinition.browser_name); } if (crawlDefinition.browser_version != null) { capabilities = checkCapabilities(capabilities); capabilities.setVersion(crawlDefinition.browser_version); } // Javascript capability if (crawlDefinition.javascript_enabled != null) { capabilities = checkCapabilities(capabilities); capabilities.setJavascriptEnabled(crawlDefinition.javascript_enabled); if (browserType == BrowserDriverEnum.phantomjs) capabilities.setCapability( PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "javascriptEnabled", crawlDefinition.javascript_enabled); } } else proxyDef = null; if (browserType == BrowserDriverEnum.phantomjs) { capabilities = checkCapabilities(capabilities); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--webdriver-loglevel=NONE", "--ignore-ssl-errors=true" }); } final WebDriver driver = browserType.getNewInstance(capabilities); try { final BrowserDriver browserDriver = new BrowserDriver(browserType, driver, proxyDef); browserDriver.setTimeouts(crawlDefinition.implicitly_wait, crawlDefinition.page_load_timeout, crawlDefinition.script_timeout); if (crawlDefinition.cookies != null) for (Map.Entry<String, String> cookie : crawlDefinition.cookies.entrySet()) driver.manage().addCookie(new Cookie(cookie.getKey(), cookie.getValue())); return browserDriver; } catch (Exception e) { driver.quit(); throw e; } }
From source file:com.safeway.app.appcert.smoketester.SmokeTester.java
@Test public void executeSmokeTest() throws Exception { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. System.setProperty("webdriver.chrome.driver", "C:\\Nino\\ChromeWebDriver\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); TestCaseReader tcreader = new TestCaseReader(); List<TestScriptTemplate> tcl = tcreader.readExcel(); List<TestScriptTemplate> validatedTestScript = new ArrayList(); String log_execution = ""; Iterator<TestScriptTemplate> i = tcl.iterator(); while (i.hasNext()) { TestScriptTemplate testscript = i.next(); //collect the results TestScriptTemplate testexecution = new TestScriptTemplate(); testexecution.setAppCode(testscript.getAppCode()); log_execution = log_execution + " Start smoke testing for application code: " + testexecution.getAppCode(); //access the URL driver.get(testscript.getAppURL()); //login if not yet if (driver.getCurrentUrl().contains("identity.safeway.com")) { //key in userid and password WebElement weusername = driver.findElement(By.id("username")); //System.out.println("tag:" + weusername.getTagName()); weusername.sendKeys(testscript.getAppUserID()); WebElement wepassword = driver.findElement(By.id("password")); //System.out.println("tag:" + wepassword.getTagName()); wepassword.sendKeys(testscript.getAppPassword()); WebElement weloginform = driver.findElement(By.name("loginData")); //System.out.println("tag:" + weloginform.getTagName()); weloginform.submit();/*w w w. j av a 2 s . c om*/ } //recoding URL; required so no need to check for nullity testexecution.setAppURL(driver.getCurrentUrl()); log_execution = log_execution + " Current URL: " + driver.getCurrentUrl(); //recoding title; required so no need to check for nullity testexecution.setHomePageTitle(driver.getTitle()); log_execution = log_execution + " Login Successful"; log_execution = log_execution + " Page Title: " + driver.getTitle(); if (isElementExist(testscript.getHomePageElementType(), testscript.getHomePageElement(), driver)) { System.out.println("Element match!" + testscript.getHomePageElement()); log_execution = log_execution + " Home Page Element validation..."; testexecution.setHomePageElement(testscript.getHomePageElement()); } else { testexecution.setHomePageElement("not found"); } //next page validation if (!testscript.getLevel1URL().isEmpty() || !testscript.getLevel1URL().equals("")) { //go to next level page driver.get(testscript.getLevel1URL()); log_execution = log_execution + " Next Page validation URL: " + testscript.getLevel1URL(); testexecution.setLevel1URL(driver.getCurrentUrl()); System.out.println("execution log: current level 1 URL on set" + testexecution.getLevel1URL()); if (!testscript.getLevel1PageTitle().isEmpty() || !testscript.getLevel1PageTitle().equals("")) { testexecution.setLevel1PageTitle(driver.getTitle()); log_execution = log_execution + " Next Page title validation: " + driver.getTitle(); } if (isElementExist(testscript.getLevel1ElementType(), testscript.getLevel1Element(), driver)) { testexecution.setLevel1Element(testscript.getLevel1Element()); log_execution = log_execution + " Next Page element validation: " + testscript.getLevel1Element(); } else { testexecution.setLevel1Element("not found"); } } testexecution.setLogs(log_execution); System.out.println("Execution Log: " + log_execution); log_execution = ""; SmokeTestValidator testvalidator = new SmokeTestValidator(testscript); TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution); validatedTestScript.add(testingresult); } tcreader.writetoExcel(validatedTestScript); //Close the browser driver.quit(); //return log_execution; }
From source file:com.saucelabs.sauce_ondemand.driver.SauceOnDemandTest.java
License:Open Source License
public void testWebDriver() throws IOException, InterruptedException { WebDriver s = SeleniumFactory.createWebDriver( "sauce-ondemand:?max-duration=30&os=Linux&browser=firefox&browser-version=3.", "http://www.google.com/"); assertEquals("Google", s.getTitle()); SauceOnDemandSelenium ss = (SauceOnDemandSelenium) s; assertNotNull(ss.getSessionIdValue()); WebDriver augmentedDriver = new Augmenter().augment(s); File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); ss.jobPassed();//from w w w. j a va 2s. c om s.quit(); Thread.sleep(15000); System.out.println(ss.getSeleniumServerLogFile()); System.out.println(ss.getVideo()); IOUtils.copy(ss.getSeleniumServerLogFileInputStream(), System.out); }
From source file:com.saucelabs.selenium.client.embedded_rc.EmbeddedSeleniumRCTest.java
License:Open Source License
public void testWebDriver() { WebDriver s = SeleniumFactory.createWebDriver("embedded-rc:*firefox", "http://www.google.com/"); assertEquals("Google", s.getTitle()); s.quit(); }