//go:build localtest package uixt import ( "context" "os" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/httprunner/httprunner/v5/uixt/option" "github.com/httprunner/httprunner/v5/uixt/types" ) func setupADBDriverExt(t *testing.T) *XTDriver { config := DriverCacheConfig{ Platform: "android", Serial: "", // Let it auto-detect the device serial AIOptions: []option.AIServiceOption{ option.WithCVService(option.CVServiceTypeVEDEM), option.WithLLMConfig( option.NewLLMServiceConfig(option.DOUBAO_1_5_UI_TARS_250328). WithPlannerModel(option.WINGS_SERVICE). WithAsserterModel(option.WINGS_SERVICE), ), }, } driverExt, err := GetOrCreateXTDriver(config) require.Nil(t, err) return driverExt } func setupUIA2DriverExt(t *testing.T) *XTDriver { // Use cache mechanism with UIA2 enabled deviceOpts := option.NewDeviceOptions( option.WithPlatform("android"), option.WithDeviceUIA2(true), option.WithDeviceLogOn(false), ) config := DriverCacheConfig{ Platform: "android", Serial: "", // Let it auto-detect the device serial DeviceOpts: deviceOpts, AIOptions: []option.AIServiceOption{ option.WithCVService(option.CVServiceTypeVEDEM), option.WithLLMConfig( option.NewLLMServiceConfig(option.DOUBAO_1_5_UI_TARS_250328). WithPlannerModel(option.WINGS_SERVICE). WithAsserterModel(option.WINGS_SERVICE), ), }, } driverExt, err := GetOrCreateXTDriver(config) require.Nil(t, err) return driverExt } func TestDevice_Android_GetPackageInfo(t *testing.T) { driver := setupADBDriverExt(t) appInfo, err := driver.GetDevice().GetPackageInfo("com.android.settings") require.Nil(t, err) t.Log(appInfo) assert.Equal(t, "com.android.settings", appInfo.Name) assert.NotEmpty(t, appInfo.AppPath) assert.NotEmpty(t, appInfo.AppMD5) } func TestDevice_Android_GetCurrentWindow(t *testing.T) { driver := setupADBDriverExt(t) driver.AppLaunch("com.android.settings") windowInfo, err := driver.GetDevice().(*AndroidDevice).GetCurrentWindow() require.Nil(t, err) assert.Equal(t, "com.android.settings", windowInfo.PackageName) } func TestDriver_ADB_Session_TODO(t *testing.T) { driver := setupADBDriverExt(t) err := driver.InitSession(nil) require.Nil(t, err) err = driver.DeleteSession() assert.Nil(t, err) } func TestDriver_ADB_Status_TODO(t *testing.T) { driver := setupADBDriverExt(t) status, err := driver.Status() require.Nil(t, err) t.Log(status) } func TestDriver_ADB_ScreenShot(t *testing.T) { driver := setupADBDriverExt(t) screenshot, err := driver.ScreenShot() assert.Nil(t, err) path := "1234.jpeg" err = saveScreenShot(screenshot, path) require.Nil(t, err) defer os.Remove(path) t.Logf("save screenshot to %s", path) } func TestDriver_ADB_Rotation_TODO(t *testing.T) { driver := setupADBDriverExt(t) rotation, err := driver.Rotation() require.Nil(t, err) t.Logf("x = %d\ty = %d\tz = %d", rotation.X, rotation.Y, rotation.Z) } func TestDriver_ADB_DeviceSize(t *testing.T) { driver := setupADBDriverExt(t) deviceSize, err := driver.WindowSize() require.Nil(t, err) assert.Greater(t, deviceSize.Width, 200) assert.Greater(t, deviceSize.Height, 200) } func TestDriver_ADB_Source(t *testing.T) { driver := setupADBDriverExt(t) source, err := driver.Source() require.Nil(t, err) assert.Contains(t, source, "