List of usage examples for org.openqa.selenium WebDriver get
void get(String url);
From source file:com.emc.kibana.emailer.KibanaEmailer.java
License:Open Source License
private static void generatePdfReports() { try {//from w w w. j a v a 2s . c o m System.setProperty("webdriver.chrome.driver", chromeDriverPath); Map<String, Object> chromeOptions = new HashMap<String, Object>(); // Specify alternate browser location if (chromeBrowserPath != null && !chromeBrowserPath.isEmpty()) { chromeOptions.put("binary", chromeBrowserPath); } DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); int index = 1; Date timestamp = new Date(System.currentTimeMillis()); for (Map<String, String> entry : kibanaUrls) { String dashboardName = entry.get(NAME_KEY); String dashboardUrl = entry.get(URL_KEY); if (dashboardUrl == null) { continue; } String filename; if ((dashboardName != null)) { String invalidCharRemoved = dashboardName.replaceAll("[\\/:\"*?<>|]+", "_").replaceAll(" ", "_"); filename = invalidCharRemoved + ".png"; } else { filename = "dashboard-" + index++ + ".png"; } WebDriver driver = new ChromeDriver(capabilities); driver.manage().window().maximize(); driver.get(dashboardUrl); // let kibana load for x seconds before taking the snapshot Integer delay = (screenCaptureDelay != null) ? (screenCaptureDelay * 1000) : (20000); Thread.sleep(delay); // take screenshot File scrnshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); // generate absolute path filename String absoluteFileName = destinationPath + File.separator + DATA_DATE_FORMAT.format(timestamp) + File.separator + filename; Map<String, String> fileMap = new HashMap<String, String>(); // file name portion fileMap.put(FILE_NAME_KEY, filename); fileMap.put(ABSOLUE_FILE_NAME_KEY, absoluteFileName); kibanaScreenCaptures.add(fileMap); File destFile = new File(absoluteFileName); logger.info("Copying " + scrnshot + " in " + destFile.getAbsolutePath()); FileUtils.copyFile(scrnshot, destFile); driver.close(); } } catch (InterruptedException e) { throw new RuntimeException(e); } catch (IOException e1) { throw new RuntimeException(e1); } }
From source file:com.esprit.GUI.Login.java
private void fbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fbActionPerformed // TODO add your handling code here: String accessToken = ""; System.setProperty("webdriver.chrome.driver", "D:\\security\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get( "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=182538538804902&redirect_uri=https://www.google.tn/&scope=user_about_me," + "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_activities,user_birthday,user_education_history," + "user_events,user_friends,user_games_activity,user_groups,user_hometown,user_interests,user_likes,user_location,user_photos,user_relationship_details," + "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email," + "manage_notifications,manage_pages,publish_actions,read_friendlists,read_insights,read_mailbox,read_page_mailboxes,read_stream,rsvp_event"); while (true) { if (!driver.getCurrentUrl().contains("facebook.com")) { String url = driver.getCurrentUrl(); int state = 0; for (int i = 0; i < url.length(); i++) { switch (state) { case (0): { if (url.charAt(i) == '=') { state = 1;//from ww w .j a v a 2s. c om } } break; case (1): { if (url.charAt(i) == '&') { state = 2; } else { accessToken += url.charAt(i); } } break; case (2): { } break; } } driver.quit(); System.out.println(accessToken); FacebookClient fbClient = new DefaultFacebookClient(accessToken); User me = fbClient.fetchObject("me", User.class); txt_password.setText(me.getName()); txt_mail.setText(me.getId()); } } }
From source file:com.esprit.GUI.Register1.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String accessToken = ""; System.setProperty("webdriver.chrome.driver", "D:\\security\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get( "https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=1685522955036652&redirect_uri=https://www.google.tn/&scope=user_about_me," + "user_actions.books,user_actions.fitness,user_actions.music,user_actions.news,user_actions.video,user_activities,user_birthday,user_education_history," + "user_events,user_friends,user_games_activity,user_groups,user_hometown,user_interests,user_likes,user_location,user_photos,user_relationship_details," + "user_relationships,user_religion_politics,user_status,user_tagged_places,user_videos,user_website,user_work_history,ads_management,ads_read,email," + "manage_notifications,manage_pages,publish_actions,read_friendlists,read_insights,read_mailbox,read_page_mailboxes,read_stream,rsvp_event"); while (true) { if (!driver.getCurrentUrl().contains("facebook.com")) { String url = driver.getCurrentUrl(); int state = 0; for (int i = 0; i < url.length(); i++) { switch (state) { case (0): { if (url.charAt(i) == '=') { state = 1;// w ww . j a v a 2 s .c om } } break; case (1): { if (url.charAt(i) == '&') { state = 2; } else { accessToken += url.charAt(i); } } break; case (2): { } break; } } driver.quit(); System.out.println(accessToken); FacebookClient fbClient = new DefaultFacebookClient(accessToken); User me = fbClient.fetchObject("me", User.class); txtno.setText(me.getFirstName()); txtpr.setText(me.getLastName()); txtma.setText(me.getEmail()); pwd.setText(me.getName()); txtid.setText(me.getId()); } } }
From source file:com.evidon.areweprivateyet.Crawler.java
License:Open Source License
public Crawler(String namedProfile) throws Exception { loadSiteList();/*from ww w . j a v a 2 s . com*/ int sleepTime = (namedProfile.equals("baseline") ? 10 : 5); boolean started = false; String baseWindow = ""; FirefoxProfile profile = new ProfilesIni().getProfile(namedProfile); //profile.setPreference("webdriver.load.strategy", "fast"); WebDriver driver = new FirefoxDriver(profile); driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(40, TimeUnit.SECONDS); // figure out where the fucking profile is. wow! String profileDir = getDriverProfile(); log("Crawling started for " + namedProfile); int count = 0; for (String url : urls) { if (!started) { // Original window handle to be used as base. Used so we can close all other popups. baseWindow = driver.getWindowHandle(); started = true; } count++; log("\t" + count + ". navigating to: " + url); CrawlusInterruptus ci = new CrawlusInterruptus(60); try { ci.start(); try { // Confirm handling for one of those super fucking annoying "Are you sure you wonna go anywhere else?" driver.switchTo().alert().accept(); log("\tAccepted a navigate away modal"); } catch (Exception e) { } driver.get("http://" + url); // WTF, why would their own fucking wait not work?!? // new WebDriverWait(driver, 5 * 1000); } catch (TimeoutException te) { handleTimeout(baseWindow, url, driver); } catch (org.openqa.selenium.UnhandledAlertException me) { log("\tModal exception caused by previous site?"); // Retry current site. try { driver.get("http://" + url); } catch (TimeoutException te) { handleTimeout(baseWindow, url, driver); } } finally { ci.interrupt(); } try { Thread.sleep(sleepTime * 1000); } catch (InterruptedException e) { } killPopups(baseWindow, driver); } // 4th party does not know when the crawl is over, so we send a trip signal by navigating to the "last" domain try { driver.get("http://www.josesignanini.com"); } catch (TimeoutException te) { } try { Thread.sleep(60 * 1000); } catch (InterruptedException e) { } // copy the fourthparty database out. FileUtils.copyFile(new File(profileDir + "/fourthparty.sqlite"), new File(path + "/fourthparty-" + namedProfile + ".sqlite")); driver.quit(); log("Crawling completed for " + namedProfile); recordLog(namedProfile); }
From source file:com.evolveum.midpoint.selenium.BaseTest.java
License:Apache License
protected void performLogin(WebDriver driver, String username, String password) { driver.get(siteUrl + "/login"); driver.findElement(By.id("userName")).sendKeys(username); driver.findElement(By.id("userPass")).sendKeys(password); driver.findElement(By.cssSelector("input.button")).click(); }
From source file:com.firewallid.crawling.FacebookApp.java
private WebDriver createWebDriver() { WebDriver webdriver = new HtmlUnitDriver(BrowserVersion.BEST_SUPPORTED, true); webdriver.get(FACEBOOK_URL); webdriver.findElement(By.id(conf.get(EMAIL_FIELD_ID))).sendKeys(conf.get(EMAIL)); webdriver.findElement(By.id(conf.get(PASSWORD_FIELD_ID))).sendKeys(conf.get(PASSWORD)); webdriver.findElement(By.id(conf.get(LOGIN_BUTTON_ID))).click(); return webdriver; }
From source file:com.firewallid.crawling.FacebookApp.java
public List<String> getUserFeeds(String id) { WebDriver webDriver1 = createWebDriver(); webDriver1.get(FACEBOOK_URL + id); List<String> feeds = Jsoup /* Get page source code */ .parse(webDriver1.getPageSource()) /* User's posts html tag */ .getElementsByClass(conf.get(POST_CLASS)).parallelStream().map(postHtmlTag -> postHtmlTag.text()) .filter(post -> !post.isEmpty()).collect(Collectors.toList()); LOG.debug(String.format("User: %s. Total feed: %s", id, feeds.size())); return feeds; }
From source file:com.galenframework.ide.tests.integration.ui.GalenTestBase.java
License:Apache License
@Override public WebDriver createDriver(Object[] args) { WebDriver driver = WebDriverSingleInstance.getDriver(); driver.get(getTestUrl()); driver.manage().window().setSize(desktopDevice.getSize()); driver.manage().deleteAllCookies();/*from ww w. j a v a2 s . c o m*/ driver.manage().addCookie(new Cookie(MockedWebApp.MOCK_KEY_COOKIE_NAME, mockUniqueKey, "/", new Date(new Date().getTime() + ONE_YEAR))); return driver; }
From source file:com.galenframework.tests.action.GalenPageActionDumpPageTest.java
License:Apache License
@Test public void shouldCreate_pageDump() throws Exception { String pageDumpPath = Files.createTempDir().getAbsolutePath() + "/pagedump"; WebDriver driver = new MockedDriver(); driver.get("/mocks/pages/galen4j-pagedump.json"); GalenPageAction pageAction = new GalenPageActionDumpPage("Test page", "/specs/galen4j/pagedump.spec", pageDumpPath);/*w w w. j a v a2s . co m*/ pageAction.execute(null, new SeleniumBrowser(driver), null, null); assertFileExists(pageDumpPath + "/page.json"); assertFileExists(pageDumpPath + "/page.html"); }
From source file:com.galenframework.tests.api.GalenTest.java
License:Apache License
@Test public void checkLayout_shouldTestLayout_andReturnLayoutReport() throws IOException { WebDriver driver = new MockedDriver(); driver.get("/mocks/pages/galen4j-sample-page.json"); LayoutReport layoutReport = Galen.checkLayout(driver, "/specs/galen4j/sample-spec-with-error.spec", asList("mobile"), null, new Properties(), null, null); assertThat(layoutReport.getValidationErrorResults(), contains(/* w w w . ja va 2s . com*/ new ValidationResult( asList(new ValidationObject(new Rect(10, 10, 100, 50), "save-button"), new ValidationObject(new Rect(120, 10, 200, 50), "name-textfield")), new ValidationError().withMessage("\"save-button\" is 10px left instead of 50px")), new ValidationResult(asList(new ValidationObject(new Rect(10, 10, 100, 50), "save-button")), new ValidationError() .withMessage("\"save-button\" text is \"Save\" but should be \"Store\"")))); }