Skip to content

Conversation

NikkiAung
Copy link

@NikkiAung NikkiAung commented Jul 15, 2025

Introduce optimized login() utility for Playwright crawler with captcha support

Adds a new login() utility function to the Playwright crawler that automatically handles website login forms, including optional captcha solving.

  • Supports both one-step and two-step login flows.
  • Allows custom locators and login success detection.
  • Supports optional captcha handler with timeout.
  • Optimized and refactored for robustness:
    • Clear error messages for all field interactions and button clicks.
    • Helper functions for field filling and captcha handling reduce code duplication.
    • Captcha handler is safely wrapped with timeout and error propagation.
    • Debug logging for each major login step.
    • Comprehensive test coverage for all scenarios, including captcha errors and timeouts.
async requestHandler({ login }) {
    await login({
        username: 'your-username',
        password: 'your-password',
        handleCaptcha: async (page) => {
            // Solve captcha here
        },
        captchaTimeoutMs: 20000,
        locators: {
            getUsernameInput: (page) => page.locator('#username'),
            getPasswordInput: (page) => page.locator('#password'),
            getSubmitButton: (page) => page.getByText('submit'),
            getNextButton: (page) => page.getByText('next'),
        },
        detectLoginSuccess: async (page) => {
            return page.locator('.user-menu').isVisible();
        },
        timeoutMs: 15_000,
    });
}

Resolves full features for Playwright #3040

@NikkiAung NikkiAung changed the title Feature: Robust Playwright Login Helper with Captcha Support feat: add robust playwright login helper with captcha support #3040 Jul 15, 2025
@NikkiAung NikkiAung changed the title feat: add robust playwright login helper with captcha support #3040 feat: add robust playwright login helper with captcha support Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant