feat: Introduce Playwright for UI testing

Instead of using Robot Framework which does not run during a `mvn install`. Playwright seems to be the better approach. We can now write them as normal JUnit test and they are executed during a build.

Additionally this PR solves some interesting bugs found during writing Playwright tests:

- A reset of a lesson removes all assignments as a result another user wouldn't see any assignments
- If someone solves an assignment the assignment automatically got solved for a new user since the assignment included the `solved` flag which immediately got copied to new lesson progress.
- Introduction of assignment progress linking a assignment not directly to all users.
This commit is contained in:
Nanne Baars
2025-01-26 16:59:59 +01:00
committed by GitHub
parent 9d5ab5fb21
commit 8e45316638
47 changed files with 599 additions and 281 deletions

View File

@ -16,6 +16,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.owasp.webgoat.container.lessons.Assignment;
import org.owasp.webgoat.container.lessons.Lesson;
import org.owasp.webgoat.container.session.Course;
import org.owasp.webgoat.container.users.AssignmentProgress;
import org.owasp.webgoat.container.users.LessonProgress;
import org.owasp.webgoat.container.users.UserProgress;
import org.owasp.webgoat.container.users.UserProgressRepository;
@ -68,10 +69,11 @@ class LessonProgressServiceTest {
@BeforeEach
void setup() {
Assignment assignment = new Assignment("test", "test", List.of());
AssignmentProgress assignmentProgress = new AssignmentProgress(assignment);
when(userProgressRepository.findByUser(any())).thenReturn(userProgress);
when(userProgress.getLessonProgress(any(Lesson.class))).thenReturn(lessonTracker);
when(course.getLessonByName(any())).thenReturn(lesson);
when(lessonTracker.getLessonOverview()).thenReturn(Maps.newHashMap(assignment, true));
when(lessonTracker.getLessonOverview()).thenReturn(Maps.newHashMap(assignmentProgress, true));
this.mockMvc =
MockMvcBuilders.standaloneSetup(new LessonProgressService(userProgressRepository, course))
.build();

View File

@ -11,6 +11,7 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.owasp.webgoat.container.lessons.Assignment;
import org.owasp.webgoat.container.lessons.Lesson;
import org.owasp.webgoat.container.users.AssignmentProgress;
import org.owasp.webgoat.container.users.LessonProgress;
/**
@ -67,9 +68,8 @@ class LessonTrackerTest {
LessonProgress lessonTracker = new LessonProgress(lesson);
lessonTracker.assignmentSolved("a1");
Map<Assignment, Boolean> lessonOverview = lessonTracker.getLessonOverview();
assertThat(lessonOverview.get(a1)).isTrue();
assertThat(lessonOverview.get(a2)).isFalse();
Map<AssignmentProgress, Boolean> lessonOverview = lessonTracker.getLessonOverview();
assertThat(lessonOverview.values()).containsExactlyInAnyOrder(true, false);
}
@Test