Beispiel #1
0
        private static int BuildAndRunAndroidTests(List <string> commandArgs, bool reinstall, string resultPath)
        {
            if (commandArgs.Count == 0)
            {
                throw new OptionException("One APK should be provided", "apk");
            }

            // get build number
            int buildNumber;

            if (!Int32.TryParse(Environment.GetEnvironmentVariable("XENKO_BUILD_NUMBER"), out buildNumber))
            {
                buildNumber = -1;
            }

            // get branch name
            var branchName = Environment.GetEnvironmentVariable("XENKO_BRANCH_NAME");

            var exitCode = 0;

            foreach (var packageFile in commandArgs)
            {
                if (!packageFile.EndsWith("-Signed.apk"))
                {
                    throw new OptionException("APK should end up with \"-Signed.apk\"", "apk");
                }

                // Remove -Signed.apk suffix
                var packageName = Path.GetFileName(packageFile);
                packageName = packageName.Replace("-Signed.apk", Empty);

                var androidDevices = AndroidDeviceEnumerator.ListAndroidDevices();
                if (androidDevices.Length == 0)
                {
                    throw new InvalidOperationException("Could not find any Android device connected.");
                }

                foreach (var device in androidDevices)
                {
                    var testServerHost = new TestServerHost(buildNumber, branchName);
                    testServerHost.TryConnect("127.0.0.1", RouterClient.DefaultPort, true).Wait();
                    Directory.CreateDirectory(resultPath);
                    var deviceResultFile = Path.Combine(resultPath, "TestResult_" + packageName + "_Android_" + device.Name + "_" + device.Serial + ".xml");

                    var currentExitCode = testServerHost.RunAndroidTest(
                        new TestServerHost.ConnectedDevice
                    {
                        Name     = device.Name,
                        Serial   = device.Serial,
                        Platform = TestPlatform.Android,
                    },
                        reinstall, packageName, packageFile, deviceResultFile);

                    var adbPath = AndroidDeviceEnumerator.GetAdbPath();

                    // force stop - only works for Android 3.0 and above.
                    ShellHelper.RunProcessAndGetOutput(adbPath, $@"-s {device.Serial} shell am force-stop {packageName}");

                    if (currentExitCode != 0)
                    {
                        exitCode = currentExitCode;
                    }
                }
            }

            return(exitCode);
        }
Beispiel #2
0
        private static int BuildAndRunAndroidTests(List<string> commandArgs, bool reinstall, string resultPath)
        {
            if (commandArgs.Count == 0)
                throw new OptionException("One APK should be provided", "apk");

            // get build number
            int buildNumber;
            if (!Int32.TryParse(Environment.GetEnvironmentVariable("XENKO_BUILD_NUMBER"), out buildNumber))
                buildNumber = -1;

            // get branch name
            var branchName = Environment.GetEnvironmentVariable("XENKO_BRANCH_NAME");

            var exitCode = 0;

            foreach (var packageFile in commandArgs)
            {
                if (!packageFile.EndsWith("-Signed.apk"))
                    throw new OptionException("APK should end up with \"-Signed.apk\"", "apk");

                // Remove -Signed.apk suffix
                var packageName = Path.GetFileName(packageFile);
                packageName = packageName.Replace("-Signed.apk", Empty);

                var androidDevices = AndroidDeviceEnumerator.ListAndroidDevices();
                if (androidDevices.Length == 0)
                    throw new InvalidOperationException("Could not find any Android device connected.");

                foreach (var device in androidDevices)
                {
                    var testServerHost = new TestServerHost(buildNumber, branchName);
                    testServerHost.TryConnect("127.0.0.1", RouterClient.DefaultPort, true).Wait();
                    Directory.CreateDirectory(resultPath);
                    var deviceResultFile = Path.Combine(resultPath, "TestResult_" + packageName + "_Android_" + device.Name + "_" + device.Serial + ".xml");

                    var currentExitCode = testServerHost.RunAndroidTest(new TestServerHost.ConnectedDevice
                    {
                        Name = device.Name, Serial = device.Serial, Platform = TestPlatform.Android,
                    }, reinstall, packageName, packageFile, deviceResultFile);

                    var adbPath = AndroidDeviceEnumerator.GetAdbPath();

                    // force stop - only works for Android 3.0 and above.
                    ShellHelper.RunProcessAndGetOutput(adbPath, $@"-s {device.Serial} shell am force-stop {packageName}");

                    if (currentExitCode != 0)
                        exitCode = currentExitCode;
                }
            }

            return exitCode;
        }