Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Improve exercise import e2e tests #10305

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

muradium
Copy link
Contributor

@muradium muradium commented Feb 11, 2025

Checklist

General

Client

Motivation and Context

While importing an exercise, loading exercise information and displaying it on exercise create/modify form may sometimes take longer. This was causing relevant E2E tests to be flaky, especially on multi-node configuration.

Description

This PR improves the waiting mechanism during execution of E2E tests. It waits for the exercise information to be loaded before making any assertions. It also removes some code repetition by small refactoring.

Steps for Testing

  • Code Review: Ensure that test passes for valid reasons and improvements make sense.
  • CI testing: Check that all tests pass on both single-node and multi-node Artemis Bamboo builds.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Summary by CodeRabbit

  • Tests
    • Enhanced synchronization in exercise import and creation workflows to ensure all forms load completely before interactions.
    • Updated method calls for setting titles in various exercises to improve clarity and consistency.
  • Refactor
    • Unified shared functionalities across various exercise types—including file upload, modeling, programming, quiz, and text—streamlining the creation process.
  • Chores
    • Updated naming conventions for improved clarity and maintainability.

Copy link

coderabbitai bot commented Feb 11, 2025

Walkthrough

The changes enhance Playwright tests and page objects for exercise import and management. In the test suites, explicit waits using waitForFormToLoad() have been added to synchronize UI readiness. Additionally, a method rename (from typeTitle to setTitle) standardizes the API in file upload tests. Several page objects have been refactored to extend a new AbstractExerciseCreationPage, which centralizes common form interactions and removes redundant date handling from specialized pages. Import statements and type definitions have been updated accordingly to align with these refactorings.

Changes

File(s) Change Summary
src/test/playwright/e2e/exercise/ExerciseImport.spec.ts
src/test/playwright/e2e/exercise/file-upload/FileUploadExerciseManagement.spec.ts
Added waitForFormToLoad() calls to various exercise creation tests and replaced a fixed timeout with dynamic waiting; renamed method from typeTitle to setTitle in file upload tests.
src/test/playwright/support/fixtures.ts Updated import and type reference from CreateModelingExercisePage to ModelingExerciseCreationPage.
src/test/playwright/support/pageobjects/exercises/AbstractExerciseCreationPage.ts New file added; introduces AbstractExerciseCreationPage with common form interaction methods (e.g., setTitle, date setters, clearText, waitForFormToLoad).
src/test/playwright/support/pageobjects/exercises/file-upload/FileUploadExerciseCreationPage.ts Now extends AbstractExerciseCreationPage; added methods for max points, file pattern, problem statement, example solution, assessment instructions, and create; removed date handling methods.
src/test/playwright/support/pageobjects/exercises/modeling/ModelingExerciseCreationPage.ts Renamed from CreateModelingExercisePage and updated to extend AbstractExerciseCreationPage; removed date-related methods.
src/test/playwright/support/pageobjects/exercises/programming/ProgrammingExerciseCreationPage.ts Modified to extend AbstractExerciseCreationPage with the constructor removed; maintains existing method functionality.
src/test/playwright/support/pageobjects/exercises/quiz/QuizExerciseCreationPage.ts Updated to extend AbstractExerciseCreationPage; removed constructor and adjusted imports, including dropping enterDate usage.
src/test/playwright/support/pageobjects/exercises/text/TextExerciseCreationPage.ts Updated to extend AbstractExerciseCreationPage; removed date setters and the clearText method, simplifying text exercise management.
src/test/playwright/e2e/exam/ExamManagement.spec.ts
src/test/playwright/e2e/exam/test-exam/TestExamManagement.spec.ts
src/test/playwright/e2e/exercise/text/TextExerciseManagement.spec.ts
Renamed method from typeTitle to setTitle in various exam and exercise management tests, ensuring consistent API usage.

Suggested labels

client, bugfix

