Skip to content

Commit b6a669e

Browse files
committed
fix running wda on ios 14..16
1 parent ee5dc73 commit b6a669e

File tree

2 files changed

+69
-40
lines changed

2 files changed

+69
-40
lines changed

ios/testmanagerd/xcuitestrunner.go

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -289,35 +289,11 @@ func runXUITestWithBundleIdsXcode15Ctx(
289289
}
290290
defer conn2.Close()
291291

292-
installationProxy, err := installationproxy.New(config.Device)
293-
if err != nil {
294-
return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot connect to installation proxy: %w", err)
295-
}
296-
defer installationProxy.Close()
297-
apps, err := installationProxy.BrowseUserApps()
298-
if err != nil {
299-
return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot browse user apps: %w", err)
300-
}
301-
302-
testAppInfo, err := getappInfo(config.TestRunnerBundleId, apps)
292+
testSessionID := uuid.New()
293+
info, err := getTestInfo(config.Device, config.BundleId, config.TestRunnerBundleId)
303294
if err != nil {
304-
return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot get test app information: %w", err)
295+
return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot build test info: %w", err)
305296
}
306-
307-
info := testInfo{
308-
testApp: testAppInfo,
309-
}
310-
311-
if config.BundleId != "" {
312-
appInfo, err := getappInfo(config.BundleId, apps)
313-
if err != nil {
314-
return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot get app information: %w", err)
315-
}
316-
317-
info.targetApp = appInfo
318-
}
319-
320-
testSessionID := uuid.New()
321297
testconfig := createTestConfig(info, testSessionID, config.XctestConfigName, config.TestsToRun, config.TestsToSkip, config.XcTest, version)
322298
ideDaemonProxy1 := newDtxProxyWithConfig(conn1, testconfig, config.Listener)
323299

@@ -483,22 +459,21 @@ func startTestRunner17(appserviceConn *appservice.Connection, bundleID string, s
483459
return appLaunch, nil
484460
}
485461

