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

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

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

WebDriver.getTitle介绍

[英]The title of the current page.
[中]当前页面的标题。

代码示例

代码示例来源:origin: galenframework/galen

@Override
public String getTitle() {
  return driver.getTitle();
}

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

public boolean isBrowserStillOpen(WebDriver webDriver) {
  try {
   webDriver.getTitle();
   return true;
  }
  catch (UnreachableBrowserException e) {
   log.log(FINE, "Browser is unreachable", e);
   return false;
  }
  catch (NoSuchWindowException e) {
   log.log(FINE, "Browser window is not found", e);
   return false;
  }
  catch (NoSuchSessionException e) {
   log.log(FINE, "Browser session is not found", e);
   return false;
  }
 }
}

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

public String title() {
 return getWebDriver().getTitle();
}

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

public DefaultLogoutPage assertAt() {
  assertThat(this.driver.getTitle()).isEqualTo("Confirm Log Out?");
  return this;
}

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

public CustomLoginPage assertAt() {
  assertThat(this.driver.getTitle()).isEqualTo("Custom Log In Page");
  return this;
}

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

public DefaultLoginPage assertAt() {
  assertThat(this.driver.getTitle()).isEqualTo("Please sign in");
  return this;
}

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

public void assertAt() {
  assertThat(this.driver.getTitle()).isEqualTo("Secured");
}

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

/**
 * Switch to window/tab by name/handle/title except some windows handles
 * @param title title of window/tab
 */
protected static WebDriver windowByTitle(WebDriver driver, String title) {
 Set<String> windowHandles = driver.getWindowHandles();
 for (String windowHandle : windowHandles) {
  driver.switchTo().window(windowHandle);
  if (title.equals(driver.getTitle())) {
   return driver;
  }
 }
 throw new NoSuchWindowException("Window with title not found: " + title);
}

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

private void beginPasswordReset(String username) {
  webDriver.get(baseUrl + "/login");
  Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
  webDriver.findElement(By.linkText("Reset password")).click();
  Assert.assertEquals("Reset Password", webDriver.findElement(By.tagName("h1")).getText());
  // Enter email address
  webDriver.findElement(By.name("username")).sendKeys(username);
  webDriver.findElement(By.xpath("//input[@value='Send reset password link']")).click();
  Assert.assertEquals("Instructions Sent", webDriver.findElement(By.tagName("h1")).getText());
}

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

@Test
public void testLoginHint() throws Exception {
  String newUserEmail = createAnotherUser();
  webDriver.get(baseUrl + "/logout.do");
  String ldapLoginHint = URLEncoder.encode("{\"origin\":\"ldap\"}", "UTF-8");
  webDriver.get(baseUrl + "/login?login_hint=" + ldapLoginHint);
  assertEquals("Cloud Foundry", webDriver.getTitle());
  attemptLogin(newUserEmail, USER_PASSWORD);
  assertThat(webDriver.findElement(By.className("alert-error")).getText(), containsString("Unable to verify email or password. Please try again."));
  String uaaLoginHint = URLEncoder.encode("{\"origin\":\"uaa\"}", "UTF-8");
  webDriver.get(baseUrl + "/login?login_hint=" + uaaLoginHint);
  assertEquals("Cloud Foundry", webDriver.getTitle());
  attemptLogin(newUserEmail, USER_PASSWORD);
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
  webDriver.get(baseUrl + "/logout.do");
}

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

private void login(IdentityProvider<SamlIdentityProviderDefinition> provider) {
    webDriver.get(baseUrl + "/login");
    Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
    webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
    webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
    webDriver.findElement(By.name("username")).clear();
    webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
    webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
    webDriver.findElement(By.xpath("//input[@value='Login']")).click();
  }
}

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

@Test
public void testUnsuccessfulLogin() throws Exception {
  webDriver.get(baseUrl + "/login");
  assertEquals("Cloud Foundry", webDriver.getTitle());
  attemptLogin(testAccounts.getUserName(), "invalidpassword");
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Welcome!"));
}

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

private void testSimpleSamlLogin(String firstUrl, String lookfor, String username, String password) throws Exception {
  IdentityProvider<SamlIdentityProviderDefinition> provider = createIdentityProvider(SAML_ORIGIN);
  webDriver.get(baseUrl + firstUrl);
  Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
  webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
  //takeScreenShot();
  webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
  webDriver.findElement(By.name("username")).clear();
  webDriver.findElement(By.name("username")).sendKeys(username);
  webDriver.findElement(By.name("password")).sendKeys(password);
  webDriver.findElement(By.xpath("//input[@value='Login']")).click();
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString(lookfor));
  IntegrationTestUtils.validateAccountChooserCookie(baseUrl, webDriver);
}

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

