From 952c2dda02c966e9ced109b87c273f1808df25dd Mon Sep 17 00:00:00 2001 From: "Arik Jones (aider)" Date: Sat, 21 Sep 2024 16:01:51 -0500 Subject: [PATCH] refactor: update browser initialization in scraper tests --- internal/scraper/scraper.go | 10 ++++++++++ internal/scraper/scraper_test.go | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/scraper/scraper.go b/internal/scraper/scraper.go index 91b1399..f7c5c2c 100644 --- a/internal/scraper/scraper.go +++ b/internal/scraper/scraper.go @@ -339,6 +339,16 @@ func ClosePlaywright() { } } +// InitBrowser initializes the browser +func InitBrowser() error { + return InitPlaywright() +} + +// CloseBrowser closes the browser +func CloseBrowser() { + ClosePlaywright() +} + // FetchWebpageContent retrieves the content of a webpage using Playwright func FetchWebpageContent(urlStr string) (string, error) { logger.Printf("Fetching webpage content for URL: %s\n", urlStr) diff --git a/internal/scraper/scraper_test.go b/internal/scraper/scraper_test.go index b7417c1..4d7b0a5 100644 --- a/internal/scraper/scraper_test.go +++ b/internal/scraper/scraper_test.go @@ -144,11 +144,11 @@ This is a **test** paragraph. } func TestExtractLinks(t *testing.T) { - // Initialize the browser before running the test - if err := InitBrowser(); err != nil { - t.Fatalf("Failed to initialize browser: %v", err) + // Initialize Playwright before running the test + if err := InitPlaywright(); err != nil { + t.Fatalf("Failed to initialize Playwright: %v", err) } - defer CloseBrowser() + defer ClosePlaywright() server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html")