Skip to content

[ENHANCEMENT] [MER-5850] Add parameterized OAuth login Playwright tests - #6764

Open
manelli wants to merge 4 commits into
masterfrom
MER-5850/automation-tests/oauth-login
Open

[ENHANCEMENT] [MER-5850] Add parameterized OAuth login Playwright tests#6764
manelli wants to merge 4 commits into
masterfrom
MER-5850/automation-tests/oauth-login

Conversation

@manelli

@manelli manelli commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds fully parameterized Playwright smoke tests for Google OAuth login across Torus account classes and deployment environments.

The suite covers:

  • Learner login through /users/log_in
  • Author login through /authors/log_in
  • Redirect to Google authorization
  • Successful callback to Torus without an OAuth error
  • Verification of the signed-in account using its email address
  • Correct learner or author workspace
  • Session persistence after reload
  • Logout and return to the public/login state

Implementation

  • Adds one parameterized test case for each account class: learner and author.
  • Reads only environment-specific values from the YAML selected by PLAYWRIGHT_PARAMETER_CONFIG_URL:
    • Torus base URL
    • Operation timeout
    • Dedicated learner credentials
    • Dedicated author credentials
    • Optional author account label
  • Keeps stable Google selectors, Torus routes, and expected workspace copy in the test code.
  • Verifies the exact signed-in email from the Torus account settings page.
  • Uses resilient helpers for the cookie modal and LiveView account menu.
  • Gives the complete test three times the configured per-operation timeout.
  • Runs headed Chrome because Google may reject automated headless authentication.
  • Disables tracing to avoid storing credentials, session cookies, and OAuth response data.
  • Validates runtime configuration and rejects placeholder values before attempting login.
  • Adds npm run test-oauth-logins, which selects the suite using the @oauth tag.

Full configuration documentation is in assets/automation/README.md.

Runtime configuration

target:
  base_url: https://torus.example.test
tests:
  oauth_logins:
    timeout_ms: 120000
    accounts:
      learner:
        email: REPLACE_WITH_LEARNER_GOOGLE_EMAIL
        password: REPLACE_WITH_LEARNER_GOOGLE_PASSWORD
      author:
        email: REPLACE_WITH_AUTHOR_GOOGLE_EMAIL
        password: REPLACE_WITH_AUTHOR_GOOGLE_PASSWORD
        account_label: Author

Do not commit real credentials or the runtime YAML.

Prerequisites

Each target environment requires:

  • Google OAuth enabled in Torus.
  • One dedicated learner Google account.
  • One dedicated author Google account.
  • Accounts without MFA, CAPTCHA, recovery, or other interactive challenges.
  • The Google identities linked to the correct Torus account class.
  • A private YAML configuration containing the account credentials and target URL.

Install the automation dependencies once from the repository root:

cd assets/automation
npm install
npx playwright install --with-deps chrome

Testing locally

  1. Configure a Google OAuth web client with these authorized redirect URIs:

    http://localhost/users/auth/google/callback
    http://localhost/authors/auth/google/callback
    
  2. Start or restart Torus with GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET set.

  3. Log in manually once with each dedicated account:

    • Learner: http://localhost/users/log_in
    • Author: http://localhost/authors/log_in

    This creates and links the corresponding Torus learner and author records.

  4. Save the runtime configuration as /tmp/oauth-local.yaml, set the base URL to http://localhost, and replace all credential placeholders.

  5. Serve the configuration from a separate terminal:

    python3 -m http.server 8787 --bind 127.0.0.1 --directory /tmp
  6. From assets/automation, run:

    PLAYWRIGHT_PARAMETER_CONFIG_URL=http://127.0.0.1:8787/oauth-local.yaml npm run test-oauth-logins

Testing Tokamak

Use dedicated Google accounts already linked to the correct account classes in Tokamak.

Set the YAML target to:

target:
  base_url: https://tokamak.oli.cmu.edu

Then run from assets/automation:

PLAYWRIGHT_PARAMETER_CONFIG_URL=http://127.0.0.1:8787/oauth-tokamak.yaml npm run test-oauth-logins

Testing Stellarator

Use dedicated Google accounts already linked to the correct account classes in Stellarator.

Set the YAML target to:

target:
  base_url: https://stellarator.oli.cmu.edu

Then run from assets/automation:

PLAYWRIGHT_PARAMETER_CONFIG_URL=http://127.0.0.1:8787/oauth-stellarator.yaml npm run test-oauth-logins

The same procedure can target another staging or production deployment by changing target.base_url and supplying dedicated accounts linked in that environment. A real Chrome window opens and runs both account-class flows.

Verification

  • Prettier passes for the changed files.
  • ESLint passes for the OAuth test files.
  • Playwright discovers both parameterized cases:
    • Learner OAuth login
    • Author OAuth login

See: https://eliterate.atlassian.net/browse/MER-5850

@manelli
manelli marked this pull request as ready for review August 6, 2026 21:30
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Risk score: 3 → risk/low

Generated by 🚫 dangerJS against 75a9c95

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

AI Review —

No issues found

@nicocirio nicocirio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I ran this suite against Tokamak using two of my own Google accounts (one per account class). After applying the fixes noted in the comments below, both the learner and author cases pass end-to-end.

Image

Comment thread assets/automation/tests/torus/oauth_login/support/oauthLoginConfig.ts Outdated
Comment thread assets/automation/README.md Outdated
Comment thread assets/automation/tests/torus/oauth_login/oauth-login.spec.ts Outdated
Comment thread assets/automation/package.json Outdated
Comment thread assets/automation/README.md Outdated
Comment thread assets/automation/tests/torus/oauth_login/support/oauthLogin.ts
Comment thread assets/automation/tests/torus/oauth_login/support/oauthLogin.ts
Comment thread assets/automation/tests/torus/oauth_login/oauth-login.spec.ts Outdated
Comment thread assets/automation/tests/torus/oauth_login/oauth-login.spec.ts Outdated
Comment thread assets/automation/tests/torus/oauth_login/oauth-login.spec.ts Outdated
@manelli

manelli commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @nicocirio for the reviews! I implemented them in 6f991fe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants