mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-19 12:29:30 +08:00
fix: display ai assert in html report
This commit is contained in:
@@ -33,8 +33,9 @@ type AssertOptions struct {
|
||||
type AssertionResult struct {
|
||||
Pass bool `json:"pass"`
|
||||
Thought string `json:"thought"`
|
||||
ModelName string `json:"model_name"` // model name used for assertion
|
||||
Usage *schema.TokenUsage `json:"usage,omitempty"` // token usage statistics
|
||||
Content string `json:"content,omitempty"` // raw response content
|
||||
ModelName string `json:"model_name"` // model name used for assertion
|
||||
Usage *schema.TokenUsage `json:"usage,omitempty"` // token usage statistics
|
||||
}
|
||||
|
||||
// Asserter handles assertion using different AI models
|
||||
@@ -180,5 +181,6 @@ func parseAssertionResult(content string, modelType option.LLMServiceType) (*Ass
|
||||
}
|
||||
|
||||
result.ModelName = string(modelType)
|
||||
result.Content = content // Store the original response content
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
@@ -492,9 +492,10 @@ func (dExt *XTDriver) AIAssert(assertion string, opts ...option.ActionOption) (*
|
||||
return assertResult, errors.Wrap(err, "AI assertion failed")
|
||||
}
|
||||
|
||||
// For assertion failure, we should still return success but mark the assertion as failed
|
||||
// This ensures that the AIResult (including screenshot and thought) is properly saved and displayed
|
||||
if !result.Pass {
|
||||
assertResult.Error = result.Thought
|
||||
return assertResult, errors.New(result.Thought)
|
||||
assertResult.Error = result.Thought // Store the failure reason for reporting
|
||||
}
|
||||
|
||||
return assertResult, nil
|
||||
|
||||
@@ -65,8 +65,8 @@ func convertToAbsolutePoint(driver IDriver, x, y float64) (absX, absY float64, e
|
||||
}
|
||||
|
||||
func convertToAbsoluteCoordinates(driver IDriver, fromX, fromY, toX, toY float64) (
|
||||
absFromX, absFromY, absToX, absToY float64, err error) {
|
||||
|
||||
absFromX, absFromY, absToX, absToY float64, err error,
|
||||
) {
|
||||
// absolute coordinates
|
||||
if fromX > 1 || toX > 1 || fromY > 1 || toY > 1 {
|
||||
return fromX, fromY, toX, toY, nil
|
||||
@@ -190,32 +190,43 @@ func (dExt *XTDriver) assertSelector(selector, assert string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dExt *XTDriver) DoValidation(check, assert, expected string, message ...string) (err error) {
|
||||
func (dExt *XTDriver) DoValidation(check, assert, expected string, message ...string) (aiResult *AIExecutionResult, err error) {
|
||||
switch check {
|
||||
case option.SelectorOCR:
|
||||
err = dExt.assertOCR(expected, assert)
|
||||
case option.SelectorAI:
|
||||
_, err = dExt.AIAssert(expected)
|
||||
aiResult, err = dExt.AIAssert(expected)
|
||||
case option.SelectorForegroundApp:
|
||||
err = dExt.assertForegroundApp(expected, assert)
|
||||
case option.SelectorSelector:
|
||||
err = dExt.assertSelector(expected, assert)
|
||||
default:
|
||||
return fmt.Errorf("validator %s not implemented", check)
|
||||
return nil, fmt.Errorf("validator %s not implemented", check)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// Technical error (not assertion failure)
|
||||
if message == nil {
|
||||
message = []string{""}
|
||||
}
|
||||
log.Error().Err(err).Str("assert", assert).Str("expect", expected).
|
||||
Str("msg", message[0]).Msg("validate failed")
|
||||
return err
|
||||
return nil, err
|
||||
} else if aiResult != nil {
|
||||
// Check assertion result instead of relying on error
|
||||
if !aiResult.AssertionResult.Pass {
|
||||
return aiResult, errors.New(aiResult.AssertionResult.Thought)
|
||||
}
|
||||
log.Info().Str("check", check).Str("assert", assert).
|
||||
Str("expect", expected).
|
||||
Interface("ai_assertion_result", aiResult.AssertionResult).
|
||||
Msg("ai assertion passed")
|
||||
return aiResult, nil
|
||||
} else {
|
||||
log.Info().Str("check", check).Str("assert", assert).
|
||||
Str("expect", expected).Msg("validate success")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
log.Info().Str("check", check).Str("assert", assert).
|
||||
Str("expect", expected).Msg("validate success")
|
||||
return nil
|
||||
}
|
||||
|
||||
type SleepConfig struct {
|
||||
|
||||
Reference in New Issue
Block a user