Skip to content

Commit

Permalink
Development: Improve execution speed of Playwright tests (#9817)
Browse files Browse the repository at this point in the history
  • Loading branch information
muradium authored Nov 21, 2024
1 parent 5024862 commit 5efb5f4
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 120 deletions.
15 changes: 8 additions & 7 deletions src/test/playwright/e2e/exam/ExamAssessment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ test.beforeAll('Create course', async ({ browser }) => {
studentOneName = (await users.getUserInfo(studentOne.username, page)).name!;
});

test.describe('Exam assessment', { tag: '@slow' }, () => {
test.describe('Exam assessment', () => {
test.describe.configure({ mode: 'serial' });
let programmingAssessmentSuccessful = false;
let modelingAssessmentSuccessful = false;
let textAssessmentSuccessful = false;

test.describe.serial('Programming exercise assessment', () => {
test.describe.serial('Programming exercise assessment', { tag: '@sequential' }, () => {
test.beforeAll('Prepare exam', async ({ browser }) => {
examEnd = dayjs().add(2, 'minutes');
const page = await newBrowserPage(browser);
Expand All @@ -85,7 +86,7 @@ test.describe('Exam assessment', { tag: '@slow' }, () => {
});
});

test.describe.serial('Modeling exercise assessment', () => {
test.describe.serial('Modeling exercise assessment', { tag: '@slow' }, () => {
test.beforeAll('Prepare exam', async ({ browser }) => {
examEnd = dayjs().add(45, 'seconds');
const page = await newBrowserPage(browser);
Expand Down Expand Up @@ -126,7 +127,7 @@ test.describe('Exam assessment', { tag: '@slow' }, () => {
});
});

test.describe.serial('Text exercise assessment', () => {
test.describe.serial('Text exercise assessment', { tag: '@slow' }, () => {
test.beforeAll('Prepare exam', async ({ browser }) => {
examEnd = dayjs().add(40, 'seconds');
const page = await newBrowserPage(browser);
Expand All @@ -153,7 +154,7 @@ test.describe('Exam assessment', { tag: '@slow' }, () => {
});
});

test.describe('Quiz exercise assessment', () => {
test.describe('Quiz exercise assessment', { tag: '@slow' }, () => {
let resultDate: Dayjs;

test.beforeAll('Prepare exam', async ({ browser }) => {
Expand Down Expand Up @@ -183,7 +184,7 @@ test.describe('Exam assessment', { tag: '@slow' }, () => {
});
});

test.describe('Exam grading', () => {
test.describe('Exam grading', { tag: '@fast' }, () => {
test.describe.serial('Instructor sets grades and student receives a grade', () => {
let exam: Exam;

Expand Down Expand Up @@ -222,7 +223,7 @@ test.describe('Exam grading', () => {
});
});

test.describe('Exam statistics', { tag: '@slow' }, () => {
test.describe('Exam statistics', { tag: '@sequential' }, () => {
let exercise: Exercise;
const students = [studentOne, studentTwo, studentThree, studentFour];

Expand Down
11 changes: 5 additions & 6 deletions src/test/playwright/e2e/exam/ExamParticipation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ExamParticipationActions } from '../../support/pageobjects/exam/ExamPar
const textFixture = 'loremIpsum.txt';
const textFixtureShort = 'loremIpsum-short.txt';

test.describe('Exam participation', { tag: '@slow' }, () => {
test.describe('Exam participation', () => {
let course: Course;
let exerciseArray: Array<Exercise> = [];
let studentTwoName: string;
Expand All @@ -43,7 +43,7 @@ test.describe('Exam participation', { tag: '@slow' }, () => {
studentFourName = studentFourInfo.name!;
});

test.describe('Early Hand-in', () => {
test.describe('Early Hand-in', { tag: '@slow' }, () => {
let exam: Exam;
const examTitle = 'exam' + generateUUID();

Expand Down Expand Up @@ -107,7 +107,6 @@ test.describe('Exam participation', { tag: '@slow' }, () => {
await examParticipation.startParticipation(studentFour, course, exam);
for (let j = 0; j < exerciseArray.length; j++) {
const exercise = exerciseArray[j];
// await
await examNavigation.openFromOverviewByTitle(exercise.exerciseGroup!.title!);
await examNavigation.openOverview();
}
Expand All @@ -118,7 +117,7 @@ test.describe('Exam participation', { tag: '@slow' }, () => {
});
});

test.describe('Early hand-in with continue and reload page', () => {
test.describe('Early hand-in with continue and reload page', { tag: '@slow' }, () => {
let exam: Exam;
const examTitle = 'exam' + generateUUID();

Expand Down Expand Up @@ -222,7 +221,7 @@ test.describe('Exam participation', { tag: '@slow' }, () => {
});
});

test.describe('Normal Hand-in', () => {
test.describe('Normal Hand-in', { tag: '@sequential' }, () => {
let exam: Exam;
const examTitle = 'exam' + generateUUID();

Expand Down Expand Up @@ -259,7 +258,7 @@ test.describe('Exam participation', { tag: '@slow' }, () => {
});
});

test.describe('Exam announcements', () => {
test.describe('Exam announcements', { tag: '@slow' }, () => {
let exam: Exam;
const students = [studentOne, studentTwo];

Expand Down
80 changes: 42 additions & 38 deletions src/test/playwright/e2e/exam/ExamResults.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ProgrammingExerciseTaskStatus } from '../../support/pageobjects/exam/Ex
import { Page } from '@playwright/test';
import { StudentExam } from 'app/entities/student-exam.model';

test.describe('Exam Results', { tag: '@slow' }, () => {
test.describe('Exam Results', () => {
let course: Course;

test.beforeEach('Create course', async ({ browser }) => {
Expand Down Expand Up @@ -126,44 +126,48 @@ test.describe('Exam Results', { tag: '@slow' }, () => {
},
);

test(`Check exam ${exerciseTypeString} exercise results`, async ({ page, login, examParticipation, examResultsPage }) => {
await login(studentOne);
await waitForExamEnd(examEndDate, page);
await page.goto(`/courses/${course.id}/exams/${exam.id}`);
await examParticipation.checkResultScore(testCase.resultScore, exercise.id!);
test(
`Check exam ${exerciseTypeString} exercise results`,
{ tag: testCase.exerciseType === ExerciseType.PROGRAMMING ? '@sequential' : '@slow' },
async ({ page, login, examParticipation, examResultsPage }) => {
await login(studentOne);
await waitForExamEnd(examEndDate, page);
await page.goto(`/courses/${course.id}/exams/${exam.id}`);
await examParticipation.checkResultScore(testCase.resultScore, exercise.id!);

switch (testCase.exerciseType) {
case ExerciseType.TEXT:
await examResultsPage.checkTextExerciseContent(exercise.id!, exercise.additionalData!.textFixture!);
await examResultsPage.checkAdditionalFeedback(exercise.id!, 7, 'Good job');
break;
case ExerciseType.PROGRAMMING:
await examResultsPage.checkProgrammingExerciseAssessments(exercise.id!, 'Wrong', 7);
await examResultsPage.checkProgrammingExerciseAssessments(exercise.id!, 'Correct', 6);
const taskStatuses: ProgrammingExerciseTaskStatus[] = [
ProgrammingExerciseTaskStatus.SUCCESS,
ProgrammingExerciseTaskStatus.SUCCESS,
ProgrammingExerciseTaskStatus.SUCCESS,
ProgrammingExerciseTaskStatus.FAILURE,
ProgrammingExerciseTaskStatus.FAILURE,
ProgrammingExerciseTaskStatus.FAILURE,
ProgrammingExerciseTaskStatus.FAILURE,
];
await examResultsPage.checkProgrammingExerciseTasks(exercise.id!, taskStatuses);
break;
case ExerciseType.QUIZ:
await examResultsPage.checkQuizExerciseScore(exercise.id!, 5, 10);
const studentAnswers = [true, false, true, false];
const correctAnswers = [true, true, false, false];
await examResultsPage.checkQuizExerciseAnswers(exercise.id!, studentAnswers, correctAnswers);
break;
case ExerciseType.MODELING:
await examResultsPage.checkAdditionalFeedback(exercise.id!, 5, 'Good');
await examResultsPage.checkModellingExerciseAssessment(exercise.id!, 'class Class', 'Wrong', -1);
await examResultsPage.checkModellingExerciseAssessment(exercise.id!, 'abstract class Abstract', 'Neutral', 0);
break;
}
});
switch (testCase.exerciseType) {
case ExerciseType.TEXT:
await examResultsPage.checkTextExerciseContent(exercise.id!, exercise.additionalData!.textFixture!);
await examResultsPage.checkAdditionalFeedback(exercise.id!, 7, 'Good job');
break;
case ExerciseType.PROGRAMMING:
await examResultsPage.checkProgrammingExerciseAssessments(exercise.id!, 'Wrong', 7);
await examResultsPage.checkProgrammingExerciseAssessments(exercise.id!, 'Correct', 6);
const taskStatuses: ProgrammingExerciseTaskStatus[] = [
ProgrammingExerciseTaskStatus.SUCCESS,
ProgrammingExerciseTaskStatus.SUCCESS,
ProgrammingExerciseTaskStatus.SUCCESS,
ProgrammingExerciseTaskStatus.FAILURE,
ProgrammingExerciseTaskStatus.FAILURE,
ProgrammingExerciseTaskStatus.FAILURE,
ProgrammingExerciseTaskStatus.FAILURE,
];
await examResultsPage.checkProgrammingExerciseTasks(exercise.id!, taskStatuses);
break;
case ExerciseType.QUIZ:
await examResultsPage.checkQuizExerciseScore(exercise.id!, 5, 10);
const studentAnswers = [true, false, true, false];
const correctAnswers = [true, true, false, false];
await examResultsPage.checkQuizExerciseAnswers(exercise.id!, studentAnswers, correctAnswers);
break;
case ExerciseType.MODELING:
await examResultsPage.checkAdditionalFeedback(exercise.id!, 5, 'Good');
await examResultsPage.checkModellingExerciseAssessment(exercise.id!, 'class Class', 'Wrong', -1);
await examResultsPage.checkModellingExerciseAssessment(exercise.id!, 'abstract class Abstract', 'Neutral', 0);
break;
}
},
);

if (testCase.exerciseType === ExerciseType.TEXT) {
test('Check exam result overview', async ({ page, login, examAPIRequests, examResultsPage }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/playwright/e2e/exam/ExamTestRun.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { expect } from '@playwright/test';
const textFixture = 'loremIpsum-short.txt';
const examTitle = 'exam' + generateUUID();

test.describe('Exam test run', { tag: '@slow' }, () => {
test.describe('Exam test run', { tag: '@fast' }, () => {
let course: Course;
let exam: Exam;
let exerciseArray: Array<Exercise> = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const examData = {
confirmationEndText: 'Exam confirmation end text',
};

test.describe('Test Exam creation/deletion', { tag: '@slow' }, () => {
test.describe('Test Exam creation/deletion', { tag: '@fast' }, () => {
let course: Course;
let exam: Exam;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { expect } from '@playwright/test';
const uid = generateUUID();
const examTitle = 'test-exam' + uid;

test.describe('Test Exam management', { tag: '@slow' }, () => {
test.describe('Test Exam management', { tag: '@fast' }, () => {
let course: Course;
let exam: Exam;

Expand Down
Loading

0 comments on commit 5efb5f4

Please sign in to comment.