Suggested reviewers

  • SimonEntholzer
  • florian-glombik
  • BBesrour
  • JohannesStoehr
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (6)
src/test/playwright/support/pageobjects/exercises/AbstractExerciseCreationPage.ts (1)

30-34: Efficient text clearing method.

Using “Control+a” could pose a cross-platform nuance (e.g., macOS might need “Command+a”). Consider verifying or adding a fallback if needed.

src/test/playwright/support/pageobjects/exercises/text/TextExerciseCreationPage.ts (1)

20-23: Consider extracting common text editor interaction logic.

The methods typeProblemStatement, typeExampleSolution, and typeAssessmentInstructions share similar text editor interaction patterns. Consider extracting this common logic into a protected method in the parent class.

+    protected async typeInEditor(selector: string, text: string) {
+        const textEditor = this.getTextEditorLocator(selector);
+        await this.typeText(textEditor, text);
+    }

-    async typeProblemStatement(statement: string) {
-        const textEditor = this.getTextEditorLocator(this.PROBLEM_STATEMENT_SELECTOR);
-        await this.typeText(textEditor, statement);
-    }
+    async typeProblemStatement(statement: string) {
+        await this.typeInEditor(this.PROBLEM_STATEMENT_SELECTOR, statement);
+    }

// Apply similar changes to typeExampleSolution and typeAssessmentInstructions

Also applies to: 30-33, 40-43

src/test/playwright/support/pageobjects/exercises/quiz/QuizExerciseCreationPage.ts (1)

65-69: Consider using Playwright's built-in drag and drop API.

The current implementation uses low-level mouse events which could be fragile. Playwright provides a more reliable built-in drag and drop API.

-        await this.page.mouse.move(boundingBox!.x + 800, boundingBox!.y + 10);
-        await this.page.mouse.down();
-        await this.page.mouse.move(boundingBox!.x + 1000, boundingBox!.y + 150);
-        await this.page.mouse.up();
+        await element.dragTo(element, {
+            targetPosition: { x: 1000, y: 150 },
+            sourcePosition: { x: 800, y: 10 }
+        });
src/test/playwright/support/pageobjects/exercises/programming/ProgrammingExerciseCreationPage.ts (2)

65-69: Consider using Playwright's waitForLoadState instead of fixed timeout.

The current implementation uses a fixed timeout which could be flaky. Consider using Playwright's built-in load state detection.

-            await this.page.locator('.owl-dt-control-content.owl-dt-control-button-content', { hasText: 'Set' }).dispatchEvent('click');
-            await this.page.waitForTimeout(500);
+            await this.page.locator('.owl-dt-control-content.owl-dt-control-button-content', { hasText: 'Set' }).click();
+            await this.page.waitForLoadState('networkidle');

77-94: Improve scroll detection with IntersectionObserver.

The current scroll detection implementation could be improved using IntersectionObserver for more reliable results.

     async waitForPageToFinishScrolling(maxTimeout: number = 5000) {
         const elementOnPageAffectedByScroll = this.page.locator('h2');
-        let isScrolling = true;
-        const startTime = Date.now();
-
-        while (isScrolling) {
-            const initialPosition = await elementOnPageAffectedByScroll.boundingBox();
-            await this.page.waitForTimeout(100); // give the page a short time to scroll
-            const newPosition = await elementOnPageAffectedByScroll.boundingBox();
-
-            isScrolling = initialPosition?.y !== newPosition?.y;
-
-            const isWaitingForScrollExceedingTimeout = Date.now() - startTime > maxTimeout;
-            if (isWaitingForScrollExceedingTimeout) {
-                throw new Error(`Aborting waiting for scroll end - page is still scrolling after ${maxTimeout}ms`);
-            }
-        }
+        await this.page.evaluate(
+            ([timeout]) => {
+                return new Promise((resolve, reject) => {
+                    let lastY = window.scrollY;
+                    const timer = setTimeout(() => reject(new Error(`Scroll timeout after ${timeout}ms`)), timeout);
+                    const observer = new IntersectionObserver(() => {
+                        if (window.scrollY === lastY) {
+                            clearTimeout(timer);
+                            observer.disconnect();
+                            resolve(true);
+                        }
+                        lastY = window.scrollY;
+                    });
+                    observer.observe(document.querySelector('h2')!);
+                });
+            },
+            [maxTimeout]
+        );
     }
