Skip to content

Commit

Permalink
Update runtest to accept additional arguments (#229)
Browse files Browse the repository at this point in the history
* Updated `runtest` command to accept 3 arguments so users can fine tune the test execution based on their own configuration - #224 
* Added `--bundle-id`, `test-runner-bundle-id` and `xctest-config` arguments to `runtest`  
* `test-runner-bundle-id` and `xctest-config` can be omitted which will use the initial logic of building them dynamically
  • Loading branch information
shamanec authored Feb 20, 2023
1 parent 0c0800d commit 5a7b837
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 13 additions & 5 deletions ios/testmanagerd/xcuitestrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package testmanagerd
import (
"context"
"fmt"
"github.com/danielpaulus/go-ios/ios/house_arrest"
"path"
"strings"
"time"

"github.com/danielpaulus/go-ios/ios/house_arrest"

"github.com/danielpaulus/go-ios/ios"
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
"github.com/danielpaulus/go-ios/ios/installationproxy"
Expand Down Expand Up @@ -247,8 +248,7 @@ const testmanagerdiOS14 = "com.apple.testmanagerd.lockdown.secure"

const testBundleSuffix = "UITests.xctrunner"

func RunXCUITest(bundleID string, device ios.DeviceEntry, env []string) error {
testRunnerBundleID := bundleID + testBundleSuffix
func RunXCUITest(bundleID string, testRunnerBundleID string, xctestConfigName string, device ios.DeviceEntry, env []string) error {
//FIXME: this is redundant code, getting the app list twice and creating the appinfos twice
//just to generate the xctestConfigFileName. Should be cleaned up at some point.
installationProxy, err := installationproxy.New(device)
Expand All @@ -257,6 +257,10 @@ func RunXCUITest(bundleID string, device ios.DeviceEntry, env []string) error {
}
defer installationProxy.Close()

if testRunnerBundleID == "" {
testRunnerBundleID = bundleID + testBundleSuffix
}

apps, err := installationProxy.BrowseUserApps()
if err != nil {
return err
Expand All @@ -265,8 +269,12 @@ func RunXCUITest(bundleID string, device ios.DeviceEntry, env []string) error {
if err != nil {
return err
}
xctestConfigFileName := info.targetAppBundleName + "UITests.xctest"
return RunXCUIWithBundleIdsCtx(nil, bundleID, testRunnerBundleID, xctestConfigFileName, device, nil, env)

if xctestConfigName == "" {
xctestConfigName = info.targetAppBundleName + "UITests.xctest"
}

return RunXCUIWithBundleIdsCtx(nil, bundleID, testRunnerBundleID, xctestConfigName, device, nil, env)
}

var closeChan = make(chan interface{})
Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Usage:
ios apps [--system] [--all] [--list] [options]
ios launch <bundleID> [--wait] [options]
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options]
ios runtest <bundleID> [--env=<e>]... [options]
ios runtest [--bundle-id=<bundleid>] [--test-runner-bundle-id=<testrunnerbundleid>] [--xctest-config=<xctestconfig>] [--env=<e>]... [options]
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]... [options]
ios ax [options]
ios debug [options] [--stop-at-entry] <app_path>
Expand Down Expand Up @@ -180,7 +180,7 @@ The commands work as following:
ios apps [--system] [--all] [--list] Retrieves a list of installed applications. --system prints out preinstalled system apps. --all prints all apps, including system, user, and hidden apps. --list only prints bundle ID, bundle name and version number.
ios launch <bundleID> [--wait] Launch app with the bundleID on the device. Get your bundle ID from the apps command. --wait keeps the connection open if you want logs.
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options] Kill app with the specified bundleID, process id, or process name on the device.
ios runtest <bundleID> [--env=<e>]... [options] Run a XCUITest.
ios runtest [--bundle-id=<bundleid>] [--test-runner-bundle-id=<testbundleid>] [--xctest-config=<xctestconfig>] [--env=<e>]... [options] Run a XCUITest. If you provide only bundle-id go-ios will try to dynamically create test-runner-bundle-id and xctest-config.
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]...[options] runs WebDriverAgents
> specify runtime args and env vars like --env ENV_1=something --env ENV_2=else and --arg ARG1 --arg ARG2
ios ax [options] Access accessibility inspector features.
Expand Down Expand Up @@ -610,9 +610,12 @@ The commands work as following:

b, _ = arguments.Bool("runtest")
if b {
bundleID, _ := arguments.String("<bundleID>")
bundleID, _ := arguments.String("--bundle-id")
testRunnerBundleId, _ := arguments.String("--test-runner-bundle-id")
xctestConfig, _ := arguments.String("--xctest-config")

env := arguments["--env"].([]string)
err := testmanagerd.RunXCUITest(bundleID, device, env)
err := testmanagerd.RunXCUITest(bundleID, testRunnerBundleId, xctestConfig, device, env)
if err != nil {
log.WithFields(log.Fields{"error": err}).Info("Failed running Xcuitest")
}
Expand Down

0 comments on commit 5a7b837

Please sign in to comment.