Skip to content

Commit

Permalink
Adding a waiter for the number of courses prior its removal is one le…
Browse files Browse the repository at this point in the history
…ss than the initial (#129)
  • Loading branch information
augustocristian authored Jul 29, 2024
1 parent b0b8f19 commit d2fe4f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -21,7 +20,7 @@

public class CourseNavigationUtilities {

private static final Logger log = LoggerFactory.getLogger(CourseNavigationUtilities.class);
private static final Logger log = getLogger(CourseNavigationUtilities.class);

public static String newCourse(WebDriver wd, String courseName) throws ElementNotFoundException { //37 lines
NavigationUtilities.toCoursesHome(wd);
Expand All @@ -32,7 +31,7 @@ public static String newCourse(WebDriver wd, String courseName) throws ElementNo
Click.byJS(wd, newCourseButton);
Wait.notTooMuch(wd).until(ExpectedConditions.visibilityOfElementLocated(NEW_COURSE_MODAL));

log.debug("Introducing Course Name: "+courseName);
log.debug("Introducing Course Name: {}", courseName);
WebElement nameField = Wait.aLittle(wd).until(ExpectedConditions.visibilityOfElementLocated(NEW_COURSE_MODAL_NAME_FIELD));
nameField.sendKeys(courseName);
Click.element(wd, By.id(NEW_COURSE_MODAL_SAVE_ID));
Expand All @@ -49,16 +48,18 @@ public static boolean checkIfCourseExists(WebDriver wd, String courseTitle) {
List<WebElement> courses = courseList.findElements(By.tagName("li"));

for (WebElement course : courses) {
String titleText = "No courses";
try {
WebElement titleElement = course.findElement(By.className("title"));
String titleText = titleElement.getText();
titleText = titleElement.getText();

if (courseTitle.equals(titleText)) {
log.info("The course with title {} exists!", courseTitle);
return true;
}
} catch (NoSuchElementException ignored) {
// Do nothing and look for the next item
log.debug("The current course is:{} and the course that we are searching is {}",courseTitle,titleText);
}
}
return false;
Expand Down Expand Up @@ -117,8 +118,8 @@ public static void deleteCourse(WebDriver wd, String courseName) throws ElementN
log.info("[INI] deleteCourse({})", courseName);

NavigationUtilities.toCoursesHome(wd);
Wait.notTooMuch(wd).until(ExpectedConditions.visibilityOfElementLocated(COURSE_LIST));

WebElement coursesList = Wait.notTooMuch(wd).until(ExpectedConditions.visibilityOfElementLocated(COURSE_LIST));
int numcoursesinitial=coursesList.findElements(By.tagName("li")).size();
try {
WebElement courseElement = getCourseByName(wd, courseName);
openEditCourseModal(wd, courseElement);
Expand All @@ -137,6 +138,12 @@ public static void deleteCourse(WebDriver wd, String courseName) throws ElementN
log.error("[END] deleteCourse KO: Course \"{}\" probably doesn't exist", courseName);
throw new ElementNotFoundException("deleteCourse - Course " + courseName + " probably doesn't exist");
}
log.debug("Checking that after removing the course, the number of courses is {} minus one", numcoursesinitial);
Wait.notTooMuch(wd).until(driver -> {
WebElement listCourses = driver.findElement(COURSE_LIST);
int currentNumberOfCourses = listCourses.findElements(By.tagName("li")).size();
return currentNumberOfCourses == numcoursesinitial - 1;
});

log.info("[END] deleteCourse OK: Course \"{}\"", courseName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void teacherCreateAndDeleteCourseTest(String mail, String password, String role)
// Create a new course
String courseTitle = "Test Course_" + System.currentTimeMillis();
CourseNavigationUtilities.newCourse(user.getDriver(), courseTitle);

//TO-DO the problem its here
// Verify the course has been created
assertTrue(checkIfCourseExists(driver, courseTitle));

Expand Down

0 comments on commit d2fe4f8

Please sign in to comment.