-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
xcuitestrunner_11.go
125 lines (112 loc) · 3.38 KB
/
xcuitestrunner_11.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package testmanagerd
import (
"context"
"github.com/danielpaulus/go-ios/ios"
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
"github.com/danielpaulus/go-ios/ios/instruments"
log "github.com/sirupsen/logrus"
"strings"
)
func RunXCUIWithBundleIds11Ctx(
ctx context.Context,
bundleID string,
testRunnerBundleID string,
xctestConfigFileName string,
device ios.DeviceEntry,
args []string,
env []string) error {
log.Debugf("set up xcuitest")
testSessionId, xctestConfigPath, testConfig, testInfo, err := setupXcuiTest(device, bundleID, testRunnerBundleID, xctestConfigFileName)
if err != nil {
return err
}
log.Debugf("test session setup ok")
conn, err := dtx.NewConnection(device, testmanagerd)
if err != nil {
return err
}
defer conn.Close()
ideDaemonProxy := newDtxProxyWithConfig(conn, testConfig)
conn2, err := dtx.NewConnection(device, testmanagerd)
if err != nil {
return err
}
defer conn2.Close()
log.Debug("connections ready")
ideDaemonProxy2 := newDtxProxyWithConfig(conn2, testConfig)
ideDaemonProxy2.ideInterface.testConfig = testConfig
//TODO: fixme
protocolVersion := uint64(25)
_, err = ideDaemonProxy.daemonConnection.initiateSessionWithIdentifier(testSessionId, protocolVersion)
if err != nil {
return err
}
pControl, err := instruments.NewProcessControl(device)
if err != nil {
return err
}
defer pControl.Close()
pid, err := startTestRunner11(pControl, xctestConfigPath, testRunnerBundleID, testSessionId.String(), testInfo.testrunnerAppPath+"/PlugIns/"+xctestConfigFileName, args, env)
if err != nil {
return err
}
log.Debugf("Runner started with pid:%d, waiting for testBundleReady", pid)
err = ideDaemonProxy2.daemonConnection.initiateControlSession(pid, protocolVersion)
if err != nil {
return err
}
log.Debugf("control session initiated")
ideInterfaceChannel := ideDaemonProxy.dtxConnection.ForChannelRequest(ProxyDispatcher{id: "emty"})
log.Debug("start executing testplan")
err = ideDaemonProxy2.daemonConnection.startExecutingTestPlanWithProtocolVersion(ideInterfaceChannel, 25)
if err != nil {
log.Error(err)
}
if ctx != nil {
select {
case <-ctx.Done():
log.Infof("Killing WebDriverAgent with pid %d ...", pid)
err = pControl.KillProcess(pid)
if err != nil {
return err
}
log.Info("WDA killed with success")
}
return nil
}
log.Debugf("done starting test")
<-closeChan
log.Infof("Killing WebDriverAgent with pid %d ...", pid)
err = pControl.KillProcess(pid)
if err != nil {
return err
}
log.Info("WDA killed with success")
var signal interface{}
closedChan <- signal
return nil
}
func startTestRunner11(pControl *instruments.ProcessControl, xctestConfigPath string, bundleID string,
sessionIdentifier string, testBundlePath string, wdaargs []string, wdaenv []string) (uint64, error) {
args := []interface{}{}
for _, arg := range wdaargs {
args = append(args, arg)
}
env := map[string]interface{}{
"XCTestBundlePath": testBundlePath,
"XCTestConfigurationFilePath": xctestConfigPath,
"XCTestSessionIdentifier": sessionIdentifier,
}
for _, entrystring := range wdaenv {
entry := strings.Split(entrystring, "=")
key := entry[0]
value := entry[1]
env[key] = value
log.Debugf("adding extra env %s=%s", key, value)
}
opts := map[string]interface{}{
"StartSuspendedKey": uint64(0),
"ActivateSuspended": uint64(1),
}
return pControl.StartProcess(bundleID, env, args, opts)
}