@Test
public void testPasscodeRedirect() throws Exception {
  webDriver.get(baseUrl + "/passcode");
  assertEquals("Cloud Foundry", webDriver.getTitle());
  attemptLogin(testAccounts.getUserName(), testAccounts.getPassword());
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Temporary Authentication Code"));
}

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

@Test
public void testSuccessfulLoginNewUser() throws Exception {
  String newUserEmail = createAnotherUser();
  webDriver.get(baseUrl + "/logout.do");
  webDriver.get(baseUrl + "/login");
  assertEquals("Cloud Foundry", webDriver.getTitle());
  attemptLogin(newUserEmail, USER_PASSWORD);
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
  webDriver.get(baseUrl + "/logout.do");
  attemptLogin(newUserEmail, USER_PASSWORD);
  assertNotNull(webDriver.findElement(By.cssSelector("#last_login_time")));
  IntegrationTestUtils.validateAccountChooserCookie(baseUrl, webDriver);
}

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

@Test
public void testSingleLogout() throws Exception {
  IdentityProvider<SamlIdentityProviderDefinition> provider = createIdentityProvider(SAML_ORIGIN);
  webDriver.get(baseUrl + "/login");
  Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
  webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
  webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
  webDriver.findElement(By.name("username")).clear();
  webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
  webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
  webDriver.findElement(By.xpath("//input[@value='Login']")).click();
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to"));
  logout();
  IntegrationTestUtils.validateAccountChooserCookie(baseUrl, webDriver);
  webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
  webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
}

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

private void testLocalSamlIdpLogin(String firstUrl, String lookfor, String username, String password)
 throws Exception {
  SamlIdentityProviderDefinition idpDef = createLocalSamlIdpDefinition(IDP_ENTITY_ID, "uaa");
  @SuppressWarnings("unchecked")
  IdentityProvider<SamlIdentityProviderDefinition> provider = IntegrationTestUtils.createIdentityProvider(
   "Local SAML IdP", true, this.baseUrl, this.serverRunning, idpDef);
  SamlServiceProviderDefinition spDef = createLocalSamlSpDefinition("cloudfoundry-saml-login", "uaa");
  createSamlServiceProvider("Local SAML SP", "cloudfoundry-saml-login", baseUrl, serverRunning, spDef);
  webDriver.get(baseUrl + firstUrl);
  IntegrationTestUtils.takeScreenShot(webDriver);
  assertEquals("Cloud Foundry", webDriver.getTitle());
  webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
  webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome!')]"));
  webDriver.findElement(By.name("username")).clear();
  webDriver.findElement(By.name("username")).sendKeys(username);
  webDriver.findElement(By.name("password")).sendKeys(password);
  webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString(lookfor));
  provider.setActive(false);
  IntegrationTestUtils.updateIdentityProvider(this.baseUrl, this.serverRunning, provider);
}

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

@Test
public void testSingleLogoutWithNoLogoutUrlOnIDP() throws Exception {
  SamlIdentityProviderDefinition providerDefinition = createIDPWithNoSLOSConfigured(SAML_ORIGIN);
  IdentityProvider<SamlIdentityProviderDefinition> provider = new IdentityProvider();
  provider.setIdentityZoneId(OriginKeys.UAA);
  provider.setType(OriginKeys.SAML);
  provider.setActive(true);
  provider.setConfig(providerDefinition);
  provider.setOriginKey(providerDefinition.getIdpEntityAlias());
  provider.setName("simplesamlphp for uaa");
  String zoneAdminToken = getZoneAdminToken(baseUrl, serverRunning);
  provider = IntegrationTestUtils.createOrUpdateProvider(zoneAdminToken, baseUrl, provider);
  webDriver.get(baseUrl + "/login");
  Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
  webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
  webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
  webDriver.findElement(By.name("username")).clear();
  webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName());
  webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword());
  webDriver.findElement(By.xpath("//input[@value='Login']")).click();
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to"));
  webDriver.findElement(By.cssSelector(".dropdown-trigger")).click();
  webDriver.findElement(By.linkText("Sign Out")).click();
  webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
  assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to"));
}

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

webDriver.get(idpZoneUrl+ "/logout.do");
webDriver.get(spZoneUrl + "/");
assertEquals(spZone.getName(), webDriver.getTitle());
Cookie beforeLogin = webDriver.manage().getCookieNamed("JSESSIONID");
assertNotNull(beforeLogin);

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

Assert.assertTrue(webDriver.getTitle().contains("testzone2"));
webDriver.findElement(By.xpath("//a[text()='" + provider.getConfig().getLinkText() + "']")).click();
webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));

相关文章