This commit is contained in:
张开元
2025-08-06 15:15:28 +08:00
parent 0b11c5491f
commit 721ed38c4c
7 changed files with 549 additions and 84 deletions
+29 -83
View File
@@ -66,7 +66,6 @@ func ParseTouchEvents(data string) ([]types.TouchEvent, error) {
if event.Action, err = strconv.Atoi(parts[12]); err != nil {
return nil, fmt.Errorf("invalid action: %v", err)
}
events = append(events, event)
}
@@ -74,14 +73,14 @@ func ParseTouchEvents(data string) ([]types.TouchEvent, error) {
}
func TestAndroidTouchByEvents(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
device, err := NewIOSDevice(
option.WithUDID(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
driver, err := NewWDADriver(device)
if err != nil {
t.Fatal(err)
}
@@ -142,28 +141,10 @@ func TestIOSTouchByEvents(t *testing.T) {
driver := setupWDADriverExt(t)
// Example touch event data as provided
touchEventData := `1752649131556,401.20703,1191.3164,2,1.0,0.03529412,457.20703,1359.3164,111586196,111586196,1,0,0
1752649131595,402.913,1185.0792,2,1.0,0.039215688,458.913,1353.0792,111586196,111586236,1,0,2
1752649131612,410.60825,1164.3806,2,1.0,0.03529412,466.60825,1332.3806,111586196,111586250,1,0,2
1752649131629,437.7335,1093.1417,2,1.0,0.039215688,493.7335,1261.1417,111586196,111586270,1,0,2
1752649131646,463.5786,1018.01746,2,1.0,0.039215688,519.5786,1186.0175,111586196,111586287,1,0,2
1752649131662,487.56482,948.9773,2,1.0,0.03529412,543.5648,1116.9773,111586196,111586304,1,0,2
1752649131679,511.81476,881.6183,2,1.0,0.039215688,567.81476,1049.6183,111586196,111586320,1,0,2
1752649131696,543.4369,811.4982,2,1.0,0.03529412,599.4369,979.4982,111586196,111586337,1,0,2
1752649131713,577.1632,747.4512,2,1.0,0.039215688,633.1632,915.4512,111586196,111586354,1,0,2
1752649131729,610.1538,691.72034,2,1.0,0.03529412,666.1538,859.72034,111586196,111586370,1,0,2
1752649131746,639.1683,642.6914,2,1.0,0.03529412,695.1683,810.6914,111586196,111586387,1,0,2
1752649131763,658.9832,605.90857,2,1.0,0.03529412,714.9832,773.90857,111586196,111586404,1,0,2
1752649131779,672.21954,581.1634,2,1.0,0.03529412,728.21954,749.1634,111586196,111586420,1,0,2
1752649131796,680.7687,566.1778,2,1.0,0.03529412,736.7687,734.1778,111586196,111586434,1,0,2
1752649131814,688.0894,554.2295,2,1.0,0.03529412,744.0894,722.2295,111586196,111586450,1,0,2
1752649131830,694.542,544.7783,2,1.0,0.03529412,750.542,712.7783,111586196,111586466,1,0,2
1752649131847,700.60645,537.2637,2,1.0,0.039215688,756.60645,705.2637,111586196,111586483,1,0,2
1752649131863,705.08887,531.1406,2,1.0,0.039215688,761.08887,699.1406,111586196,111586500,1,0,2
1752649131880,708.1211,527.8008,2,1.0,0.039215688,764.1211,695.8008,111586196,111586517,1,0,2
1752649131897,709.43945,524.46094,2,1.0,0.039215688,765.43945,692.46094,111586196,111586533,1,0,2
1752649131902,709.1758,523.34766,2,1.0,0.03529412,765.1758,691.34766,111586196,111586537,1,33554432,2
1752649131907,709.1758,523.34766,2,1.0,0.03529412,765.1758,691.34766,111586196,111586546,1,0,1`
touchEventData := `1752649131556,401.20703,1191.3164,2,1.0,0.03529412,400.20703,400.3164,111586196,111586196,1,0,0
1752649131595,402.913,1185.0792,2,1.0,0.039215688,300.913,300.0792,111586196,111586236,1,0,2
1752649131612,410.60825,1164.3806,2,1.0,0.03529412,250.60825,250.3806,111586196,111586250,1,0,2
1752649131907,709.1758,523.34766,2,1.0,0.03529412,200.1758,200.34766,111586196,111586546,1,0,1`
// Parse touch events
events, err := ParseTouchEvents(touchEventData)
@@ -281,14 +262,14 @@ func TestTouchEventSequenceValidation(t *testing.T) {
}
func TestSwipeWithDirection(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
device, err := NewIOSDevice(
option.WithUDID(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
driver, err := NewWDADriver(device)
if err != nil {
t.Fatal(err)
}
@@ -308,7 +289,7 @@ func TestSwipeWithDirection(t *testing.T) {
direction: "up",
startX: 0.5,
startY: 0.5,
minDistance: 100.0,
minDistance: 500.0,
maxDistance: 500.0,
},
}
@@ -332,50 +313,15 @@ func TestSwipeWithDirection(t *testing.T) {
}
}
func TestSwipeWithDirectionInvalidInputs(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
if err != nil {
t.Fatal(err)
}
defer driver.TearDown()
// Test invalid direction
err = driver.SIMSwipeWithDirection("invalid", 500.0, 500.0, 100.0, 200.0)
if err == nil {
t.Error("Expected error for invalid direction, but got none")
}
// Test invalid distance range (max < min)
err = driver.SIMSwipeWithDirection("up", 500.0, 500.0, 200.0, 100.0)
if err == nil {
t.Error("Expected error for invalid distance range, but got none")
}
// Test zero distance
err = driver.SIMSwipeWithDirection("up", 500.0, 500.0, 0.0, 0.0)
if err == nil {
t.Error("Expected error for zero distance, but got none")
}
t.Log("Invalid input validation tests passed")
}
func TestSwipeInArea(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
device, err := NewIOSDevice(
option.WithUDID(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
driver, err := NewWDADriver(device)
if err != nil {
t.Fatal(err)
}
@@ -428,14 +374,14 @@ func TestSwipeInArea(t *testing.T) {
}
func TestSwipeFromPointToPoint(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
device, err := NewIOSDevice(
option.WithUDID(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
driver, err := NewWDADriver(device)
if err != nil {
t.Fatal(err)
}
@@ -477,14 +423,14 @@ func TestSwipeFromPointToPoint(t *testing.T) {
}
func TestSwipeFromPointToPointInvalidInputs(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
device, err := NewIOSDevice(
option.WithUDID(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
driver, err := NewWDADriver(device)
if err != nil {
t.Fatal(err)
}
@@ -506,14 +452,14 @@ func TestSwipeFromPointToPointInvalidInputs(t *testing.T) {
}
func TestClickAtPoint(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
device, err := NewIOSDevice(
option.WithUDID(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
driver, err := NewWDADriver(device)
if err != nil {
t.Fatal(err)
}
@@ -546,14 +492,14 @@ func TestClickAtPoint(t *testing.T) {
}
func TestClickAtPointInvalidInputs(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
device, err := NewIOSDevice(
option.WithUDID(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
driver, err := NewWDADriver(device)
if err != nil {
t.Fatal(err)
}
@@ -580,14 +526,14 @@ func TestClickAtPointInvalidInputs(t *testing.T) {
}
func TestSIMInput(t *testing.T) {
device, err := NewAndroidDevice(
option.WithSerialNumber(""),
device, err := NewIOSDevice(
option.WithUDID(""),
)
if err != nil {
t.Fatal(err)
}
driver, err := NewUIA2Driver(device)
driver, err := NewWDADriver(device)
if err != nil {
t.Fatal(err)
}