org.openqa.selenium.WebDriver.getPageSource()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(172)

本文整理了Java中org.openqa.selenium.WebDriver.getPageSource()方法的一些代码示例,展示了WebDriver.getPageSource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebDriver.getPageSource()方法的具体详情如下:
包路径:org.openqa.selenium.WebDriver
类名称:WebDriver
方法名:getPageSource

WebDriver.getPageSource介绍

[英]Get the source of the last loaded page. If the page has been modified after loading (for example, by Javascript) there is no guarantee that the returned text is that of the modified page. Please consult the documentation of the particular driver being used to determine whether the returned text reflects the current state of the page or the text last sent by the web server. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server. Think of it as an artist's impression.
[中]

代码示例

代码示例来源:origin: selenide/selenide

public String source() {
 return getWebDriver().getPageSource();
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testLoginPageReloadBasedOnCsrf() {
  webDriver.get(baseUrl + "/login");
  assertTrue(webDriver.getPageSource().contains("http-equiv=\"refresh\""));
}

代码示例来源:origin: spring-projects/spring-security

@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");
}

代码示例来源:origin: cloudfoundry/uaa

public void debugPage(String className, String description) {
  TakesScreenshot takesScreenshot = (TakesScreenshot) browser;
  File scrFile = takesScreenshot.getScreenshotAs(OutputType.FILE);
  File destFile = getDestinationFile(className, description);
  try {
    FileUtils.copyFile(scrFile, destFile);
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  }
  File pageSourceFile = getDestinationFile(className, description + ".html");
  String pageSource = browser.getPageSource();
  try {
    FileUtils.write(pageSourceFile, pageSource);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: selenide/selenide

writeToFile(webdriver.getPageSource(), pageSource);

代码示例来源:origin: spring-projects/spring-security

@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");
}

代码示例来源:origin: TEAMMATES/teammates

/**
 * Returns the HTML source of the currently loaded page.
 */
public String getPageSource() {
  return browser.driver.getPageSource();
}

代码示例来源:origin: TEAMMATES/teammates

private void waitForRedirectIfAny() {
  String loginRedirectUrl = TestProperties.TEAMMATES_URL + "/_ah/conflogin";
  waitFor(d -> {
    String url = Preconditions.checkNotNull(d).getCurrentUrl();
    boolean isTeammatesPage = url.startsWith(TestProperties.TEAMMATES_URL) && !url.startsWith(loginRedirectUrl);
    boolean isApprovalPage = d.getPageSource().contains(EXPECTED_SNIPPET_APPROVAL);
    return isTeammatesPage || isApprovalPage;
  });
}

代码示例来源:origin: TEAMMATES/teammates

@Test
public void testTimezoneDatabasesAreUpToDate() {
  // ensure the timezone databases are up-to-date
  String currentTzVersion = Jsoup.parse(browser.driver.getPageSource()).getElementById("tzversion-moment").text();
  browser.driver.get(IANA_TIMEZONE_DATABASE_URL);
  Document tzReleasePage = Jsoup.parse(browser.driver.getPageSource());
  String latestTzVersion = tzReleasePage.getElementById("version").text();
  if (!currentTzVersion.equals(latestTzVersion)) {
    // find the release day
    String releaseDateString = tzReleasePage.getElementById("date").text();
    Pattern datePattern = Pattern.compile("\\(Released (.+)\\)");
    Matcher matcher = datePattern.matcher(releaseDateString);
    assertTrue(matcher.find());
    LocalDate releaseDate = LocalDate.parse(matcher.group(1), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    LocalDate nowDate = Instant.now().atZone(Const.DEFAULT_TIME_ZONE).toLocalDate();
    assertTrue(
        "The timezone database version is not up-to-date for more than " + DAYS_TO_UPDATE_TZ + " days,"
            + " please update them according to the maintenance guide.",
        releaseDate.plusDays(DAYS_TO_UPDATE_TZ).isAfter(nowDate));
  }
}

代码示例来源:origin: TEAMMATES/teammates

@Test
public void testFrontendBackendTimezoneDatabasesAreConsistent() {
  // ensure the front-end and the back-end have the same timezone database version
  Document pageSource = Jsoup.parse(browser.driver.getPageSource());
  String javaOffsets = processOffsets(pageSource.getElementById("tz-java").text());
  String momentOffsets = processOffsets(pageSource.getElementById("tz-moment").text());
  assertEquals(pageSource.getElementById("tzversion-java").text(),
      pageSource.getElementById("tzversion-moment").text());
  if (!javaOffsets.equals(momentOffsets)) {
    // Show diff when running test in Gradle
    assertEquals("<expected>" + System.lineSeparator() + javaOffsets + "</expected>",
        "<actual>" + System.lineSeparator() + momentOffsets + "</actual>");
  }
}

代码示例来源:origin: TEAMMATES/teammates

String pageSource = browser.driver.getPageSource();
assertTrue(pageSource.contains("Feedback Results"));
assertTrue(pageSource.contains("SHomeUiT.CS2104"));
pageSource = browser.driver.getPageSource();
assertTrue(pageSource.contains("Submit Feedback"));
assertTrue(pageSource.contains("SHomeUiT.CS2104"));
pageSource = browser.driver.getPageSource();
assertTrue(pageSource.contains("Submit Feedback"));
assertTrue(pageSource.contains("SHomeUiT.CS2104"));
pageSource = browser.driver.getPageSource();
assertTrue(pageSource.contains("Submit Feedback"));
assertTrue(pageSource.contains("SHomeUiT.CS2104"));

代码示例来源:origin: com.googlecode.fighting-layout-bugs/fighting-layout-bugs

/**
 * Returns the source HTML of this web page.
 */
@Nonnull
public String getHtml() {
  String html = (_html == null ? null : _html.get());
  if (html == null) {
    html = _driver.getPageSource();
    _html = new SoftReference<String>(html);
  }
  return html;
}

代码示例来源:origin: org.seleniumhq.webdriver/webdriver-support

/**
 * Returns the current page source
 */
public String getPageSource() {
 return getWebDriver().getPageSource();
}

代码示例来源:origin: io.github.aktoluna/slnarch-core

@Override
public String apply(WebDriver driver) {
 currentPageSource = driver.getPageSource();
 if (currentPageSource != null) {
  return currentPageSource;
 } else {
  throw new WebDriverException(); //TODO change exception
 }
}

代码示例来源:origin: com.atlassian.selenium/atlassian-webdriver-core

@Override
public void failed(final Throwable e, final Description description)
{
  if (!logPageSourceEnabled())
  {
    return;
  }
  logger.info("----- Test '{}' Failed. ", description.getMethodName());
  logger.info("----- START PAGE SOURCE DUMP\n\n\n{}\n\n\n", webDriver.get().getPageSource());
  logger.info("----- END PAGE SOURCE DUMP");
}

代码示例来源:origin: de.codecentric.zucchini/zucchini-web

/**
 * Expects that the specified text is present.
 */
@Override
public void expect() {
  assertTrue(String.format("Page should contain \"%s\" but it does not.", text), getWebDriver().getPageSource().contains(text));
}

代码示例来源:origin: com.github.dandelion/datatables-testing

public void goToPage(String page, Boolean display){
  goToPage(page);
  if(display){
    System.out.println(driver.getPageSource());
    System.out.println(getConfigurationFromPage(page).getContent());
  }
}

代码示例来源:origin: net.serenity-bdd/core

public String getPageSource() {
  if (!isEnabled()) {
    return StringUtils.EMPTY;
  }
  return getProxiedDriver().getPageSource();
}

代码示例来源:origin: org.juzu/juzu-core

@Test
 public void testFoo() {
  driver.get(applicationURL().toString());
  String page = driver.getPageSource();
  assertTrue("Was expecting to find 'pass' in " + page, page.contains("pass"));
 }
}

代码示例来源:origin: org.juzu/juzu-core

@Test
 public void testPathParam() throws Exception {
  driver.get(applicationURL().toString());
  assertTrue(driver.getPageSource().contains("pass"));
  assertNotSame(requestURL, runnableURL);
  assertEquals("null", runnableURL);
  assertSame(requestObject, runnableObject);
  assertTrue(runnableActive);
 }
}

相关文章