Skip to content

Commit

Permalink
Solving Flakiness, some improvements simplifying test and using metho…
Browse files Browse the repository at this point in the history
…ds from NavigationUtilities
  • Loading branch information
augustocristian committed Dec 3, 2023
1 parent e4ed6e4 commit e8f1471
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,6 @@ public static List<String> getCoursesList(WebDriver wd, String host) throws Elem
return courses_names;

}
/* public static WebDriver removeTestCourseIfExist(WebDriver wd, String host) throws ElementNotFoundException {//13 lines
List<String > courses= getCoursesList(wd, host);
if courses.get(courses.s)
return wd;
}*/


public static WebElement getCourseElement(WebDriver wd, String name) throws ElementNotFoundException { //14 lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import com.fullteaching.e2e.no_elastest.utils.Click;
import com.fullteaching.e2e.no_elastest.utils.ParameterLoader;
import com.fullteaching.e2e.no_elastest.utils.Wait;
import com.google.gson.annotations.Until;
import giis.retorch.annotations.AccessMode;
import giis.retorch.annotations.Resource;
import io.github.bonigarcia.seljup.SeleniumJupiter;
import org.junit.Assert;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -26,18 +28,17 @@
import java.util.stream.Stream;

import static com.fullteaching.e2e.no_elastest.common.Constants.*;
import static com.fullteaching.e2e.no_elastest.common.CourseNavigationUtilities.checkIfCourseExists;
import static com.fullteaching.e2e.no_elastest.common.CourseNavigationUtilities.getCoursesList;
import static org.junit.jupiter.api.Assertions.*;


@ExtendWith(SeleniumJupiter.class)
class CourseTeacherTest extends BaseLoggedTest {


public static Stream<Arguments> data() throws IOException {
return ParameterLoader.getTestTeachers();
}


/**
* This test get the login the user, go the courses and select the default
* course.Once the user it's here, it clicks upon the different tabs(Course info,sessions,Forum,Files
Expand Down Expand Up @@ -107,42 +108,29 @@ void teacherCourseMainTest(String mail, String password, String role) {//39+80+
@AccessMode(resID = "Course", concurrency = 15, sharing = true, accessMode = "DYNAMIC")
@ParameterizedTest
@MethodSource("data")
void teacherCreateAndDeleteCourseTest(String mail, String password, String role) throws ElementNotFoundException {//58+93+28 set up +13 lines teardown =192
this.slowLogin(user, mail, password); //24 lines
boolean found = false;
int numberOfCourses = 0;
try {
// navigate to course tab if not there
if (NavigationUtilities.amINotHere(driver, COURSES_URL.replace("__HOST__", HOST))) //9lines
NavigationUtilities.toCoursesHome(driver); //3lines
} catch (Exception e) {
fail("Failed to go to Courses " + e.getClass() + ": " + e.getLocalizedMessage());
}
try {
//Count number of courses
WebElement courses_list = Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(COURSE_LIST));
//find the newly create course
List<WebElement> courses = courses_list.findElements(By.tagName("li"));
numberOfCourses = courses.size();
void teacherCreateAndDeleteCourseTest(String mail, String password, String role) throws ElementNotFoundException {
// Setup
this.slowLogin(user, mail, password);

} catch (Exception e) {
fail("Not possible get the number of courses " + e.getClass() + ": " + e.getLocalizedMessage());
}
course_title = "Test Course_" + System.currentTimeMillis();
// Create a new course
String courseTitle = "Test Course_" + System.currentTimeMillis();
CourseNavigationUtilities.newCourse(user.getDriver(), HOST, courseTitle);

// Verify the course has been created
Assert.assertTrue(checkIfCourseExists(driver, courseTitle));

// Delete the course
CourseNavigationUtilities.deleteCourse(user.getDriver(), courseTitle, HOST);

CourseNavigationUtilities.newCourse(user.getDriver(), HOST, course_title);
user.waitUntil(ExpectedConditions.numberOfElementsToBe(By.cssSelector("#course-list .course-list-item"),
numberOfCourses + 1), "Unexpected number of courses");
assertTrue(CourseNavigationUtilities.checkIfCourseExists(user.getDriver(), course_title), "The course title hasn't been found in the list ¿Have been created?");
CourseNavigationUtilities.deleteCourse(user.getDriver(), course_title, HOST);
user.waitUntil(ExpectedConditions.numberOfElementsToBe(By.cssSelector("#course-list .course-list-item"),
numberOfCourses), "Unexpected number of courses");
assertFalse(CourseNavigationUtilities.checkIfCourseExists(user.getDriver(), course_title), "the course still exists");//15lines
//Return to the mainpage
// Verify the course has been deleted
Assert.assertFalse(checkIfCourseExists(driver, courseTitle));

// Teardown
user.getDriver().get(APP_URL);
//Well done!!!
}



/**
* This test get the login the user, go to the courses and in first place, edits the
* course title, change its name for EDIT_+ one timestamp to avoid test overlapping.After that, we proceed
Expand Down Expand Up @@ -184,11 +172,11 @@ void teacherEditCourseValues(String mail, String password, String role) {//165+2
driver = CourseNavigationUtilities.changeCourseName(driver, old_name, edition_name);//21 lines
//check if course exists
log.info("Checking if course exists");
assertTrue(CourseNavigationUtilities.checkIfCourseExists(driver, edition_name, 3), "The course title hasn't been found in the list ¿Have been created?");//10 lines
assertTrue(checkIfCourseExists(driver, edition_name, 3), "The course title hasn't been found in the list ¿Have been created?");//10 lines
//return to old name
log.info("Rolling back to old name");
driver = CourseNavigationUtilities.changeCourseName(driver, edition_name, old_name); //21 lines
assertTrue(CourseNavigationUtilities.checkIfCourseExists(driver, old_name, 3), "The course title hasn't been reset"); //10 lines
assertTrue(checkIfCourseExists(driver, old_name, 3), "The course title hasn't been reset"); //10 lines
} catch (Exception e) {
fail("Failed to edit course name " + e.getClass() + ": " + e.getLocalizedMessage());
}
Expand Down Expand Up @@ -359,5 +347,4 @@ void teacherDeleteCourseTest(String mail, String password, String role) throws E
//Well done!
}


}

0 comments on commit e8f1471

Please sign in to comment.