public override IEnumerator Setup()
        {
            yield return(base.Setup());

            Screen.sleepTimeout = SleepTimeout.NeverSleep;
            ReportingManager.IsPlaybackStartedFromEditorWindow = false;
            ReportingManager.InitializeReport();

            if (AutomatedQARuntimeSettings.hostPlatform == HostPlatform.Cloud &&
                AutomatedQARuntimeSettings.buildType == BuildType.UnityTestRunner)
            {
                RecordedTesting.SetupCloudUTFTests(testName);
            }
            else
            {
                RecordedTesting.SetupRecordedTest(testName);
            }

            // Start playback
            CentralAutomationController.Instance.Reset();
            CentralAutomationController.Instance.AddAutomator <RecordedPlaybackAutomator>(new RecordedPlaybackAutomatorConfig
            {
                loadEntryScene = true,
            });
            CentralAutomationController.Instance.Run();

            // wait for playback to start
            while (!RecordedPlaybackController.Exists() || !RecordedPlaybackController.Instance.IsInitialized())
            {
                yield return(null);
            }
        }
    /// <summary>
    /// A new recording or Unity test is being launched. Prepare to capture related data.
    /// </summary>
    public static void InitializeDataForNewTest()
    {
        if (!Initialized)
        {
            InitializeReport();
        }

        // Test was already initialized. Most likely due to errors or logs requiring test data initialization before it would normally be invoked.
        bool isCurrentTestAlreadyInitialized = ReportData.Tests.Any() && ReportData.Tests.FindAll(x => x.TestName == CurrentTestName).Any();
        // If this is a full generated test, this method will be invoked when empty scenes are loaded between Unity Test Runner test execution. Ignore when that happens.
        bool isCurrentGameStateReadyForInitialization = IsTestWithoutRecordingFile &&
                                                        (string.IsNullOrEmpty(CurrentTestName) ||
                                                         SceneManager.GetActiveScene().name.ToLower().Contains("emptyscene"));

        if (!IsCrawler &&
            (isCurrentTestAlreadyInitialized || isCurrentGameStateReadyForInitialization))
        {
            return;
        }

        if (ReportData.Tests.Any() && ReportData.Tests.Last().InProgress)
        {
            FinalizeTestData();
        }
        TestData recording = new TestData();

        recording.TestName = IsCrawler ? "Game Crawler" : CurrentTestName;

        // Check if the current test is expected to have a json recording file.
        if (!IsTestWithoutRecordingFile && AutomatedQARuntimeSettings.hostPlatform != HostPlatform.Cloud &&
            (!string.IsNullOrEmpty(recording.TestName) || !string.IsNullOrEmpty(RecordedPlaybackPersistentData.RecordingFileName)) &&
            // CurrentTestName is null/empty if a recording was launched from AutomatedQa editor windows.
            (string.IsNullOrEmpty(CurrentTestName) ? true : RecordedTesting.IsRecordedTest(recording.TestName)))
        {
            recording.RecordingName = string.IsNullOrEmpty(RecordedPlaybackPersistentData.RecordingFileName) ?
                                      RecordedTesting.GetLocalRecordingFile(recording.TestName) :
                                      RecordedPlaybackPersistentData.RecordingFileName;
        }
        recording.RecordingName = string.IsNullOrEmpty(recording.RecordingName) ? "" : recording.RecordingName.Split('/').Last().Replace(".json", string.Empty);
        recording.StartTime     = Time.time;
        recording.TimestampUtc  = DateTime.UtcNow.ToString();
        recording.InProgress    = true;
        StepData step = new StepData();

        step.Name       = "Test Initialization";
        step.Scene      = SceneManager.GetActiveScene().name;
        step.ActionType = "setup";
        recording.Steps.Add(step);
        ReportData.Tests.Add(recording);
    }
Ejemplo n.º 3
0
        public virtual IEnumerator UnityTearDown()
        {
            if (CentralAutomationController.Exists())
            {
                CentralAutomationController.Instance.Reset();
            }
            if (RecordedPlaybackController.Exists())
            {
                RecordedPlaybackController.Instance.Reset();
            }

            if (RecordedTesting.IsRecordedTest(testName))
            {
                ReportingManager.CreateMonitoringService();
            }

            int    sceneCount = 0;
            string sceneName  = string.Empty;

            while (true)
            {
                bool sceneExists = false;
                sceneName = "emptyscene" + sceneCount++;
                for (int x = 0; x < SceneManager.sceneCount; x++)
                {
                    if (SceneManager.GetSceneAt(x).name == sceneName)
                    {
                        sceneExists = true;
                    }
                }
                if (!sceneExists)
                {
                    break;
                }
            }

            var emptyScene = SceneManager.CreateScene(sceneName);

            SceneManager.SetActiveScene(emptyScene);
            yield return(UnloadScenesExcept(emptyScene.name));
        }