From b16fff870056a3541f051edde7f91c0f9461bba8 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Sun, 7 Jun 2026 14:08:40 +0100 Subject: [PATCH] test(e2e): playwright browser harness against 2captcha demo --- Makefile | 11 +- test/e2e/browser_test.go | 95 +++++++++ test/e2e/playwright/solve-recaptcha-v2.mjs | 222 +++++++++++++++++++++ test/e2e/playwright/solve-text.mjs | 149 ++++++++++++++ 4 files changed, 476 insertions(+), 1 deletion(-) create mode 100644 test/e2e/browser_test.go create mode 100644 test/e2e/playwright/solve-recaptcha-v2.mjs create mode 100644 test/e2e/playwright/solve-text.mjs diff --git a/Makefile b/Makefile index 0d66663..de2b322 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build test e2e e2e-live lint tidy +.PHONY: build test e2e e2e-live e2e-browser lint tidy build: go build -o bin/captcha-solver-mcp ./cmd/captcha-solver-mcp test: @@ -7,6 +7,15 @@ e2e: go test -tags e2e ./test/e2e/... e2e-live: CAPTCHA_E2E_LIVE=1 go test -tags e2e,live ./test/e2e/... +# Live browser e2e against the 2captcha demo (network + Chromium required). +# Prereqs: npm install && npx playwright install chromium +e2e-browser: + CAPTCHA_E2E_LIVE=1 \ + CAPTCHA_LLM_PROVIDER=openai-compatible \ + CAPTCHA_LLM_BASE_URL=https://llmgw.h.raczylo.com \ + CAPTCHA_LLM_MODEL=openai/gpt-5.4 \ + CAPTCHA_LLM_TIMEOUT=120s \ + go test -tags 'e2e live' -run Browser -v ./test/e2e/... lint: golangci-lint run tidy: diff --git a/test/e2e/browser_test.go b/test/e2e/browser_test.go new file mode 100644 index 0000000..3b6a538 --- /dev/null +++ b/test/e2e/browser_test.go @@ -0,0 +1,95 @@ +//go:build e2e && live + +package e2e + +import ( + "os" + "os/exec" + "path/filepath" + "testing" + "time" +) + +// runBrowserScript shells out to a Playwright .mjs harness under test/e2e/playwright. +// It gates on CAPTCHA_E2E_LIVE=1, requires `node` and an installed Playwright Chromium, +// inherits the ambient CAPTCHA_LLM_* gateway config, and asserts a clean (exit 0) run. +func runBrowserScript(t *testing.T, script string) { + t.Helper() + + if os.Getenv("CAPTCHA_E2E_LIVE") != "1" { + t.Skip("CAPTCHA_E2E_LIVE != 1; skipping live browser e2e") + } + if os.Getenv("CAPTCHA_LLM_PROVIDER") == "" || os.Getenv("CAPTCHA_LLM_MODEL") == "" { + t.Skip("CAPTCHA_LLM_PROVIDER / CAPTCHA_LLM_MODEL not set; skipping live browser e2e") + } + if _, err := exec.LookPath("node"); err != nil { + t.Skip("node not found on PATH; skipping live browser e2e") + } + if !chromiumInstalled() { + t.Skip("Playwright Chromium not installed (run: npx playwright install chromium); skipping") + } + + // cwd is test/e2e so the script path "playwright/