From 4dc4571a1c074bf1129d29c53d4921cb4bc8c2a5 Mon Sep 17 00:00:00 2001 From: reppuli92 Date: Mon, 13 Apr 2026 10:24:42 +0300 Subject: [PATCH] Improve e2e testing coverage and robustness --- e2e_tests/assets/functions.py | 2 ++ e2e_tests/assets/functions2.py | 2 ++ e2e_tests/helpers.py | 2 +- e2e_tests/test_file_upload_grader.py | 39 ++++++++++++++++++++++++-- e2e_tests/test_main_navigation.py | 41 ++++++++++++++++++++++++++-- e2e_tests/test_text_exercise.py | 6 ++-- 6 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 e2e_tests/assets/functions.py create mode 100644 e2e_tests/assets/functions2.py diff --git a/e2e_tests/assets/functions.py b/e2e_tests/assets/functions.py new file mode 100644 index 000000000..2f866ff08 --- /dev/null +++ b/e2e_tests/assets/functions.py @@ -0,0 +1,2 @@ +def hello() -> str: + return "Hello Python!" \ No newline at end of file diff --git a/e2e_tests/assets/functions2.py b/e2e_tests/assets/functions2.py new file mode 100644 index 000000000..e24ceec9d --- /dev/null +++ b/e2e_tests/assets/functions2.py @@ -0,0 +1,2 @@ +def hello() -> str: + return "Hello, world!" \ No newline at end of file diff --git a/e2e_tests/helpers.py b/e2e_tests/helpers.py index 5b299e454..af1baae77 100644 --- a/e2e_tests/helpers.py +++ b/e2e_tests/helpers.py @@ -31,7 +31,7 @@ def logout(page: Page): def upload_submission(page: Page, chapter_name: str, exercise_name: str, files: List[File]): page.get_by_label("Course").get_by_role( "link", name="Course materials").click() - page.get_by_role("link", name=chapter_name).click() + page.get_by_role("link", name=chapter_name).first.click() for file in files: page.get_by_label(file.label).set_input_files(os.path.join(assets_path, file.name)) page.locator(exercise_name).get_by_role("button", name="Submit").click() diff --git a/e2e_tests/test_file_upload_grader.py b/e2e_tests/test_file_upload_grader.py index 741259b5a..f3aab3f6a 100644 --- a/e2e_tests/test_file_upload_grader.py +++ b/e2e_tests/test_file_upload_grader.py @@ -1,6 +1,6 @@ import re from playwright.sync_api import Page, expect -from e2e_tests.helpers import navigate_to_default_course, login +from e2e_tests.helpers import File, navigate_to_default_course, login, upload_submission def test_should_not_submit_without_files(page: Page): @@ -22,4 +22,39 @@ def test_should_not_submit_without_files(page: Page): #clicking submit without files will not result in a submission expect(points).to_contain_text("0 / 10") -#TODO more tests ? \ No newline at end of file +def test_should_give_zero_points_on_incorrect_answer(page: Page): + page.goto("http://localhost:8000/?hl=en") + login(page, "student", "student") + navigate_to_default_course(page) + + upload_submission( + page, + chapter_name="6.3 Exercises with Python", + exercise_name="#chapter-exercise-1", + files=[File("functions2.py", "functions.py")] + ) + + exercise = page.locator('#chapter-exercise-1') + points = exercise.get_by_role("button", name=re.compile("Points")) + + #the submission should be incorrect and give zero points + expect(points).to_contain_text("0 / 10") + + +def test_should_give_full_points_on_correct_answer(page: Page): + page.goto("http://localhost:8000/?hl=en") + login(page, "student", "student") + navigate_to_default_course(page) + + upload_submission( + page, + chapter_name="6.3 Exercises with Python", + exercise_name="#chapter-exercise-1", + files=[File("functions.py")] + ) + + exercise = page.locator('#chapter-exercise-1') + points = exercise.get_by_role("button", name=re.compile("Points")) + + #the submission should be correct and give full points + expect(points).to_contain_text("10 / 10") \ No newline at end of file diff --git a/e2e_tests/test_main_navigation.py b/e2e_tests/test_main_navigation.py index 1e308072d..d8759312e 100644 --- a/e2e_tests/test_main_navigation.py +++ b/e2e_tests/test_main_navigation.py @@ -7,13 +7,48 @@ def test_main_navigation(page: Page): page.goto("http://localhost:8000/?hl=en") login(page, "teacher", "teacher") navigate_to_default_course(page) + sidebar = page.locator("#main-course-menu") - page.get_by_role("link", name="Your points").click() + sidebar.get_by_role("link", name="Course materials").click() + expect(page).to_have_url(re.compile("/toc/")) + navigate_to_default_course(page) + + sidebar.get_by_role("link", name="Your points").click() expect(page).to_have_url(re.compile("/user/results/")) navigate_to_default_course(page) - page.get_by_role("link", name="All results").click() + sidebar.get_by_role("link", name="Participants").click() + expect(page).to_have_url(re.compile("/teachers/participants/")) + navigate_to_default_course(page) + + sidebar.get_by_role("link", name="Groups").click() + expect(page).to_have_url(re.compile("/teachers/groups/")) + navigate_to_default_course(page) + + sidebar.get_by_role("link", name="All results").click() expect(page).to_have_url(re.compile("/teachers/results/")) + navigate_to_default_course(page) + + sidebar.get_by_role("link", name="Visualizations").click() + expect(page).to_have_url(re.compile("/teachers/analytics/")) + navigate_to_default_course(page) + + sidebar.get_by_role("link", name="Edit news").click() + expect(page).to_have_url(re.compile("/teachers/news/")) + navigate_to_default_course(page) + + sidebar.get_by_role("link", name="Edit course").click() + expect(page).to_have_url(re.compile("/teachers/")) + navigate_to_default_course(page) + + sidebar.get_by_role("link", name="Deadline deviations").click() + expect(page).to_have_url(re.compile("/teachers/deadline-deviations/")) + navigate_to_default_course(page) + + sidebar.get_by_role("link", name="Submission deviations").click() + expect(page).to_have_url(re.compile("/teachers/submission-deviations/")) + navigate_to_default_course(page) - #TODO test rest of links? Also student view? + sidebar.get_by_role("link", name="All submissions").click() + expect(page).to_have_url(re.compile("/teachers/all-submissions/")) \ No newline at end of file diff --git a/e2e_tests/test_text_exercise.py b/e2e_tests/test_text_exercise.py index dcbd45dbe..750aa89e5 100644 --- a/e2e_tests/test_text_exercise.py +++ b/e2e_tests/test_text_exercise.py @@ -57,7 +57,7 @@ def test_should_give_partial_points_on_partially_correct_submission(page: Page): page.goto("http://localhost:8000/?hl=en") login(page, "student", "student") navigate_to_default_course(page) - page.get_by_role("link", name="5.1 Creating questionnaire exercises").click() + page.get_by_role("link", name="5.1 Creating questionnaire exercises").first.click() #fill in an partially correct answer for exercise 5.1.3 #fill in different exercise to make the test work independently of the previous test @@ -78,7 +78,7 @@ def test_should_give_full_points_on_correct_submission(page: Page): page.goto("http://localhost:8000/?hl=en") login(page, "student", "student") navigate_to_default_course(page) - page.get_by_role("link", name="5.1 Creating questionnaire exercises").click() + page.get_by_role("link", name="5.1 Creating questionnaire exercises").first.click() #fill in an correct answer for exercise 5.1.4 #fill in different exercise to make the test work independently of the previous test @@ -99,7 +99,7 @@ def test_should_not_accept_submission_after_max_submissions_reached(page: Page): page.goto("http://localhost:8000/?hl=en") login(page, "student", "student") navigate_to_default_course(page) - page.get_by_role("link", name="5.1 Creating questionnaire exercises").click() + page.get_by_role("link", name="5.1 Creating questionnaire exercises").first.click() #fill in an false answer for exercise 5.1.2 until max submissions reached exercise = page.locator("#chapter-exercise-2")