diff --git a/ios/testmanagerd/xcuitestrunner.go b/ios/testmanagerd/xcuitestrunner.go index a49dbf3b..4d56ecfa 100644 --- a/ios/testmanagerd/xcuitestrunner.go +++ b/ios/testmanagerd/xcuitestrunner.go @@ -289,35 +289,11 @@ func runXUITestWithBundleIdsXcode15Ctx( } defer conn2.Close() - installationProxy, err := installationproxy.New(config.Device) - if err != nil { - return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot connect to installation proxy: %w", err) - } - defer installationProxy.Close() - apps, err := installationProxy.BrowseUserApps() - if err != nil { - return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot browse user apps: %w", err) - } - - testAppInfo, err := getappInfo(config.TestRunnerBundleId, apps) + testSessionID := uuid.New() + info, err := getTestInfo(config.Device, config.BundleId, config.TestRunnerBundleId) if err != nil { - return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot get test app information: %w", err) + return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot build test info: %w", err) } - - info := testInfo{ - testApp: testAppInfo, - } - - if config.BundleId != "" { - appInfo, err := getappInfo(config.BundleId, apps) - if err != nil { - return make([]TestSuite, 0), fmt.Errorf("runXUITestWithBundleIdsXcode15Ctx: cannot get app information: %w", err) - } - - info.targetApp = appInfo - } - - testSessionID := uuid.New() testconfig := createTestConfig(info, testSessionID, config.XctestConfigName, config.TestsToRun, config.TestsToSkip, config.XcTest, version) ideDaemonProxy1 := newDtxProxyWithConfig(conn1, testconfig, config.Listener) @@ -483,22 +459,21 @@ func startTestRunner17(appserviceConn *appservice.Connection, bundleID string, s return appLaunch, nil } -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) { - testSessionID := uuid.New() +func getTestInfo(device ios.DeviceEntry, bundleID string, testRunnerBundleID string) (testInfo, error) { installationProxy, err := installationproxy.New(device) if err != nil { - return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + return testInfo{}, fmt.Errorf("cannot connect to installation proxy: %w", err) } defer installationProxy.Close() apps, err := installationProxy.BrowseUserApps() if err != nil { - return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + return testInfo{}, fmt.Errorf("cannot browse user apps: %w", err) } testAppInfo, err := getappInfo(testRunnerBundleID, apps) if err != nil { - return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + return testInfo{}, fmt.Errorf("cannot get test app information: %w", err) } info := testInfo{ @@ -508,19 +483,32 @@ func setupXcuiTest(device ios.DeviceEntry, bundleID string, testRunnerBundleID s if bundleID != "" { appInfo, err := getappInfo(bundleID, apps) if err != nil { - return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + return testInfo{}, fmt.Errorf("cannot get app information: %w", err) } log.Debugf("app info found: %+v", appInfo) info.targetApp = appInfo } + return info, nil +} + +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) { + info, err := getTestInfo(device, bundleID, testRunnerBundleID) + if err != nil { + return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + } + houseArrestService, err := house_arrest.New(device, testRunnerBundleID) - defer houseArrestService.Close() if err != nil { return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err } + defer houseArrestService.Close() + log.Debugf("creating test config") + testSessionID := uuid.New() testConfigPath, testConfig, err := createTestConfigOnDevice(testSessionID, info, houseArrestService, xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version) if err != nil { return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err @@ -529,6 +517,44 @@ func setupXcuiTest(device ios.DeviceEntry, bundleID string, testRunnerBundleID s return testSessionID, testConfigPath, testConfig, info, nil } +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) { + testSessionID := uuid.New() + installationProxy, err := installationproxy.New(device) + if err != nil { + return uuid.UUID{}, nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + } + defer installationProxy.Close() + + apps, err := installationProxy.BrowseUserApps() + if err != nil { + return uuid.UUID{}, nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + } + + testAppInfo, err := getappInfo(testRunnerBundleID, apps) + if err != nil { + return uuid.UUID{}, nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + } + + info := testInfo{ + testApp: testAppInfo, + } + + if bundleID != "" { + appInfo, err := getappInfo(bundleID, apps) + if err != nil { + return uuid.UUID{}, nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err + } + log.Debugf("app info found: %+v", appInfo) + + info.targetApp = appInfo + } + + log.Debugf("creating test config") + testConfig := createTestConfig(info, testSessionID, xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version) + + return testSessionID, testConfig, info, nil +} + 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) { relativeXcTestConfigPath := path.Join("tmp", testSessionID.String()+".xctestconfiguration") xctestConfigPath := path.Join(info.testApp.homePath, relativeXcTestConfigPath) diff --git a/ios/testmanagerd/xcuitestrunner_12.go b/ios/testmanagerd/xcuitestrunner_12.go index f4a0ea40..25632657 100644 --- a/ios/testmanagerd/xcuitestrunner_12.go +++ b/ios/testmanagerd/xcuitestrunner_12.go @@ -10,6 +10,7 @@ import ( dtx "github.com/danielpaulus/go-ios/ios/dtx_codec" "github.com/danielpaulus/go-ios/ios/instruments" "github.com/danielpaulus/go-ios/ios/nskeyedarchiver" + "github.com/google/uuid" log "github.com/sirupsen/logrus" ) @@ -19,13 +20,15 @@ func runXUITestWithBundleIdsXcode12Ctx(ctx context.Context, config TestConfig, v if err != nil { return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot create a usbmuxd connection to testmanagerd: %w", err) } + defer conn.Close() - testSessionId, xctestConfigPath, testConfig, testInfo, err := setupXcuiTest(config.Device, config.BundleId, config.TestRunnerBundleId, config.XctestConfigName, config.TestsToRun, config.TestsToSkip, config.XcTest, version) + testSessionId := uuid.New() + testInfo, err := getTestInfo(config.Device, config.BundleId, config.TestRunnerBundleId) if err != nil { - return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot setup test config: %w", err) + return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot get test info: %w", err) } - defer conn.Close() + testConfig := createTestConfig(testInfo, testSessionId, config.XctestConfigName, config.TestsToRun, config.TestsToSkip, config.XcTest, version) ideDaemonProxy := newDtxProxyWithConfig(conn, testConfig, config.Listener) conn2, err := dtx.NewUsbmuxdConnection(config.Device, testmanagerdiOS14) @@ -58,7 +61,7 @@ func runXUITestWithBundleIdsXcode12Ctx(ctx context.Context, config TestConfig, v } defer pControl.Close() - pid, err := startTestRunner12(pControl, xctestConfigPath, config.TestRunnerBundleId, testSessionId.String(), testInfo.testApp.path+"/PlugIns/"+config.XctestConfigName, config.Args, config.Env) + pid, err := startTestRunner12(pControl, config.TestRunnerBundleId, testSessionId.String(), testInfo.testApp.path+"/PlugIns/"+config.XctestConfigName, config.Args, config.Env) if err != nil { return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot start test runner: %w", err) } @@ -106,7 +109,7 @@ func runXUITestWithBundleIdsXcode12Ctx(ctx context.Context, config TestConfig, v return config.Listener.TestSuites, config.Listener.err } -func startTestRunner12(pControl *instruments.ProcessControl, xctestConfigPath string, bundleID string, +func startTestRunner12(pControl *instruments.ProcessControl, bundleID string, sessionIdentifier string, testBundlePath string, wdaargs []string, wdaenv map[string]interface{}, ) (uint64, error) { args := []interface{}{ @@ -125,7 +128,7 @@ func startTestRunner12(pControl *instruments.ProcessControl, xctestConfigPath st "OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "XCTestBundlePath": testBundlePath, - "XCTestConfigurationFilePath": xctestConfigPath, + "XCTestConfigurationFilePath": "", "XCTestSessionIdentifier": sessionIdentifier, }