/** * @see By#xpath(java.lang.String) * @since 3.1 */ public static By byXpath(String xpath) { return By.xpath(xpath); }
@Override public SelenideElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { String tagOrClass = (String) args[0]; String xpath = tagOrClass.startsWith(".") ? format("ancestor::*[contains(concat(' ', normalize-space(@class), ' '), ' %s ')][1]", tagOrClass.substring(1)) : format("ancestor::%s[1]", tagOrClass); return locator.find(proxy, By.xpath(xpath), 0); } }
private void loginThroughDiscovery(String userEmail, String password) { webDriver.findElement(By.id("email")).sendKeys(userEmail); webDriver.findElement(By.cssSelector(".form-group input[value='Next']")).click(); webDriver.findElement(By.id("password")).sendKeys(password); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); } }
private static By convertToBy(Locator locator) { if ("xpath".equals(locator.getLocatorType())) { return By.xpath(locator.getLocatorValue()); } else if ("id".equals(locator.getLocatorType())) { return By.id(locator.getLocatorValue()); } else if ("css".equals(locator.getLocatorType())) { return By.cssSelector(locator.getLocatorValue()); } else return null; } }
private void signIn(String userName, String password) { webDriver.findElement(By.name("username")).sendKeys(userName); webDriver.findElement(By.name("password")).sendKeys(password); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); } }
public void attemptLogin(String username, String password) { webDriver.findElement(By.name("username")).sendKeys(username); webDriver.findElement(By.name("password")).sendKeys(password); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); }
private String startCreateUserFlow(String secret) { String userEmail = "user" + new SecureRandom().nextInt() + "@example.com"; webDriver.get(baseUrl + "/"); webDriver.findElement(By.xpath("//*[text()='Create account']")).click(); assertEquals("Create your account", webDriver.findElement(By.tagName("h1")).getText()); webDriver.findElement(By.name("email")).sendKeys(userEmail); webDriver.findElement(By.name("password")).sendKeys(secret); webDriver.findElement(By.name("password_confirmation")).sendKeys(secret); webDriver.findElement(By.xpath("//input[@value='Send activation link']")).click(); return userEmail; }
private void signIn(String userName, String password) { webDriver.get(baseUrl + "/logout.do"); webDriver.get(baseUrl + "/login"); 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("Where to?")); } }
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(); } }
private void navigateToForcePasswordChange() { updateUserToForcePasswordChange(restTemplate, baseUrl, adminAccessToken, userId); webDriver.get(baseUrl+"/login"); webDriver.findElement(By.name("username")).sendKeys(userEmail); webDriver.findElement(By.name("password")).sendKeys("secr3T"); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Force Change Password")); assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl()); }
@Test public void resettingAPasswordWithInvalidPassword() throws Exception { // Go to Forgot Password page beginPasswordReset(username); String link = getPasswordResetLink(email); webDriver.get(link); // Enter invalid password information webDriver.findElement(By.name("password")).sendKeys("newsecret"); webDriver.findElement(By.name("password_confirmation")).sendKeys(""); webDriver.findElement(By.xpath("//input[@value='Create new password']")).click(); assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Passwords must match and not be empty.")); }
@Test public void resetPassword_displaysErrorMessage_NewPasswordSameAsOld() throws Exception { beginPasswordReset(username); String link = getPasswordResetLink(email); webDriver.get(link); webDriver.findElement(By.name("password")).sendKeys("secr3T"); webDriver.findElement(By.name("password_confirmation")).sendKeys("secr3T"); webDriver.findElement(By.xpath("//input[@value='Create new password']")).click(); assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Your new password cannot be the same as the old password.")); }
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()); }
@Test public void testHandleForceChangingPassword() throws Exception { navigateToForcePasswordChange(); webDriver.findElement(By.name("password")).sendKeys("newsecr3T"); webDriver.findElement(By.name("password_confirmation")).sendKeys("newsecr3T"); webDriver.findElement(By.xpath("//input[@value='Create new password']")).click(); assertEquals(baseUrl+"/", webDriver.getCurrentUrl()); }
@Test public void testHandleForcePasswordChangeEmptyConfirmation() throws Exception { navigateToForcePasswordChange(); webDriver.findElement(By.name("password")).sendKeys("newsecr3T"); webDriver.findElement(By.xpath("//input[@value='Create new password']")).click(); assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl()); assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Passwords must match and not be empty.")); }
@Test public void resetPassword_displaysErrorMessage_WhenPasswordIsInvalid() throws Exception { String newPassword = new RandomValueStringGenerator(260).generate(); beginPasswordReset(username); String link = getPasswordResetLink(email); webDriver.get(link); webDriver.findElement(By.name("password")).sendKeys(newPassword); webDriver.findElement(By.name("password_confirmation")).sendKeys(newPassword); webDriver.findElement(By.xpath("//input[@value='Create new password']")).click(); assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Password must be no more than 255 characters in length.")); }
@Test public void testHandleForcePasswordChangeInvalidConfirmation() throws Exception { navigateToForcePasswordChange(); webDriver.findElement(By.name("password")).sendKeys("newsecr3T"); webDriver.findElement(By.name("password_confirmation")).sendKeys("invalid"); webDriver.findElement(By.xpath("//input[@value='Create new password']")).click(); assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl()); assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Passwords must match and not be empty.")); }
@Test public void testHandleForceChangingPasswordWithNewPasswordSameAsOld() throws Exception { navigateToForcePasswordChange(); webDriver.findElement(By.name("password")).sendKeys("secr3T"); webDriver.findElement(By.name("password_confirmation")).sendKeys("secr3T"); webDriver.findElement(By.xpath("//input[@value='Create new password']")).click(); assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl()); assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Your new password cannot be the same as the old password.")); }
@Before public void setUp() { logout_and_clear_cookies(); webDriver.get(baseUrl + "/login"); webDriver.findElement(By.name("username")).sendKeys(testAccounts.getUserName()); webDriver.findElement(By.name("password")).sendKeys(testAccounts.getPassword()); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); asOnHomePage = new HomePagePerspective(webDriver, testAccounts.getUserName()); }
@Test public void testForcePasswordChangeThatFailsPasswordPolicy() { navigateToForcePasswordChange(); String invalidNewPassword = new RandomValueStringGenerator(256).generate(); webDriver.findElement(By.name("password")).sendKeys(invalidNewPassword); webDriver.findElement(By.name("password_confirmation")).sendKeys(invalidNewPassword); webDriver.findElement(By.xpath("//input[@value='Create new password']")).click(); assertEquals(baseUrl+"/force_password_change", webDriver.getCurrentUrl()); assertThat(webDriver.findElement(By.cssSelector(".error-message")).getText(), containsString("Password must be no more than 255 characters in length.")); }