From 3edbf3fb26b45a63a9252cc829e493a78e8bc6d1 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sat, 18 Jul 2026 18:38:04 +0300 Subject: [PATCH] fix: correct Reddit login selectors and detect network-level blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Live verification against a real Reddit login page (from this dev sandbox) showed: - The actual submit button has no [type="submit"] attribute; its accessible name is "Log In" — switched to getByRole with that name. - Username/password fields are better targeted via their visible labels (getByLabel) than brittle name= attribute selectors. - A cookie-consent dialog can overlay the form and intercept clicks; it's now dismissed via "Reject Optional Cookies" before filling in. - This sandbox's network is flagged by Reddit's bot detection with a "blocked by network security" interstitial before the login form even loads — this is unrelated to credentials and unrelated to the target account (confirmed reachable fine from a residential network/browser). Added explicit detection for this state so it reports a clear, distinguishable error instead of a generic CAPTCHA/2FA guess. Full live end-to-end verification (successful login + post creation) must be run from a network Reddit does not block, e.g. the mini PC this app actually runs on. Co-Authored-By: Claude Sonnet 5 --- .../reddit-post/tests/reddit-post.spec.js | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/sidecars/reddit-post/tests/reddit-post.spec.js b/sidecars/reddit-post/tests/reddit-post.spec.js index f540bc6..5a396db 100644 --- a/sidecars/reddit-post/tests/reddit-post.spec.js +++ b/sidecars/reddit-post/tests/reddit-post.spec.js @@ -42,16 +42,41 @@ test.describe('reddit post', () => { try { await page.goto('https://www.reddit.com/login/'); - await page.fill('input[name="username"]', /** @type {string} */ (username)); - await page.fill('input[name="password"]', /** @type {string} */ (password)); - await page.click('button[type="submit"]'); + const blockedHeading = page.getByText(/blocked by network security/i); + if (await blockedHeading.isVisible({ timeout: 3_000 }).catch(() => false)) { + outcome = { + success: false, + error: 'Reddit blocked this request at the network level ("blocked by network security") before login could be attempted — this is not a credentials or selector issue, it means the current network/IP is being flagged as automation by Reddit', + }; + outcomeFinalized = true; + throw new Error(outcome.error); + } + + const rejectCookies = page.getByRole('button', { name: 'Reject Optional Cookies' }); + if (await rejectCookies.isVisible({ timeout: 5_000 }).catch(() => false)) { + await rejectCookies.click(); + } + + const usernameField = page.getByLabel(/email or username/i); + await usernameField.click(); + await usernameField.fill(/** @type {string} */ (username)); + + const passwordField = page.getByLabel(/^password/i); + await passwordField.click(); + await passwordField.fill(/** @type {string} */ (password)); + + await page.getByRole('button', { name: 'Log In' }).click(); try { await expect(page.locator('span[name="avatar"], #USER_DROPDOWN_ID, [icon-name="account-circle-outline"]').first()).toBeVisible({ timeout: 20_000 }); } catch { + const loginErrorBanner = page.getByText(/something went wrong logging in|invalid username|invalid password/i); + const bannerText = await loginErrorBanner.first().textContent().catch(() => null); outcome = { success: false, - error: 'Login did not complete — possible CAPTCHA, 2FA prompt, or invalid credentials', + error: bannerText + ? `Login failed: ${bannerText.trim()}` + : 'Login did not complete — possible CAPTCHA, 2FA prompt, or invalid credentials', }; outcomeFinalized = true; throw new Error(outcome.error);