79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Diagnostics;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AndroidLauncher
|
|
{
|
|
class Program
|
|
{
|
|
private const int MainThreadSleepTime = 60000; // 1 minute
|
|
private const int DetectDevicesRetryCount = 2;
|
|
private const int CheckFreeDeviceWaitingTime = 10000;
|
|
private const int MaxWaitTime = 3 * 60 * 60 * 1000; // 3 hours
|
|
public static DeviceConnectionInfo device = null;
|
|
|
|
|
|
public static void PrepareTestingEnvironment(string appPackageName, string apkLocation)
|
|
{
|
|
Action onFailureCallback = () =>
|
|
{
|
|
Environment.Exit(ExitCodes.Failed);
|
|
};
|
|
|
|
|
|
// Kill the Android process which might be still active but in the background after a crash occured
|
|
Utils.StartAdbSyncWithTimeout("Killing the app before running the tests!", "shell am force-stop " + appPackageName);
|
|
|
|
device = Utils.FindAvailableDeviceToRunWithRetry(appPackageName, DetectDevicesRetryCount);
|
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
stopwatch.Start();
|
|
|
|
while (device == null && stopwatch.Elapsed.TotalMilliseconds < MaxWaitTime)
|
|
{
|
|
Console.WriteLine("All devices are busy! Waiting for a free device!");
|
|
Thread.Sleep(CheckFreeDeviceWaitingTime);
|
|
device = Utils.FindAvailableDeviceToRun(appPackageName);
|
|
}
|
|
|
|
if (device == null)
|
|
{
|
|
Console.WriteLine("Timeout while waiting for a free device!");
|
|
Environment.Exit(ExitCodes.WaitFreeDeviceTimeout);
|
|
}
|
|
else
|
|
{
|
|
device.PrepareDevice(appPackageName, apkLocation, onFailureCallback);
|
|
}
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Utils.ValidateArguments(args);
|
|
|
|
string apkLocation = args[0];
|
|
string appPackageName = args[1];
|
|
string onSuccessStringParameter = args[2];
|
|
string onExitStringsParameter = args[3];
|
|
string activityIntent = args[4];
|
|
string activityIntentParameters = args[5];
|
|
string fullLogsPath = args[6];
|
|
string adbPath = args[7];
|
|
|
|
AndroidADBProcess.SetADB(adbPath);
|
|
|
|
PrepareTestingEnvironment(appPackageName, apkLocation);
|
|
|
|
device.LaunchTests(activityIntent, activityIntentParameters);
|
|
|
|
WatchDog watchDog = new WatchDog(device, appPackageName, Utils.GetExitStrings(onExitStringsParameter), onSuccessStringParameter, fullLogsPath);
|
|
watchDog.Start();
|
|
|
|
while (watchDog.IsAlive)
|
|
{
|
|
Thread.Sleep(MainThreadSleepTime);
|
|
}
|
|
}
|
|
}
|
|
}
|