src/test/playwright/e2e/exercise/ExerciseImport.spec.ts (1)

41-71: Consider adding negative test cases.

The test coverage could be enhanced by adding test cases for:

  • Import failures due to network issues
  • Form validation errors
  • Concurrent imports
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c8453c and ba77ee7.

📒 Files selected for processing (9)
  • src/test/playwright/e2e/exercise/ExerciseImport.spec.ts (4 hunks)
  • src/test/playwright/e2e/exercise/file-upload/FileUploadExerciseManagement.spec.ts (1 hunks)
  • src/test/playwright/support/fixtures.ts (3 hunks)
  • src/test/playwright/support/pageobjects/exercises/AbstractExerciseCreationPage.ts (1 hunks)
  • src/test/playwright/support/pageobjects/exercises/file-upload/FileUploadExerciseCreationPage.ts (1 hunks)
  • src/test/playwright/support/pageobjects/exercises/modeling/ModelingExerciseCreationPage.ts (1 hunks)
  • src/test/playwright/support/pageobjects/exercises/programming/ProgrammingExerciseCreationPage.ts (1 hunks)
  • src/test/playwright/support/pageobjects/exercises/quiz/QuizExerciseCreationPage.ts (1 hunks)
  • src/test/playwright/support/pageobjects/exercises/text/TextExerciseCreationPage.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: client-style
  • GitHub Check: server-style
  • GitHub Check: client-tests
  • GitHub Check: server-tests
  • GitHub Check: Analyse
🔇 Additional comments (17)
src/test/playwright/support/pageobjects/exercises/file-upload/FileUploadExerciseCreationPage.ts (2)

2-2: Good addition of the abstract page import.

Bringing in AbstractExerciseCreationPage promotes shared functionality and reduces duplication across exercise creation pages.


4-4: Extending the abstract page for better maintainability.

By inheriting from AbstractExerciseCreationPage, this class benefits from centralized methods (e.g., form handling), simplifying future code updates.

src/test/playwright/support/pageobjects/exercises/modeling/ModelingExerciseCreationPage.ts (2)

2-2: Importing the abstract page for standardization.

This ensures consistency with other exercise creation pages that also rely on shared logic from AbstractExerciseCreationPage.


4-4: Refactoring to extend the abstract page.

Extending AbstractExerciseCreationPage centralizes common form interactions and fosters code reuse across various exercise types.

src/test/playwright/support/pageobjects/exercises/AbstractExerciseCreationPage.ts (8)

1-3: Imports appear appropriate and concise.

Using @playwright/test, dayjs, and a local utility (enterDate) for date handling aligns well with the project’s E2E testing strategy.


5-7: Well-structured class declaration and dependency setup.

Declaring page as a protected property neatly encapsulates it while allowing subclasses to leverage shared functionality.


8-11: Constructor ensures a consistent page reference.

Accepting a Page object in the constructor and storing it for subclass use is a clean approach to page object design.


12-16: Robust title setter.

Clearing and then filling the title field avoids stale data, reducing risk of flaky tests. The flow is readable and straightforward.


18-20: Release date handling is properly encapsulated.

Relying on enterDate centralizes date-typing logic. Good approach to maintain consistency across multiple exercise creation flows.


22-24: Due date handling mirrors release date setting.

This parallel structure reduces confusion and makes test code easier to follow.


26-28: Assessment due date handling remains consistent.

