feat: assert with openai model

This commit is contained in:
lilong.129
2025-04-29 22:03:11 +08:00
parent f6e421fc34
commit 429bfe3986
6 changed files with 58 additions and 57 deletions
+10 -11
View File
@@ -1,6 +1,7 @@
package ai
import (
"context"
"testing"
"github.com/httprunner/httprunner/v5/uixt/types"
@@ -8,16 +9,15 @@ import (
"github.com/stretchr/testify/require"
)
func createAIService(t *testing.T) *AIServices {
aiService := NewAIService(WithLLMService(LLMServiceTypeUITARS))
require.NotNil(t, aiService)
require.NotNil(t, aiService.ILLMService)
return aiService
func createAsserter(t *testing.T) *Asserter {
asserter, err := NewAsserter(context.Background(), LLMServiceTypeUITARS)
require.NoError(t, err)
return asserter
}
// 测试有效断言
func TestValidAssertions(t *testing.T) {
aiService := createAIService(t)
asserter := createAsserter(t)
testCases := []struct {
name string
@@ -33,7 +33,7 @@ func TestValidAssertions(t *testing.T) {
},
{
name: "深度思考功能未开启",
assertion: "输入框下方的「深度思考」文字是灰色的",
assertion: "输入框下方的「深度思考」文字不是蓝色的",
imagePath: "testdata/deepseek_think_off.png",
expectPass: true,
},
@@ -50,7 +50,7 @@ func TestValidAssertions(t *testing.T) {
imageBase64, size, err := loadImage(tc.imagePath)
require.NoError(t, err)
result, err := aiService.ILLMService.Assert(&AssertOptions{
result, err := asserter.Assert(&AssertOptions{
Assertion: tc.assertion,
Screenshot: imageBase64,
Size: size,
@@ -58,14 +58,13 @@ func TestValidAssertions(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, result)
assert.Equal(t, tc.expectPass, result.Pass)
assert.NotEmpty(t, result.Thought)
})
}
}
// 测试无效参数
func TestInvalidParameters(t *testing.T) {
aiService := createAIService(t)
asserter := createAsserter(t)
testCases := []struct {
name string
assertion string
@@ -91,7 +90,7 @@ func TestInvalidParameters(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
_, err := aiService.ILLMService.Assert(&AssertOptions{
_, err := asserter.Assert(&AssertOptions{
Assertion: tc.assertion,
Screenshot: tc.screenshot,
Size: tc.size,