486-
func setupXcuiTest(device ios.DeviceEntry, bundleID string, testRunnerBundleID string, xctestConfigFileName string, testsToRun []string, testsToSkip []string, isXCTest bool, version *semver.Version) (uuid.UUID, string, nskeyedarchiver.XCTestConfiguration, testInfo, error) {
487-
testSessionID := uuid.New()
462+
func getTestInfo(device ios.DeviceEntry, bundleID string, testRunnerBundleID string) (testInfo, error) {
488463
installationProxy, err := installationproxy.New(device)
489464
if err != nil {
490-
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
465+
return testInfo{}, fmt.Errorf("cannot connect to installation proxy: %w", err)
491466
}
492467
defer installationProxy.Close()
493468

494469
apps, err := installationProxy.BrowseUserApps()
495470
if err != nil {
496-
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
471+
return testInfo{}, fmt.Errorf("cannot browse user apps: %w", err)
497472
}
498473

499474
testAppInfo, err := getappInfo(testRunnerBundleID, apps)
500475
if err != nil {
501-
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
476+
return testInfo{}, fmt.Errorf("cannot get test app information: %w", err)
502477
}
503478

504479
info := testInfo{
@@ -508,19 +483,32 @@ func setupXcuiTest(device ios.DeviceEntry, bundleID string, testRunnerBundleID s
508483
if bundleID != "" {
509484
appInfo, err := getappInfo(bundleID, apps)
510485
if err != nil {
511-
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
486+
return testInfo{}, fmt.Errorf("cannot get app information: %w", err)
512487
}
513488
log.Debugf("app info found: %+v", appInfo)
514489

515490
info.targetApp = appInfo
516491
}
517492

493+
return info, nil
494+
}
495+
496+
func setupXcuiTest(device ios.DeviceEntry, bundleID string, testRunnerBundleID string, xctestConfigFileName string, testsToRun []string,
497+
testsToSkip []string, isXCTest bool, version *semver.Version,
498+
) (uuid.UUID, string, nskeyedarchiver.XCTestConfiguration, testInfo, error) {
499+
info, err := getTestInfo(device, bundleID, testRunnerBundleID)
500+
if err != nil {
501+
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
502+
}
503+
518504
houseArrestService, err := house_arrest.New(device, testRunnerBundleID)
519-
defer houseArrestService.Close()
520505
if err != nil {
521506
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
522507
}
508+
defer houseArrestService.Close()
509+
523510
log.Debugf("creating test config")
511+
testSessionID := uuid.New()
524512
testConfigPath, testConfig, err := createTestConfigOnDevice(testSessionID, info, houseArrestService, xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version)
525513
if err != nil {
526514
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
@@ -529,6 +517,44 @@ func setupXcuiTest(device ios.DeviceEntry, bundleID string, testRunnerBundleID s
529517
return testSessionID, testConfigPath, testConfig, info, nil
530518
}
531519

520+
func setupXcuiTest12(device ios.DeviceEntry, bundleID string, testRunnerBundleID string, xctestConfigFileName string, testsToRun []string, testsToSkip []string, isXCTest bool, version *semver.Version) (uuid.UUID, nskeyedarchiver.XCTestConfiguration, testInfo, error) {
521+
testSessionID := uuid.New()
522+
installationProxy, err := installationproxy.New(device)
523+
if err != nil {
524+
return uuid.UUID{}, nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
525+
}
526+
defer installationProxy.Close()
527+
528+
apps, err := installationProxy.BrowseUserApps()
529+
if err != nil {
530+
return uuid.UUID{}, nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
531+
}
532+
533+
testAppInfo, err := getappInfo(testRunnerBundleID, apps)
534+
if err != nil {
535+
return uuid.UUID{}, nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
536+
}
537+
538+
info := testInfo{
539+
testApp: testAppInfo,
540+
}
541+
542+
if bundleID != "" {
543+
appInfo, err := getappInfo(bundleID, apps)
544+
if err != nil {
545+
return uuid.UUID{}, nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
546+
}
547+
log.Debugf("app info found: %+v", appInfo)
548+
549+
info.targetApp = appInfo
550+
}
551+
552+
log.Debugf("creating test config")
553+
testConfig := createTestConfig(info, testSessionID, xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version)
554+
555+
return testSessionID, testConfig, info, nil
556+
}
557+
532558
func createTestConfigOnDevice(testSessionID uuid.UUID, info testInfo, houseArrestService *house_arrest.Connection, xctestConfigFileName string, testsToRun []string, testsToSkip []string, isXCTest bool, version *semver.Version) (string, nskeyedarchiver.XCTestConfiguration, error) {
533559
relativeXcTestConfigPath := path.Join("tmp", testSessionID.String()+".xctestconfiguration")
534560
xctestConfigPath := path.Join(info.testApp.homePath, relativeXcTestConfigPath)

ios/testmanagerd/xcuitestrunner_12.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
1111
"github.com/danielpaulus/go-ios/ios/instruments"
1212
"github.com/danielpaulus/go-ios/ios/nskeyedarchiver"
13+
"github.com/google/uuid"
1314
log "github.com/sirupsen/logrus"
1415
)
1516

@@ -19,13 +20,15 @@ func runXUITestWithBundleIdsXcode12Ctx(ctx context.Context, config TestConfig, v
1920
if err != nil {
2021
return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot create a usbmuxd connection to testmanagerd: %w", err)
2122
}
23+
defer conn.Close()
2224

23-
testSessionId, xctestConfigPath, testConfig, testInfo, err := setupXcuiTest(config.Device, config.BundleId, config.TestRunnerBundleId, config.XctestConfigName, config.TestsToRun, config.TestsToSkip, config.XcTest, version)
25+
testSessionId := uuid.New()
26+
testInfo, err := getTestInfo(config.Device, config.BundleId, config.TestRunnerBundleId)
2427
if err != nil {
25-
return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot setup test config: %w", err)
28+
return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot get test info: %w", err)
2629
}
27-
defer conn.Close()
2830

31+
testConfig := createTestConfig(testInfo, testSessionId, config.XctestConfigName, config.TestsToRun, config.TestsToSkip, config.XcTest, version)
2932
ideDaemonProxy := newDtxProxyWithConfig(conn, testConfig, config.Listener)
3033

3134
conn2, err := dtx.NewUsbmuxdConnection(config.Device, testmanagerdiOS14)
@@ -58,7 +61,7 @@ func runXUITestWithBundleIdsXcode12Ctx(ctx context.Context, config TestConfig, v
5861
}
5962
defer pControl.Close()
6063

61-
pid, err := startTestRunner12(pControl, xctestConfigPath, config.TestRunnerBundleId, testSessionId.String(), testInfo.testApp.path+"/PlugIns/"+config.XctestConfigName, config.Args, config.Env)
64+
pid, err := startTestRunner12(pControl, config.TestRunnerBundleId, testSessionId.String(), testInfo.testApp.path+"/PlugIns/"+config.XctestConfigName, config.Args, config.Env)
6265
if err != nil {
6366
return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot start test runner: %w", err)
6467
}
@@ -106,7 +109,7 @@ func runXUITestWithBundleIdsXcode12Ctx(ctx context.Context, config TestConfig, v
106109
return config.Listener.TestSuites, config.Listener.err
107110
}
108111

109-
func startTestRunner12(pControl *instruments.ProcessControl, xctestConfigPath string, bundleID string,
112+
func startTestRunner12(pControl *instruments.ProcessControl, bundleID string,
110113
sessionIdentifier string, testBundlePath string, wdaargs []string, wdaenv map[string]interface{},
111114
) (uint64, error) {
112115
args := []interface{}{
@@ -125,7 +128,7 @@ func startTestRunner12(pControl *instruments.ProcessControl, xctestConfigPath st
125128
"OS_ACTIVITY_DT_MODE": "YES",
126129
"SQLITE_ENABLE_THREAD_ASSERTIONS": "1",
127130
"XCTestBundlePath": testBundlePath,
128-
"XCTestConfigurationFilePath": xctestConfigPath,
131+
"XCTestConfigurationFilePath": "",
129132
"XCTestSessionIdentifier": sessionIdentifier,
130133
}
131134

0 commit comments

Comments
 (0)