List of usage examples for org.openqa.selenium WebDriver get
void get(String url);
From source file:org.rivalry.example.runescape.RuneScapeDataCollector.java
License:Open Source License
/** * @param rivalryData Rivalry data./*from w w w.j av a 2 s.c om*/ */ private void fetchDataTipIt(final RivalryData rivalryData) { final boolean isJavascriptEnabled = false; final WebDriver webDriver = createWebDriver(isJavascriptEnabled); final String url = "http://www.tip.it/runescape/?rs2item"; System.out.println("accessing URL " + url); webDriver.get(url); System.out.println("findElement query"); final WebElement queryInput = webDriver.findElement(By.name("query")); if (queryInput != null) { System.out.println("queryInput = " + queryInput.getClass().getName()); } }
From source file:org.seasar.robot.client.http.WebDriverClient.java
License:Apache License
@Override public ResponseData execute(final RequestData request) { WebDriver webDriver = null; try {/*from ww w .jav a2s.c o m*/ webDriver = webDriverPool.borrowObject(); Map<String, String> paramMap = null; String url = request.getUrl(); String metaData = request.getMetaData(); if (StringUtil.isNotBlank(metaData)) { paramMap = parseParamMap(metaData); } if (!url.equals(webDriver.getCurrentUrl())) { webDriver.get(url); } if (logger.isDebugEnabled()) { logger.debug("Base URL: " + url + "\nContent: " + webDriver.getPageSource()); } if (paramMap != null) { final String processorName = paramMap.get(UrlAction.URL_ACTION); final UrlAction urlAction = urlActionMap.get(processorName); if (urlAction == null) { throw new RobotSystemException("Unknown processor: " + processorName); } urlAction.navigate(webDriver, paramMap); } final String source = webDriver.getPageSource(); final ResponseData responseData = new ResponseData(); responseData.setUrl(webDriver.getCurrentUrl()); responseData.setMethod(request.getMethod().name()); responseData.setContentLength(source.length()); final String charSet = getCharSet(webDriver); responseData.setCharSet(charSet); responseData.setHttpStatusCode(getStatusCode(webDriver)); responseData.setLastModified(getLastModified(webDriver)); responseData.setMimeType(getContentType(webDriver)); responseData.setResponseBody(new ByteArrayInputStream(source.getBytes(charSet))); for (final UrlAction urlAction : urlActionMap.values()) { urlAction.collect(url, webDriver, responseData); } return responseData; } catch (final Exception e) { throw new RobotSystemException("Failed to access " + request.getUrl(), e); } finally { if (webDriver != null) { try { webDriverPool.returnObject(webDriver); } catch (final Exception e) { logger.warn("Failed to return a returned object.", e); } } } }
From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java
License:Open Source License
public void captureScreenshots() { Base64Encoder encoder = new Base64Encoder(); String encodedCredentials = encoder .encode((Credentials.getUsername() + ":" + Credentials.getPassword()).getBytes()); DesiredCapabilities caps = new DesiredCapabilities(); if (phantomjsPath != null) { caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjsPath); }/*from ww w . j a v a2 s .c o m*/ caps.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Authorization", "Basic " + encodedCredentials); WebDriver driver = new PhantomJSDriver(caps); String[] chapters = StringUtils.split(configProperties.getProperty("chapters"), ","); List<String> cssSelectors = new ArrayList<String>(); for (String chapter : chapters) { String[] sections = StringUtils.split(configProperties.getProperty(chapter + ".sections"), ","); for (String section : sections) { cssSelectors.add("." + section); } } try { driver.get(dashboardUrl); for (String selector : cssSelectors) { captureScreenshot(driver, selector); } } catch (IOException e) { e.printStackTrace(); } finally { driver.quit(); } }
From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java
License:Open Source License
private void captureScreenshot(WebDriver driver, String selector) throws IOException { File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); driver.get(dashboardUrl); System.out.println("Screenshot captured..."); List<WebElement> elements = driver.findElements(By.cssSelector(selector)); if (!elements.isEmpty()) { WebElement element = elements.get(0); BufferedImage fullImg = ImageIO.read(screenshot); Point point = element.getLocation(); int eleWidth = element.getSize().getWidth(); int eleHeight = element.getSize().getHeight(); BufferedImage eleScreenshot = fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight); ImageIO.write(eleScreenshot, "png", screenshot); System.out.println("Cropping to get widget: " + selector.substring(1)); FileUtils.copyFile(screenshot,/*w ww . j a va2 s . c om*/ new File(screenshotsDir + File.separator + selector.substring(1) + ".png")); } }
From source file:org.specrunner.webdriver.actions.PluginOpen.java
License:Open Source License
@Override protected void doEnd(IContext context, IResultSet result, WebDriver client) throws PluginException { Node node = context.getNode(); String u = getUrl() != null ? getUrl() : node.getValue(); String tmp = getBrowserName(); if (!u.startsWith("http") && !u.startsWith("file")) { String baseUrl = (String) context.getByName(PluginStartIn.getBaseForBrowser(tmp)); if (baseUrl == null) { throw new PluginException("Could not find base url for browser '" + tmp + "'."); }//from w w w . j a v a2s .c om String target; try { URL base = new URL(baseUrl); target = new URL(base, u).toString(); if (UtilLog.LOG.isInfoEnabled()) { UtilLog.LOG.info("Relative url resolved from '" + u + "' to '" + target + "'."); } } catch (MalformedURLException e) { throw new PluginException("Could not resolve '" + baseUrl + "' with " + u + ".", e); } u = target; } PluginException error = null; try { if (UtilLog.LOG.isInfoEnabled()) { UtilLog.LOG.info("Openning '" + u + "' on browser named '" + tmp + "'."); } client.get(u); } catch (Exception e) { error = new PluginException(e); } if (error != null && !isIgnorable(error)) { throw error; } else { result.addResult(Success.INSTANCE, context.newBlock(node, this)); } }
From source file:org.springframework.security.config.web.server.LogoutBuilderTests.java
License:Apache License
@Test public void customLogout() { SecurityWebFilterChain securityWebFilter = this.http.authorizeExchange().anyExchange().authenticated().and() .formLogin().and().logout().requiresLogout(ServerWebExchangeMatchers.pathMatchers("/custom-logout")) .and().build();//from w ww. ja va 2s .co m WebTestClient webTestClient = WebTestClientBuilder.bindToWebFilters(securityWebFilter).build(); WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build(); FormLoginTests.DefaultLoginPage loginPage = FormLoginTests.HomePage .to(driver, FormLoginTests.DefaultLoginPage.class).assertAt(); loginPage = loginPage.loginForm().username("user").password("invalid") .submit(FormLoginTests.DefaultLoginPage.class).assertError(); FormLoginTests.HomePage homePage = loginPage.loginForm().username("user").password("password") .submit(FormLoginTests.HomePage.class); homePage.assertAt(); driver.get("http://localhost/custom-logout"); FormLoginTests.DefaultLoginPage.create(driver).assertAt().assertLogout(); }
From source file:org.springframework.security.config.web.server.OAuth2LoginTests.java
License:Apache License
@Test public void defaultLoginPageWithSingleClientRegistrationThenRedirect() { this.spring.register(OAuth2LoginWithSingleClientRegistrations.class).autowire(); WebTestClient webTestClient = WebTestClientBuilder .bindToWebFilters(new GitHubWebFilter(), this.springSecurity).build(); WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build(); driver.get("http://localhost/"); assertThat(driver.getCurrentUrl()).startsWith("https://github.com/login/oauth/authorize"); }
From source file:org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilderTests.java
License:Apache License
@Test public void helloWorld() { WebTestClient webTestClient = WebTestClient.bindToController(new HelloWorldController()).build(); WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build(); driver.get("http://localhost/"); assertThat(driver.getPageSource()).contains("Hello World"); }
From source file:org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilderTests.java
License:Apache License
@Test public void cookies() { WebTestClient webTestClient = WebTestClient.bindToController(new CookieController()).build(); WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build(); driver.get("http://localhost/cookie"); assertThat(driver.getPageSource()).contains("theCookie"); driver.get("http://localhost/cookie/delete"); assertThat(driver.getPageSource()).contains("null"); }
From source file:org.springframework.security.samples.pages.ContactsPage.java
License:Apache License
public static LoginPage accessManagePageWithUnauthenticatedUser(WebDriver driver, int port) { driver.get("http://localhost:" + port + "/secure/"); return PageFactory.initElements(driver, LoginPage.class); }