-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
65 lines (53 loc) · 2.08 KB
/
test.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
package appiumService
import (
"fmt"
commonService "github.com/aaronchen2k/tester/internal/agent/service/common"
deviceService "github.com/aaronchen2k/tester/internal/agent/service/device"
androidService "github.com/aaronchen2k/tester/internal/agent/service/device/android"
execService "github.com/aaronchen2k/tester/internal/agent/service/exec"
agentConst "github.com/aaronchen2k/tester/internal/agent/utils/const"
_domain "github.com/aaronchen2k/tester/internal/pkg/domain"
"strconv"
"strings"
)
func ExecTest(build *_domain.BuildTo) {
result := _domain.RpcResult{}
device, ok := deviceService.GetDevice(build.Serial)
if !ok {
result.Fail(fmt.Sprintf("can't find device %s@%s。", device.Serial, device.ComputerIp))
return
}
commonService.SetBuildWorkDir(build)
// get script
execService.GetTestScript(build)
if build.ProjectDir == "" {
result.Fail(fmt.Sprintf("failed to get test script, %#v。", build))
return
}
// get app
execService.GetTestApp(build)
// exec test
parseBuildCommand(build)
result = execService.ExcCommand(build)
if !result.IsSuccess() {
result.Fail(fmt.Sprintf("failed to ext test,\n dir: %s\n app: %s\n cmd: \n%s",
build.ProjectDir, build.AppPath, build.BuildCommands))
}
// submit result
execService.UploadResult(*build, result)
}
func parseBuildCommand(build *_domain.BuildTo) {
// mvn clean test -Dtestng.suite=target/test-classes/android-test.xml
// -DappPath=${appPath}
// -DappPackage=${appPackage}
// -DappActivity==${appActivity}
// -DappiumPort==${appiumPort}
app := androidService.GetAppInfo(build.AppPath)
appPackage := app.MainPackage
appActivity := app.MainActivity
command := strings.ReplaceAll(build.BuildCommands, agentConst.BuildParamAppPath, build.AppPath)
command = strings.ReplaceAll(command, agentConst.BuildParamAppPackage, appPackage)
command = strings.ReplaceAll(command, agentConst.BuildParamAppActivity, appActivity)
command = strings.ReplaceAll(command, agentConst.BuildParamAppiumPort, strconv.Itoa(build.AppiumPort))
build.BuildCommands = command
}