Skip to content
Snippets Groups Projects
Commit 13993926 authored by ale's avatar ale
Browse files

Always dump browser state on http probe errors

parent 420149ac
No related branches found
No related tags found
No related merge requests found
Pipeline #57999 passed
...@@ -61,6 +61,7 @@ func (p *httpProbe) RunProbe(ctx context.Context, debug *log.Logger) error { ...@@ -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 { if err := http.CheckStep(ctx, browser, step, debug); err != nil {
err = fmt.Errorf("step %s failed: %w", stepName, err) err = fmt.Errorf("step %s failed: %w", stepName, err)
debug.Printf("%v", err) debug.Printf("%v", err)
browser.Dump(debug)
return err return err
} }
} }
......
...@@ -225,3 +225,13 @@ func (b *Browser) SubmitForm(ctx context.Context, formSelector string, moreValue ...@@ -225,3 +225,13 @@ func (b *Browser) SubmitForm(ctx context.Context, formSelector string, moreValue
Args: values, 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)
}
...@@ -61,11 +61,9 @@ func CheckStep(ctx context.Context, b *Browser, step *Step, debug *log.Logger) e ...@@ -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()) { 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()) return fmt.Errorf("expected URL %s, got %s instead", step.ExpectedURL.String(), resp.URL.String())
} }
if step.ExpectedData.IsSet() && !step.ExpectedData.MatchString(resp.Body) { 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 fmt.Errorf("page body at %s does not match expected regexp %s", resp.URL.String(), step.ExpectedData.String())
} }
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment