/** * @see By#className(java.lang.String) * @since 3.8 */ public static By byClassName(String className) { return By.className(className); } }
private void saveAlertErrorMessage() { try { WebElement element = webDriver.findElement(By.className("alert-error")); alertError = Optional.of(element.getText()); } catch (NoSuchElementException _) { // do nothing } } }
@Test public void testAccountChooserFlow() throws Exception { String zoneUrl = createDiscoveryZone(); String userEmail = createAnotherUser(zoneUrl); webDriver.get(zoneUrl + "/logout.do"); webDriver.get(zoneUrl); loginThroughDiscovery(userEmail, USER_PASSWORD); webDriver.get(zoneUrl + "/logout.do"); webDriver.get(zoneUrl); assertEquals(userEmail, webDriver.findElement(By.className("email-address")).getText()); webDriver.findElement(By.className("email-address")).click(); assertEquals(userEmail, webDriver.findElement(By.id("username")).getAttribute("value")); webDriver.findElement(By.id("password")).sendKeys(USER_PASSWORD); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); assertEquals("Where to?", webDriver.findElement(By.cssSelector(".island h1")).getText()); }
@Test public void testInvalidAppRedirectDisplaysError() throws Exception { ScimUser user = createUnapprovedUser(serverRunning); // given we vist the app (specifying an invalid redirect - incorrect protocol https) webDriver.get(appUrl + "?redirect_uri=https://localhost:8080/app/"); // Sign in to login server webDriver.findElement(By.name("username")).sendKeys(user.getUserName()); webDriver.findElement(By.name("password")).sendKeys(user.getPassword()); webDriver.findElement(By.xpath("//input[@value='Sign in']")).click(); // Authorize the app for some scopes assertThat(webDriver.findElement(By.className("alert-error")).getText(), IntegrationTestUtils.RegexMatcher.matchesRegex("^Invalid redirect (.*) did not match one of the registered values")); }
@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"); }
@Test public void displaysErrorWhenPasswordContravenesPolicy() { //the only policy we can contravene by default is the length String newPassword = new RandomValueStringGenerator(260).generate(); webDriver.get(baseUrl + "/change_password"); signIn(userEmail, PASSWORD); changePassword(PASSWORD, newPassword, newPassword); WebElement errorMessage = webDriver.findElement(By.className("error-message")); assertTrue(errorMessage.isDisplayed()); assertEquals("Password must be no more than 255 characters in length.", errorMessage.getText()); }
@Test public void testChangePassword() throws Exception { webDriver.get(baseUrl + "/change_password"); signIn(userEmail, PASSWORD); changePassword(PASSWORD, NEW_PASSWORD, "new"); WebElement errorMessage = webDriver.findElement(By.className("error-message")); assertTrue(errorMessage.isDisplayed()); assertEquals("Passwords must match and not be empty.", errorMessage.getText()); changePassword(PASSWORD, NEW_PASSWORD, NEW_PASSWORD); signOut(); signIn(userEmail, NEW_PASSWORD); }
/** * Returns number of question edit forms + question add form. */ public int getNumberOfQuestionEditForms() { return browser.driver.findElements(By.className("questionTable")).size(); }
private void waitForModalShown() { // Possible exploration: Change to listening to modal shown event as // this is based on the implementation detail assumption that once modal-backdrop is added the modal is shown waitForElementVisibility(By.className("modal-backdrop")); }
public void closeCommentModal(String commentId) { WebElement commentModal = browser.driver.findElement(By.id("commentModal" + commentId)); WebElement modalFooter = commentModal.findElement(By.className("modal-footer")); WebElement closeButton = modalFooter.findElement(By.className("commentModalClose")); clickDismissModalButtonAndWaitForModalHidden(closeButton); }
private int getStudentRowId(String studentName) { int studentCount = browser.driver.findElements(By.className("student_row")).size(); for (int i = 0; i < studentCount; i++) { String studentNameInRow = getStudentNameInRow(i); if (studentNameInRow.equals(studentName)) { return i; } } return -1; }
public boolean isVisibilityDropdownOptionHidden(String optionValue, int qnNumber) { return browser.driver.findElement(By.id("questionTable-" + qnNumber)) .findElement(By.className("visibility-options-dropdown-option")) .findElement(By.xpath("//a[@data-option-name='" + optionValue + "']/..")) .getAttribute("class").contains("hidden"); }
public void waitForAjaxLoadCoursesError() { By element = By.id("retryAjax"); waitForElementPresence(element); WebElement statusMessage = browser.driver.findElement(By.id("statusMessagesToUser")).findElement(By.className("statusMessage")); assertEquals("Courses could not be loaded. Click here to retry.", statusMessage.getText()); }
/** * Returns the number of rows from the nth(0-index-based) table * (which is of type {@code class=table}) in the page. */ public int getNumberOfRowsFromDataTable(int tableNum) { WebElement tableElement = browser.driver.findElements(By.className("table")).get(tableNum); return tableElement.findElements(By.tagName("tr")).size(); }
public InstructorCourseEnrollPage loadEnrollLink(String courseId) { int courseRowNumber = getRowNumberOfCourse(courseId); return goToLinkInRow( By.className("t_course_enroll" + courseRowNumber), InstructorCourseEnrollPage.class); }
public InstructorCourseEditPage loadEditLink(String courseId) { int courseRowNumber = getRowNumberOfCourse(courseId); return goToLinkInRow( By.className("t_course_edit" + courseRowNumber), InstructorCourseEditPage.class); }
/** * Waits for a confirmation modal to appear and click the cancel button. */ public void waitForConfirmationModalAndClickCancel() { waitForModalShown(); WebElement cancelButton = browser.driver.findElement(By.className("modal-btn-cancel")); waitForElementToBeClickable(cancelButton); clickDismissModalButtonAndWaitForModalHidden(cancelButton); }
/** * Returns the value of the header located at {@code (row, column)} * from the nth(0-index-based) table (which is of type {@code class=table}) in the page. */ public String getHeaderValueFromDataTable(int tableNum, int row, int column) { WebElement tableElement = browser.driver.findElements(By.className("table")).get(tableNum); WebElement trElement = tableElement.findElements(By.tagName("tr")).get(row); WebElement tdElement = trElement.findElements(By.tagName("th")).get(column); return tdElement.getText(); }
public void clickCommentModalButton(String commentId) { WebElement commentModal = browser.driver.findElement(By.id("commentModal" + commentId)); WebElement parentTable = commentModal.findElement(By.xpath("../..")); WebElement commentButton = parentTable.findElement(By.className("comment-button")); click(commentButton); }
/** * Returns the number of columns from the header in the table * (which is of type {@code class=table}) in the page. */ public int getNumberOfColumnsFromDataTable(int tableNum) { WebElement tableElement = browser.driver.findElements(By.className("table")).get(tableNum); WebElement trElement = tableElement.findElement(By.tagName("tr")); return trElement.findElements(By.tagName("th")).size(); }