Files
openserp/testutil/ithelper/ithelper.go
Rustem Kamalov ecacfab4d6 Add integration tests for multiple search engines and enhance error handling
- Implement integration tests for Baidu, Bing, DuckDuckGo, Google, and Yandex.
- Refactor test utility functions to avoid core import cycles.
2026-04-14 02:05:58 +03:00

54 lines
1.3 KiB
Go

package ithelper
import (
"testing"
"time"
"github.com/karust/openserp/core"
"github.com/karust/openserp/testutil"
)
// HandleError skips on captcha/timeout (expected in live environments),
// fatals on other errors. In strict mode, captcha/timeout also fatal.
func HandleError(t *testing.T, operation string, err error) {
t.Helper()
if err == nil {
return
}
if err == core.ErrCaptcha {
t.Logf("captcha detected during %s: %v", operation, err)
if testutil.IntegrationStrict() {
t.Fatalf("%s failed (strict mode): %v", operation, err)
}
t.Skipf("skipping flaky live %s due to captcha: %v", operation, err)
}
if err == core.ErrSearchTimeout {
if testutil.IntegrationStrict() {
t.Fatalf("%s failed (strict mode): %v", operation, err)
}
t.Skipf("skipping flaky live %s due to timeout: %v", operation, err)
}
t.Fatalf("%s failed: %v", operation, err)
}
// CreateBrowser creates a browser configured for integration tests.
// Respects OPENSERP_INTEGRATION_HEADFUL for debugging.
func CreateBrowser(t *testing.T) *core.Browser {
t.Helper()
headful := testutil.IntegrationHeadful()
opts := core.BrowserOpts{
IsHeadless: !headful,
IsLeakless: false,
Timeout: time.Second * 15,
LeavePageOpen: headful,
}
b, err := core.NewBrowser(opts)
if err != nil {
t.Fatalf("failed to create test browser: %v", err)
}
return b
}