List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:io.github.bonigarcia.wdm.test.PerformanceRemoteTest.java
License:Apache License
@After public void teardown() throws InterruptedException { ExecutorService executor = newFixedThreadPool(NUMBER_OF_BROWSERS); CountDownLatch latch = new CountDownLatch(NUMBER_OF_BROWSERS); for (int i = 0; i < NUMBER_OF_BROWSERS; i++) { final WebDriver driver = driverList.get(i); final int j = i; executor.execute(() -> {// w ww . ja v a 2 s. c o m try { if (driver != null) { driver.quit(); } else { System.out.println("**** Error with driver " + j); } } finally { latch.countDown(); } }); } latch.await(); executor.shutdown(); }
From source file:io.github.bonigarcia.wdm.test.StabilityTest.java
License:Apache License
@Test public void test() throws InterruptedException { CountDownLatch latch = new CountDownLatch(NUM_THREADS); ExecutorService executorService = newFixedThreadPool(NUM_THREADS); for (int i = 0; i < NUM_THREADS; i++) { executorService.submit(() -> { try { WebDriverManager.chromedriver().setup(); ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); WebDriver driver = new ChromeDriver(options); driver.get("https://bonigarcia.github.io/selenium-jupiter/"); String title = driver.getTitle(); System.out.println(title); driver.quit(); } finally { latch.countDown();/* w w w.jav a 2 s . co m*/ } }); } latch.await(); executorService.shutdown(); }
From source file:io.github.mike10004.vhs.testsupport.MakeFileUploadHar.java
License:Open Source License
@SuppressWarnings("UnusedReturnValue") public static net.lightbody.bmp.core.har.Har main(Charset harOutputCharset, File binaryFile) throws IOException { File harFile = File.createTempFile("traffic-with-file-upload", ".har"); int port = 49111; int proxyPort = 60999; String landingHtml = "<!DOCTYPE html>\n" + "<html>\n" + "<body>\n" + " <form method=\"post\" action=\"/upload\" enctype=\"multipart/form-data\">\n" + " <input type=\"file\" name=\"f\" required>\n" + " <label>Tag <input type=\"text\" name=\"tag\" value=\"this will be url-encoded\"></label>\n" + " <input type=\"submit\" value=\"Upload\">\n" + " </form>\n" + "</body>\n" + "</html>"; byte[] landingHtmlBytes = landingHtml.getBytes(StandardCharsets.UTF_8); Map<String, TypedContent> storage = Collections.synchronizedMap(new HashMap<>()); fi.iki.elonen.NanoHTTPD nano = new fi.iki.elonen.NanoHTTPD(port) { @Override/* w w w . j a v a 2s . c om*/ public fi.iki.elonen.NanoHTTPD.Response serve(fi.iki.elonen.NanoHTTPD.IHTTPSession session) { System.out.format("%s http://localhost:%s%s%n", session.getMethod(), port, session.getUri()); URI uri = URI.create(session.getUri()); if ("/".equals(uri.getPath())) { return newFixedLengthResponse(Response.Status.OK, MediaType.HTML_UTF_8.toString(), new ByteArrayInputStream(landingHtmlBytes), landingHtmlBytes.length); } else if ("/upload".equals(uri.getPath())) { return processUpload(session, storage); } else if ("/file".equals(uri.getPath())) { return serveFileById(storage, session.getParms().get("id")); } else { return newFixedLengthResponse(NanoHTTPD.Response.Status.NOT_FOUND, "text/plain", "404 Not Found"); } } }; nano.start(); BrowserMobProxy proxy = new BrowserMobProxyServer(); proxy.newHar(); proxy.enableHarCaptureTypes(EnumSet.allOf(CaptureType.class)); proxy.start(proxyPort); try { try { String url = String.format("http://localhost:%s/%n", nano.getListeningPort()); System.out.format("visiting %s%n", url); WebDriver driver = createWebDriver(proxyPort); try { driver.get(url); // new CountDownLatch(1).await(); WebElement fileInput = driver.findElement(By.cssSelector("input[type=\"file\"]")); fileInput.sendKeys(binaryFile.getAbsolutePath()); WebElement submitButton = driver.findElement(By.cssSelector("input[type=\"submit\"]")); submitButton.click(); new WebDriverWait(driver, 10).until(ExpectedConditions.urlMatches("^.*/file\\?id=\\S+$")); System.out.format("ending on %s%n", driver.getCurrentUrl()); } finally { driver.quit(); } } finally { nano.stop(); } } finally { proxy.stop(); } net.lightbody.bmp.core.har.Har bmpHar = proxy.getHar(); removeConnectEntries(bmpHar.getLog().getEntries()); String serializer = "gson"; serialize(serializer, bmpHar, harFile, harOutputCharset); System.out.format("%s written (%d bytes)%n", harFile, harFile.length()); bmpHar.getLog().getEntries().stream().map(HarEntry::getRequest).forEach(request -> { System.out.format("%s %s%n", request.getMethod(), request.getUrl()); }); return bmpHar; }
From source file:io.github.seleniumquery.browser.driver.DriverBuilder.java
License:Apache License
protected void autoQuitDriverIfAskedFor(WebDriver driver) { if (this.autoQuitAskedFor) { Runtime.getRuntime().addShutdownHook(new Thread(() -> { synchronized (driver) { LOGGER.warn("Quitting driver automatically now: " + driver); driver.quit(); }//from w w w.ja v a 2s. c o m })); } }
From source file:io.selendroid.server.e2e.SessionCreationE2ETest.java
License:Apache License
private void testMethod(SelendroidCapabilities capa) throws Exception { WebDriver driver = new SelendroidDriver("http://localhost:5555/wd/hub", capa); String activityClass = "io.selendroid.testapp." + "HomeScreenActivity"; driver.get("and-activity://" + activityClass); driver.getCurrentUrl();/*w w w . j a v a 2 s. c om*/ try { driver.findElement(By.id("not there")); Assert.fail(); } catch (NoSuchElementException e) { // expected } WebElement inputField = driver.findElement(By.id("my_text_field")); Assert.assertEquals("true", inputField.getAttribute("enabled")); inputField.sendKeys("Selendroid"); Assert.assertEquals("Selendroid", inputField.getText()); driver.quit(); }
From source file:io.selendroid.server.e2e.SessionCreationE2ETests.java
License:Apache License
private void testMethod(SelendroidCapabilities capa) throws Exception { WebDriver driver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"), capa); String activityClass = "io.selendroid.testapp." + "HomeScreenActivity"; driver.get("and-activity://" + activityClass); driver.getCurrentUrl();/*from ww w . j ava 2 s. c om*/ try { driver.findElement(By.id("not there")); Assert.fail(); } catch (NoSuchElementException e) { // expected } WebElement inputField = driver.findElement(By.id("my_text_field")); Assert.assertEquals("true", inputField.getAttribute("enabled")); inputField.sendKeys("Selendroid"); Assert.assertEquals("Selendroid", inputField.getText()); driver.findElement(By.id("buttonStartWebview")).click(); driver.switchTo().window("WEBVIEW"); WebElement element = driver.findElement(By.id("name_input")); element.clear(); ((JavascriptExecutor) driver).executeScript("var inputs = document.getElementsByTagName('input');" + "for(var i = 0; i < inputs.length; i++) { " + " inputs[i].value = 'helloJavascript';" + "}"); Assert.assertEquals("helloJavascript", element.getAttribute("value")); driver.quit(); }
From source file:JavaClasses.DBConnectionIT.java
@Test 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. //WebDriver driver = new FirefoxDriver(); WebDriver driver = new HtmlUnitDriver(); driver.get("http://54.255.142.60:8080/PhoenixConsulting-1.0-SNAPSHOT/index.jsp"); // 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"); //}// w ww .j a va 2 s . c o m String actualTitle = driver.getTitle(); assertTrue(actualTitle.equalsIgnoreCase("Home Page - Phoenix")); WebElement element = driver.findElement(By.name("submit")); element.click(); actualTitle = driver.getTitle(); assertTrue(actualTitle.equalsIgnoreCase("Phoenix Consulting - Details")); element = driver.findElement(By.name("back")); element.click(); actualTitle = driver.getTitle(); assertTrue(actualTitle.equalsIgnoreCase("Home Page - Phoenix")); //Close the browser driver.quit(); }
From source file:jdave.webdriver.Browser.java
License:Apache License
public void close() { WebDriver webDriver = WebDriverHolder.get(); Options options = webDriver.manage(); if (options != null) { options.deleteAllCookies();//from w w w . j a va 2 s . c o m } webDriver.quit(); }
From source file:limmen.hw4.view.GoogleSearchTest.java
public static void main(String... args) { WebDriver driver = new FirefoxDriver(); driver.navigate().to("http://google.com"); String appTitle = driver.getTitle(); System.out.println("Application title is :: " + appTitle); driver.quit(); }
From source file:litecartAdmin.GeoZonesPageTest.java
@Parameters public static Collection<Object[]> getAllUrl() { WebDriver driver = getDriver(); (new AdminLoginPage(driver)).login(); driver.get("http://litecart.resscode.org.ua/admin/?app=geo_zones&doc=geo_zones"); List<WebElement> elems = driver.findElements(By.cssSelector(".row td:nth-child(3) a")); List<Object[]> hrefs = new ArrayList<Object[]>(); elems.forEach((e) -> {//w w w . ja v a2 s. com hrefs.add(new Object[] { e.getAttribute("href") }); }); driver.quit(); return hrefs; }