void Start()
        {
            logger = new AQALogger();
            if (AutomatedQARuntimeSettings.hostPlatform == HostPlatform.Cloud &&
                AutomatedQARuntimeSettings.buildType == BuildType.FullBuild)
            {
                DontDestroyOnLoad(this.gameObject);
                RecordedPlaybackPersistentData.SetRecordingMode(RecordingMode.Playback);
                DeviceFarmConfig dfConf = CloudTestManager.Instance.GetDeviceFarmConfig();
                Application.quitting += () =>
                {
# if UNITY_EDITOR
                    logger.Log($"Counters generated - {CloudTestManager.Instance.GetTestResults().ToString()}");
#else
                    CloudTestManager.UploadCounters();
#endif
                    RuntimeClient.LogTestCompletion(dfConf.testName);
                };

                // Optionally us a settings json file other than the default.
                TextAsset settings = Resources.Load <TextAsset>(Path.GetFileNameWithoutExtension(dfConf.settingsFileToLoad));
                if (!string.IsNullOrEmpty(dfConf.settingsFileToLoad) && settings != null && !string.IsNullOrEmpty(settings.text))
                {
                    logger.Log($"Updating default Automated QA settings file to {dfConf.settingsFileToLoad}");
                    AutomatedQARuntimeSettings.AutomatedQaSettingsFileName = dfConf.settingsFileToLoad;
                    AutomatedQARuntimeSettings.RefreshConfig();
                }
                RunTest(dfConf.testName);
            }
Example #2
0
        public static void UploadCounters(DeviceFarmOverrides dfConfOverrides = null)
        {
            AQALogger logger = new AQALogger();

            var testResults = CloudTestManager.Instance.GetTestResults(dfConfOverrides);

            logger.Log($"Uploading counters {testResults.ToString()}");
            var postUrl = $"{AutomatedQARuntimeSettings.DEVICE_TESTING_API_ENDPOINT}/v1/counters";

            logger.Log($"Counters = {testResults}");
            byte[]           counterPayload = GetBytes(testResults);
            UploadHandlerRaw uH             = new UploadHandlerRaw(counterPayload);

            uH.contentType = "application/json";


            using (var uwr = new UnityWebRequest(postUrl, UnityWebRequest.kHttpVerbPOST))
            {
                uwr.uploadHandler = uH;
                AsyncOperation request = uwr.SendWebRequest();

                while (!request.isDone)
                {
                }

                if (uwr.IsError())
                {
                    logger.LogError($"Couldn't upload counters. Error - {uwr.error}");
                }
                else
                {
                    logger.Log($"Uploaded counters.");
                }
            }
        }
        public static void DownloadRecording(string recordingFileName, string resultFileOutputPath)
        {
            var logger = new AQALogger();

            var projectId   = Application.cloudProjectId;
            var downloadUri =
                $"{AutomatedQARuntimeSettings.GAMESIM_API_ENDPOINT}/v1/recordings/{recordingFileName}/download?projectId={projectId}";

            var dh = new DownloadHandlerFile(resultFileOutputPath);

            dh.removeFileOnAbort = true;
            logger.Log("Starting download" + downloadUri);
            using (var webrx = UnityWebRequest.Get(downloadUri))
            {
                webrx.downloadHandler = dh;
                AsyncOperation request = webrx.SendWebRequest();

                while (!request.isDone)
                {
                }

                if (webrx.IsError())
                {
                    logger.LogError($"Couldn't download file. Error - {webrx.error}");
                }
                else
                {
                    logger.Log($"Downloaded file saved to {resultFileOutputPath}.");
                }
            }
        }
        public static List <string> CopyRecordingFile(string sourcePath, string destPath)
        {
            AQALogger logger = new AQALogger();

            var createdFiles = new List <string>();
            var destDir      = Path.GetDirectoryName(destPath) ?? "";

            if (!string.IsNullOrEmpty(destDir) && !Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }
            if (!File.Exists(sourcePath))
            {
                logger.LogException(new UnityException($"Required recording file does not exist [{sourcePath}]."));
            }
            File.Copy(sourcePath, destPath, true);
            createdFiles.Add(destPath);

            var recordingFiles = GetSegmentFiles(sourcePath);

            foreach (var recordingFile in recordingFiles)
            {
                var segmentPath = Path.Combine(Path.GetDirectoryName(sourcePath), recordingFile);
                var segmentDest = Path.Combine(destDir, recordingFile);
                File.Copy(segmentPath, segmentDest, true);
                createdFiles.Add(segmentDest);
            }
            logger.Log($"Copied recording file from {sourcePath} to {destPath}");

            return(createdFiles);
        }
Example #5
0
        public DeviceFarmConfig GetDeviceFarmConfig(DeviceFarmOverrides dfOverrides = null)
        {
            string configPath = Path.Combine(Application.persistentDataPath, deviceFarmConfigFile);

            DeviceFarmConfig dfConf;

            if (File.Exists(configPath))
            {
                // Read env and testName
                string configStr = File.ReadAllText(configPath);
                dfConf = JsonUtility.FromJson <DeviceFarmConfig>(configStr.ToString());
            }
            else
            {
                //TODO: Graceful shutdown with logs.
                logger.Log("config.json not found");
                dfConf             = new DeviceFarmConfig();
                dfConf.testName    = "DummyTest";
                dfConf.packageName = Application.identifier;
            }

            if (dfOverrides != null)
            {
                dfConf.testName      = dfOverrides.testName;
                dfConf.awsDeviceUDID = dfOverrides.awsDeviceUDID;
#if UNITY_IOS
                dfConf.awsDeviceModel = dfOverrides.awsDeviceModel;
                dfConf.awsDeviceName  = GetAppleDevice(dfOverrides.awsDeviceModel);
#else
                dfConf.awsDeviceModel = dfOverrides.awsDeviceModel;
#endif
            }

            logger.Log($"Test name - {dfConf.testName}, Config - {dfConf.ToString()}," +
                       $"Device Model - {dfConf.awsDeviceModel}, Device Name - {dfConf.awsDeviceName}");
            return(dfConf);
        }
        /// <summary>
        /// Check if an EventSystem already exists at the time of recording or playback start.
        /// If one exists, set our EventSystem variables to the values defined by the existing system.
        /// Finally, disable the pre-existing system. There can only be one active EventSystem.
        /// </summary>
        void SetEventSystem()
        {
            if (!Initialized)
            {
                return;
            }

            if (EventSystem.current != null)
            {
                GameObject inputObj = new List <GameObject>(FindObjectsOfType <GameObject>()).Find(x =>
                                                                                                   x != gameObject && x.GetComponent <BaseInputModule>() && x.GetComponent <EventSystem>());
                if (inputObj == null)
                {
                    logger.Log("No existing Event System & Input Module was found");
                    return;
                }

                RecordingInputModule  ourModule       = inputModule;
                StandaloneInputModule theirModule     = inputObj.GetComponent <StandaloneInputModule>();
                BaseInputModule       theirBaseModule = inputObj.GetComponent <BaseInputModule>();
                if (theirModule != null)
                {
                    ourModule.cancelButton          = theirModule.cancelButton;
                    ourModule.submitButton          = theirModule.submitButton;
                    ourModule.verticalAxis          = theirModule.verticalAxis;
                    ourModule.horizontalAxis        = theirModule.horizontalAxis;
                    ourModule.inputActionsPerSecond = theirModule.inputActionsPerSecond;
                    ourModule.repeatDelay           = theirModule.repeatDelay;
                }

                EventSystem ourEventSystem   = ourModule.GetComponent <EventSystem>();
                EventSystem theirEventSystem = inputObj.GetComponent <EventSystem>();
                ourEventSystem.firstSelectedGameObject = theirEventSystem.firstSelectedGameObject;
                ourEventSystem.sendNavigationEvents    = theirEventSystem.sendNavigationEvents;
                ourEventSystem.pixelDragThreshold      = theirEventSystem.pixelDragThreshold;

                theirBaseModule.enabled = theirEventSystem.enabled = false;
            }

            EventSystem.current = GetComponent <EventSystem>();
        }
Example #7
0
        public static string CreateFileFromResource(string resourcePath, string fileName)
        {
            AQALogger logger = new AQALogger();

            var resource  = Path.Combine(Path.GetDirectoryName(resourcePath), Path.GetFileNameWithoutExtension(resourcePath));
            var recording = Resources.Load <TextAsset>(resource);

            if (recording != null)
            {
                string destPath = Path.Combine(AutomatedQARuntimeSettings.PersistentDataPath, fileName);
                File.WriteAllText(destPath, recording.text);
                logger.Log($"Copied recording file {resourcePath} to {destPath}");
                return(destPath);
            }
            else
            {
                logger.LogError($"Could not load recording {resourcePath}");
            }

            return(null);
        }
        public static void LogTestCompletion(string testName)
        {
            var logger = new AQALogger();

            logger.Log("Unity Test Completed: " + testName);
        }