Skip to content

Commit bfaf2eb

Browse files
reppuli92ihalaij1
authored andcommitted
Improve e2e testing coverage and robustness
1 parent cf842d3 commit bfaf2eb

6 files changed

Lines changed: 83 additions & 9 deletions

File tree

e2e_tests/assets/functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello() -> str:
2+
return "Hello Python!"

e2e_tests/assets/functions2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello() -> str:
2+
return "Hello, world!"

e2e_tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def logout(page: Page):
3131
def upload_submission(page: Page, chapter_name: str, exercise_name: str, files: List[File]):
3232
page.get_by_label("Course").get_by_role(
3333
"link", name="Course materials").click()
34-
page.get_by_role("link", name=chapter_name).click()
34+
page.get_by_role("link", name=chapter_name).first.click()
3535
for file in files:
3636
page.get_by_label(file.label).set_input_files(os.path.join(assets_path, file.name))
3737
page.locator(exercise_name).get_by_role("button", name="Submit").click()

e2e_tests/test_file_upload_grader.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from playwright.sync_api import Page, expect
3-
from e2e_tests.helpers import navigate_to_default_course, login
3+
from e2e_tests.helpers import File, navigate_to_default_course, login, upload_submission
44

55

66
def test_should_not_submit_without_files(page: Page):
@@ -22,4 +22,39 @@ def test_should_not_submit_without_files(page: Page):
2222
#clicking submit without files will not result in a submission
2323
expect(points).to_contain_text("0 / 10")
2424

25-
#TODO more tests ?
25+
def test_should_give_zero_points_on_incorrect_answer(page: Page):
26+
page.goto("http://localhost:8000/?hl=en")
27+
login(page, "student", "student")
28+
navigate_to_default_course(page)
29+
30+
upload_submission(
31+
page,
32+
chapter_name="6.3 Exercises with Python",
33+
exercise_name="#chapter-exercise-1",
34+
files=[File("functions2.py", "functions.py")]
35+
)
36+
37+
exercise = page.locator('#chapter-exercise-1')
38+
points = exercise.get_by_role("button", name=re.compile("Points"))
39+
40+
#the submission should be incorrect and give zero points
41+
expect(points).to_contain_text("0 / 10")
42+
43+
44+
def test_should_give_full_points_on_correct_answer(page: Page):
45+
page.goto("http://localhost:8000/?hl=en")
46+
login(page, "student", "student")
47+
navigate_to_default_course(page)
48+
49+
upload_submission(
50+
page,
51+
chapter_name="6.3 Exercises with Python",
52+
exercise_name="#chapter-exercise-1",
53+
files=[File("functions.py")]
54+
)
55+
56+
exercise = page.locator('#chapter-exercise-1')
57+
points = exercise.get_by_role("button", name=re.compile("Points"))
58+
59+
#the submission should be correct and give full points
60+
expect(points).to_contain_text("10 / 10")

e2e_tests/test_main_navigation.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,48 @@ def test_main_navigation(page: Page):
77
page.goto("http://localhost:8000/?hl=en")
88
login(page, "teacher", "teacher")
99
navigate_to_default_course(page)
10+
sidebar = page.locator("#main-course-menu")
1011

11-
page.get_by_role("link", name="Your points").click()
12+
sidebar.get_by_role("link", name="Course materials").click()
13+
expect(page).to_have_url(re.compile("/toc/"))
14+
navigate_to_default_course(page)
15+
16+
sidebar.get_by_role("link", name="Your points").click()
1217
expect(page).to_have_url(re.compile("/user/results/"))
1318
navigate_to_default_course(page)
1419

15-
page.get_by_role("link", name="All results").click()
20+
sidebar.get_by_role("link", name="Participants").click()
21+
expect(page).to_have_url(re.compile("/teachers/participants/"))
22+
navigate_to_default_course(page)
23+
24+
sidebar.get_by_role("link", name="Groups").click()
25+
expect(page).to_have_url(re.compile("/teachers/groups/"))
26+
navigate_to_default_course(page)
27+
28+
sidebar.get_by_role("link", name="All results").click()
1629
expect(page).to_have_url(re.compile("/teachers/results/"))
30+
navigate_to_default_course(page)
31+
32+
sidebar.get_by_role("link", name="Visualizations").click()
33+
expect(page).to_have_url(re.compile("/teachers/analytics/"))
34+
navigate_to_default_course(page)
35+
36+
sidebar.get_by_role("link", name="Edit news").click()
37+
expect(page).to_have_url(re.compile("/teachers/news/"))
38+
navigate_to_default_course(page)
39+
40+
sidebar.get_by_role("link", name="Edit course").click()
41+
expect(page).to_have_url(re.compile("/teachers/"))
42+
navigate_to_default_course(page)
43+
44+
sidebar.get_by_role("link", name="Deadline deviations").click()
45+
expect(page).to_have_url(re.compile("/teachers/deadline-deviations/"))
46+
navigate_to_default_course(page)
47+
48+
sidebar.get_by_role("link", name="Submission deviations").click()
49+
expect(page).to_have_url(re.compile("/teachers/submission-deviations/"))
50+
navigate_to_default_course(page)
1751

18-
#TODO test rest of links? Also student view?
52+
sidebar.get_by_role("link", name="All submissions").click()
53+
expect(page).to_have_url(re.compile("/teachers/all-submissions/"))
1954

e2e_tests/test_text_exercise.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_should_give_partial_points_on_partially_correct_submission(page: Page):
5757
page.goto("http://localhost:8000/?hl=en")
5858
login(page, "student", "student")
5959
navigate_to_default_course(page)
60-
page.get_by_role("link", name="5.1 Creating questionnaire exercises").click()
60+
page.get_by_role("link", name="5.1 Creating questionnaire exercises").first.click()
6161

6262
#fill in an partially correct answer for exercise 5.1.3
6363
#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):
7878
page.goto("http://localhost:8000/?hl=en")
7979
login(page, "student", "student")
8080
navigate_to_default_course(page)
81-
page.get_by_role("link", name="5.1 Creating questionnaire exercises").click()
81+
page.get_by_role("link", name="5.1 Creating questionnaire exercises").first.click()
8282

8383
#fill in an correct answer for exercise 5.1.4
8484
#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):
9999
page.goto("http://localhost:8000/?hl=en")
100100
login(page, "student", "student")
101101
navigate_to_default_course(page)
102-
page.get_by_role("link", name="5.1 Creating questionnaire exercises").click()
102+
page.get_by_role("link", name="5.1 Creating questionnaire exercises").first.click()
103103

104104
#fill in an false answer for exercise 5.1.2 until max submissions reached
105105
exercise = page.locator("#chapter-exercise-2")

0 commit comments

Comments
 (0)