Keeping the same approach for all date fields eliminates discrepancies in test logic.


36-38: Reliable form-load wait strategy.

Explicitly waiting for the edit form to become visible improves test stability, especially in slower or multi-node environments.

src/test/playwright/e2e/exercise/file-upload/FileUploadExerciseManagement.spec.ts (1)

27-27: LGTM!

The change from typeTitle to setTitle aligns with the standardized method naming across exercise creation pages.

src/test/playwright/support/pageobjects/exercises/quiz/QuizExerciseCreationPage.ts (1)

7-7: LGTM!

The inheritance from AbstractExerciseCreationPage appropriately centralizes common exercise creation functionality.

src/test/playwright/support/pageobjects/exercises/programming/ProgrammingExerciseCreationPage.ts (1)

8-8: LGTM!

The inheritance from AbstractExerciseCreationPage appropriately centralizes common exercise creation functionality.

src/test/playwright/e2e/exercise/ExerciseImport.spec.ts (1)

47-47: LGTM! Improved test reliability with form load synchronization.

The addition of waitForFormToLoad() calls before form validation is a great improvement. This ensures that the tests wait for the exercise information to be fully loaded before proceeding with assertions, addressing the flaky test issues in multi-node configurations.

Also applies to: 78-78, 105-105, 136-136

src/test/playwright/support/fixtures.ts (1)

40-40: LGTM! Consistent naming convention.

The renaming of CreateModelingExercisePage to ModelingExerciseCreationPage aligns with the naming convention used for other exercise creation pages in the codebase.

Also applies to: 118-118, 294-296

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/test/playwright/support/pageobjects/exercises/text/TextExerciseCreationPage.ts (2)

10-12: Consider using the inherited setPoints method.

For consistency with other exercise creation pages, consider using the inherited setPoints method instead of typeMaxPoints.

-    async typeMaxPoints(maxPoints: number) {
-        await this.page.locator('#field_points').fill(maxPoints.toString());
-    }

60-63: Consider using Playwright's fill method for text input.

Instead of using pressSequentially, consider using Playwright's fill method which is more reliable for text input.

-    private async typeText(textEditor: Locator, text: string) {
-        await textEditor.click();
-        await textEditor.pressSequentially(text);
-    }
+    private async typeText(textEditor: Locator, text: string) {
+        await textEditor.fill(text);
+    }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba77ee7 and e024411.

📒 Files selected for processing (4)
  • src/test/playwright/e2e/exam/ExamManagement.spec.ts (1 hunks)
  • src/test/playwright/e2e/exam/test-exam/TestExamManagement.spec.ts (1 hunks)
  • src/test/playwright/e2e/exercise/text/TextExerciseManagement.spec.ts (1 hunks)
  • src/test/playwright/support/pageobjects/exercises/text/TextExerciseCreationPage.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: server-tests
  • GitHub Check: server-style
  • GitHub Check: client-tests
  • GitHub Check: client-style
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyse
🔇 Additional comments (4)
src/test/playwright/support/pageobjects/exercises/text/TextExerciseCreationPage.ts (1)

1-5: LGTM! Good refactoring to use inheritance.

The class now extends AbstractExerciseCreationPage, which helps centralize common functionality and reduce code duplication.

src/test/playwright/e2e/exercise/text/TextExerciseManagement.spec.ts (1)

35-35: LGTM! Method name standardization.

The change from typeTitle to setTitle aligns with the standardized method naming across exercise creation pages.

src/test/playwright/e2e/exam/test-exam/TestExamManagement.spec.ts (1)

54-54: LGTM! Consistent method naming.

The changes from typeTitle to setTitle maintain consistency with the standardized method naming convention.

Also applies to: 80-81

src/test/playwright/e2e/exam/ExamManagement.spec.ts (1)

42-42: LGTM! Consistent method naming.

The change from typeTitle to setTitle maintains consistency with the standardized method naming convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

1 participant