diff --git a/probes/http/http_probe.go b/probes/http/http_probe.go index 228882757a393d7bc27d7ecd432bcc947a7ca2b4..e18b07810f9c998ba42d2815eb2439d6fe564332 100644 --- a/probes/http/http_probe.go +++ b/probes/http/http_probe.go @@ -61,6 +61,7 @@ func (p *httpProbe) RunProbe(ctx context.Context, debug *log.Logger) error { if err := http.CheckStep(ctx, browser, step, debug); err != nil { err = fmt.Errorf("step %s failed: %w", stepName, err) debug.Printf("%v", err) + browser.Dump(debug) return err } } diff --git a/protocol/http/http.go b/protocol/http/http.go index 9839297e1bcfa4892dbd9c0d9bd430ccb9a87fab..9814ce24e6c02a03c5bb7b706df74765b6b550a7 100644 --- a/protocol/http/http.go +++ b/protocol/http/http.go @@ -225,3 +225,13 @@ func (b *Browser) SubmitForm(ctx context.Context, formSelector string, moreValue Args: values, }) } + +func (b *Browser) Dump(l *log.Logger) { + if b.lastResponse == nil { + return + } + + l.Printf("[browser state] URL=%s", b.lastResponse.URL.String()) + l.Printf("[browser state] status=%d", b.lastResponse.StatusCode) + l.Printf("[browser state] body:\n%s", b.lastResponse.Body) +} diff --git a/protocol/http/step.go b/protocol/http/step.go index 1e1d7be5e80e61daceef513781ed2159216ac9e1..09c2db8c9011555c85fd429cd3105de45e0afd48 100644 --- a/protocol/http/step.go +++ b/protocol/http/step.go @@ -61,11 +61,9 @@ func CheckStep(ctx context.Context, b *Browser, step *Step, debug *log.Logger) e } if step.ExpectedURL.IsSet() && !step.ExpectedURL.MatchString(resp.URL.String()) { - debug.Printf("response body:\n%s", resp.Body) return fmt.Errorf("expected URL %s, got %s instead", step.ExpectedURL.String(), resp.URL.String()) } if step.ExpectedData.IsSet() && !step.ExpectedData.MatchString(resp.Body) { - debug.Printf("response body:\n%s", resp.Body) return fmt.Errorf("page body at %s does not match expected regexp %s", resp.URL.String(), step.ExpectedData.String()) } return nil