Skip to content

fix running wda on ios 14..16 #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 60 additions & 34 deletions ios/testmanagerd/xcuitestrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand All @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions ios/testmanagerd/xcuitestrunner_12.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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{}{
Expand All @@ -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,
}

Expand Down