Skip to content

Commit

Permalink
fix 'automationFrameworkPath' for iOS 17+ (#506)
Browse files Browse the repository at this point in the history
this value has changed with iOS 17. While this did not cause problems in most
cases, UI interruption handlers were broken because of that. They simply stopped
firing with that value pointing to the old path
  • Loading branch information
dmissmann authored Oct 30, 2024
1 parent 55deb23 commit 6fa8b80
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
3 changes: 2 additions & 1 deletion ios/nskeyedarchiver/archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"testing"

"github.com/Masterminds/semver"
"github.com/danielpaulus/go-ios/ios/nskeyedarchiver"
archiver "github.com/danielpaulus/go-ios/ios/nskeyedarchiver"
"github.com/google/uuid"
Expand Down Expand Up @@ -36,7 +37,7 @@ func TestArchiveSlice(t *testing.T) {
// TODO currently only partially decoding XCTestConfig is supported, fix later
func TestXCTestconfig(t *testing.T) {
uuid := uuid.New()
config := nskeyedarchiver.NewXCTestConfiguration("productmodulename", uuid, "targetAppBundle", "targetAppPath", "testBundleUrl", nil, nil, false)
config := nskeyedarchiver.NewXCTestConfiguration("productmodulename", uuid, "targetAppBundle", "targetAppPath", "testBundleUrl", nil, nil, false, semver.MustParse("17.0.0"))
result, err := nskeyedarchiver.ArchiveXML(config)
if err != nil {
log.Error(err)
Expand Down
8 changes: 7 additions & 1 deletion ios/nskeyedarchiver/objectivec_classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"regexp"
"time"

"github.com/Masterminds/semver"
"github.com/google/uuid"
"howett.net/plist"
)
Expand Down Expand Up @@ -84,6 +85,7 @@ func NewXCTestConfiguration(
testsToRun []string,
testsToSkip []string,
isXCTest bool,
version *semver.Version,
) XCTestConfiguration {
contents := map[string]interface{}{}

Expand Down Expand Up @@ -119,7 +121,11 @@ func NewXCTestConfiguration(
}

contents["aggregateStatisticsBeforeCrash"] = map[string]interface{}{"XCSuiteRecordsKey": map[string]interface{}{}}
contents["automationFrameworkPath"] = "/Developer/Library/PrivateFrameworks/XCTAutomationSupport.framework"
if version.Major() >= 17 {
contents["automationFrameworkPath"] = "/System/Developer/Library/PrivateFrameworks/XCTAutomationSupport.framework"
} else {
contents["automationFrameworkPath"] = "/Developer/Library/PrivateFrameworks/XCTAutomationSupport.framework"
}
contents["baselineFileRelativePath"] = plist.UID(0)
contents["baselineFileURL"] = plist.UID(0)
contents["defaultTestExecutionTimeAllowance"] = plist.UID(0)
Expand Down
25 changes: 14 additions & 11 deletions ios/testmanagerd/xcuitestrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"strings"

"github.com/Masterminds/semver"
"github.com/danielpaulus/go-ios/ios/appservice"

"github.com/danielpaulus/go-ios/ios/house_arrest"
Expand Down Expand Up @@ -270,16 +271,16 @@ func RunXCUIWithBundleIdsCtx(

if version.LessThan(ios.IOS14()) {
log.Debugf("iOS version: %s detected, running with ios11 support", version)
return runXCUIWithBundleIdsXcode11Ctx(ctx, bundleID, testRunnerBundleID, xctestConfigFileName, device, args, env, testsToRun, testsToSkip, testListener, isXCTest)
return runXCUIWithBundleIdsXcode11Ctx(ctx, bundleID, testRunnerBundleID, xctestConfigFileName, device, args, env, testsToRun, testsToSkip, testListener, isXCTest, version)
}

if version.LessThan(ios.IOS17()) {
log.Debugf("iOS version: %s detected, running with ios14 support", version)
return runXUITestWithBundleIdsXcode12Ctx(ctx, bundleID, testRunnerBundleID, xctestConfigFileName, device, args, env, testsToRun, testsToSkip, testListener, isXCTest)
return runXUITestWithBundleIdsXcode12Ctx(ctx, bundleID, testRunnerBundleID, xctestConfigFileName, device, args, env, testsToRun, testsToSkip, testListener, isXCTest, version)
}

log.Debugf("iOS version: %s detected, running with ios17 support", version)
return runXUITestWithBundleIdsXcode15Ctx(ctx, bundleID, testRunnerBundleID, xctestConfigFileName, device, args, env, testsToRun, testsToSkip, testListener, isXCTest)
return runXUITestWithBundleIdsXcode15Ctx(ctx, bundleID, testRunnerBundleID, xctestConfigFileName, device, args, env, testsToRun, testsToSkip, testListener, isXCTest, version)
}

func runXUITestWithBundleIdsXcode15Ctx(
Expand All @@ -294,6 +295,7 @@ func runXUITestWithBundleIdsXcode15Ctx(
testsToSkip []string,
testListener *TestListener,
isXCTest bool,
version *semver.Version,
) ([]TestSuite, error) {
conn1, err := dtx.NewTunnelConnection(device, testmanagerdiOS17)
if err != nil {
Expand Down Expand Up @@ -336,7 +338,7 @@ func runXUITestWithBundleIdsXcode15Ctx(
}

testSessionID := uuid.New()
testconfig := createTestConfig(info, testSessionID, xctestConfigFileName, testsToRun, testsToSkip, isXCTest)
testconfig := createTestConfig(info, testSessionID, xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version)
ideDaemonProxy1 := newDtxProxyWithConfig(conn1, testconfig, testListener)

localCaps := nskeyedarchiver.XCTCapabilities{CapabilitiesDictionary: map[string]interface{}{
Expand Down Expand Up @@ -500,7 +502,7 @@ func startTestRunner17(device ios.DeviceEntry, appserviceConn *appservice.Connec
return appLaunch, nil
}

func setupXcuiTest(device ios.DeviceEntry, bundleID string, testRunnerBundleID string, xctestConfigFileName string, testsToRun []string, testsToSkip []string, isXCTest bool) (uuid.UUID, string, nskeyedarchiver.XCTestConfiguration, testInfo, error) {
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()
installationProxy, err := installationproxy.New(device)
if err != nil {
Expand Down Expand Up @@ -538,21 +540,22 @@ func setupXcuiTest(device ios.DeviceEntry, bundleID string, testRunnerBundleID s
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
}
log.Debugf("creating test config")
testConfigPath, testConfig, err := createTestConfigOnDevice(testSessionID, info, houseArrestService, xctestConfigFileName, testsToRun, testsToSkip, isXCTest)
testConfigPath, testConfig, err := createTestConfigOnDevice(testSessionID, info, houseArrestService, xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version)
if err != nil {
return uuid.UUID{}, "", nskeyedarchiver.XCTestConfiguration{}, testInfo{}, err
}

return testSessionID, testConfigPath, testConfig, info, nil
}

func createTestConfigOnDevice(testSessionID uuid.UUID, info testInfo, houseArrestService *house_arrest.Connection, xctestConfigFileName string, testsToRun []string, testsToSkip []string, isXCTest bool) (string, nskeyedarchiver.XCTestConfiguration, error) {
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)

testBundleURL := path.Join(info.testApp.path, "PlugIns", xctestConfigFileName)

config := nskeyedarchiver.NewXCTestConfiguration(info.targetApp.bundleName, testSessionID, info.targetApp.bundleID, info.targetApp.path, testBundleURL, testsToRun, testsToSkip, isXCTest)
testConfig := nskeyedarchiver.NewXCTestConfiguration(info.targetApp.bundleName, testSessionID, info.targetApp.bundleID, info.targetApp.path, testBundleURL, testsToRun, testsToSkip, isXCTest, version)
config := testConfig
result, err := nskeyedarchiver.ArchiveXML(config)
if err != nil {
return "", nskeyedarchiver.XCTestConfiguration{}, err
Expand All @@ -562,13 +565,13 @@ func createTestConfigOnDevice(testSessionID uuid.UUID, info testInfo, houseArres
if err != nil {
return "", nskeyedarchiver.XCTestConfiguration{}, err
}
return xctestConfigPath, nskeyedarchiver.NewXCTestConfiguration(info.targetApp.bundleName, testSessionID, info.targetApp.bundleID, info.targetApp.path, testBundleURL, testsToRun, testsToSkip, isXCTest), nil
return xctestConfigPath, testConfig, nil
}

func createTestConfig(info testInfo, testSessionID uuid.UUID, xctestConfigFileName string, testsToRun []string, testsToSkip []string, isXCTest bool) nskeyedarchiver.XCTestConfiguration {
func createTestConfig(info testInfo, testSessionID uuid.UUID, xctestConfigFileName string, testsToRun []string, testsToSkip []string, isXCTest bool, version *semver.Version) nskeyedarchiver.XCTestConfiguration {
// the default value for this generated by Xcode is the target name, and the same name is used for the '.xctest' bundle name per default
productModuleName := strings.ReplaceAll(xctestConfigFileName, ".xctest", "")
return nskeyedarchiver.NewXCTestConfiguration(productModuleName, testSessionID, info.targetApp.bundleID, info.targetApp.path, "PlugIns/"+xctestConfigFileName, testsToRun, testsToSkip, isXCTest)
return nskeyedarchiver.NewXCTestConfiguration(productModuleName, testSessionID, info.targetApp.bundleID, info.targetApp.path, "PlugIns/"+xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version)
}

type testInfo struct {
Expand Down
4 changes: 3 additions & 1 deletion ios/testmanagerd/xcuitestrunner_11.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"maps"

"github.com/Masterminds/semver"
"github.com/danielpaulus/go-ios/ios"
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
"github.com/danielpaulus/go-ios/ios/instruments"
Expand All @@ -23,9 +24,10 @@ func runXCUIWithBundleIdsXcode11Ctx(
testsToSkip []string,
testListener *TestListener,
isXCTest bool,
version *semver.Version,
) ([]TestSuite, error) {
log.Debugf("set up xcuitest")
testSessionId, xctestConfigPath, testConfig, testInfo, err := setupXcuiTest(device, bundleID, testRunnerBundleID, xctestConfigFileName, testsToRun, testsToSkip, isXCTest)
testSessionId, xctestConfigPath, testConfig, testInfo, err := setupXcuiTest(device, bundleID, testRunnerBundleID, xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version)
if err != nil {
return make([]TestSuite, 0), fmt.Errorf("RunXCUIWithBundleIdsXcode11Ctx: cannot create test config: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions ios/testmanagerd/xcuitestrunner_12.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"maps"
"time"

"github.com/Masterminds/semver"
"github.com/danielpaulus/go-ios/ios"
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
"github.com/danielpaulus/go-ios/ios/instruments"
Expand All @@ -14,14 +15,14 @@ import (
)

func runXUITestWithBundleIdsXcode12Ctx(ctx context.Context, bundleID string, testRunnerBundleID string, xctestConfigFileName string,
device ios.DeviceEntry, args []string, env map[string]interface{}, testsToRun []string, testsToSkip []string, testListener *TestListener, isXCTest bool,
device ios.DeviceEntry, args []string, env map[string]interface{}, testsToRun []string, testsToSkip []string, testListener *TestListener, isXCTest bool, version *semver.Version,
) ([]TestSuite, error) {
conn, err := dtx.NewUsbmuxdConnection(device, testmanagerdiOS14)
if err != nil {
return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot create a usbmuxd connection to testmanagerd: %w", err)
}

testSessionId, xctestConfigPath, testConfig, testInfo, err := setupXcuiTest(device, bundleID, testRunnerBundleID, xctestConfigFileName, testsToRun, testsToSkip, isXCTest)
testSessionId, xctestConfigPath, testConfig, testInfo, err := setupXcuiTest(device, bundleID, testRunnerBundleID, xctestConfigFileName, testsToRun, testsToSkip, isXCTest, version)
if err != nil {
return make([]TestSuite, 0), fmt.Errorf("RunXUITestWithBundleIdsXcode12Ctx: cannot setup test config: %w", err)
}
Expand Down

0 comments on commit 6fa8b80

Please sign in to comment.