private static void Set() { _config = FileBroker.GetTextResource(FileResource.TrilleonConfig); string[] rawKeys = _config.Split(new string[] { "\n", "\r" }, System.StringSplitOptions.RemoveEmptyEntries); _requiredConfigs = new List <KeyValuePair <string, string> >(); _customConfigs = new List <KeyValuePair <string, string> >(); isRequiredSection = true; for (int i = 0; i < rawKeys.Length; i++) { if (i != 0) { if (rawKeys[i].StartsWith("**")) { isRequiredSection = false; continue; } string[] thisKey = rawKeys[i].Split('='); if (isRequiredSection) { _requiredConfigs.Add(new KeyValuePair <string, string>(thisKey[0], thisKey[1])); } else { _customConfigs.Add(new KeyValuePair <string, string>(thisKey[0], thisKey[1])); } } } }
public static void BuildTemporaryReportForSingleConsoleFailure(string testMethodName) { #if UNITY_EDITOR SetCompleteReport(testMethodName); FileBroker.CreateFileAtPath(string.Format("{0}SingleTestAsReportTemp.html", FileBroker.RESOURCES_DIRECTORY), htmlBody.ToString()); #endif }
void SaveSettings() { changesMade = false; //Build file text. StringBuilder textInfo = new StringBuilder(); for (int i = 0; i < editableFields.Count; i++) { if (string.IsNullOrEmpty(editableFields[i][0])) { textInfo.AppendLine(editableFields[i][1]); } else { string key = editableFields[i][0].ToUpper().Replace(' ', '_'); HandleSpecificKeyChangeRequirements(key, editableFields[i][1]); textInfo.AppendLine(string.Format("{0}{1}={2}", criticalFields[i] ? "!" : string.Empty, key, editableFields[i][1])); } } //Overwrite and save settings to file. FileBroker.SaveTextResource(FileResource.TrilleonConfig, textInfo.ToString()); editableFields = new List <string[]>(); hiddenFields = new List <string[]>(); criticalFields = new List <bool>(); saveTime = DateTime.UtcNow; saved = true; Set(); GetConfig(); }
public override void Set() { if (!AutomationMaster.AllMethodsInFramework.Any()) { AutomationMaster.SetAllMethodsInFramework(); } string rawFavoritesData = FileBroker.GetNonUnityTextResource(AutomationMaster.UnitTestMode ? FileResource.FavoritesUnit : FileResource.Favorites); List <string> favoritesEachRaw = rawFavoritesData.Split(AutomationMaster.DELIMITER).ToList(); FavoritesList = new List <KeyValuePair <string, List <KeyValuePair <bool, string> > > >(); for (int f = 0; f < favoritesEachRaw.Count; f++) { //Invalid data if (!favoritesEachRaw[f].Trim().Contains(internalDelimiter)) { continue; } List <string> pieces = favoritesEachRaw[f].Split(new string[] { internalDelimiter }, StringSplitOptions.None).ToList(); pieces = pieces.RemoveNullAndEmpty(); //Remove possible empties due to line breaks at end of file. string name = pieces.First(); List <KeyValuePair <bool, string> > tests = new List <KeyValuePair <bool, string> >(); for (int t = 1; t < pieces.Count; t++) { tests.Add(new KeyValuePair <bool, string>(pieces[t].EndsWith(classIndicator) ? true : false, pieces[t].EndsWith(classIndicator) ? pieces[t].Replace(classIndicator, string.Empty) : pieces[t])); } FavoritesList.Add(new KeyValuePair <string, List <KeyValuePair <bool, string> > >(name, tests)); } }
private static string GetReportCss() { StringBuilder css = new StringBuilder(); css.Append("<style>"); //Temporararily removing the usage of inline png's. /*for(int f = 0; f < AutomationMaster.TestRunContext.Failed.tests.Count; f++) { * string testName = AutomationMaster.TestRunContext.Failed.tests[f].Key; * bool saveInline = !AutomationMaster.ConfigReader.GetBool("EDITOR_IS_DOT_NET_SUBSET"); * string inlinePngString = saveInline ? GetScreenShotAsInlinePng(testName) : string.Empty; * if(!string.IsNullOrEmpty(inlinePngString)) { * css.AppendLine(string.Format(".fail_test_image_{0} {{ background-repeat: no-repeat; width: 1240px; height: 600px; background-image:url('data:image/png;base64,{1}'); }}", testName, inlinePngString)); * } else { * if(saveInline) { * imageCaptureFailures.Append(string.Format("<div id='fail_test_no_image_{0}' style='display: none;'></div>", testName)); * } * } * }*/ css.Append(FileBroker.GetTextResource(FileResource.ReportCss)); css.Append("</style>"); return(css.ToString()); }
public IEnumerator TakeScreenshot(string screenshotName) { #if UNITY_EDITOR _allScreenshots.Add(screenshotName); string directory = string.Format("{0}{1}/screenshots/", FileBroker.REPORTS_DIRECTORY, AutomationMaster.TestRunLocalDirectory); if (!Directory.Exists(directory)) { Directory.CreateDirectory(Path.GetDirectoryName(directory)); } directory = string.Format("{0}{1}.png", directory, screenshotName); string singleTestReportScreenshotsDirectory = string.Format("{0}screenshots/{1}.png", FileBroker.RESOURCES_DIRECTORY, screenshotName); int counter = 1; while (Directory.Exists(singleTestReportScreenshotsDirectory) || Directory.Exists(directory)) { singleTestReportScreenshotsDirectory = string.Format("{0}screenshots/{1}.png", FileBroker.RESOURCES_DIRECTORY, string.Format("{0}_{1}", screenshotName, counter.ToString())); directory = string.Format("{0}{1}.png", directory, string.Format("{0}_{1}", screenshotName, counter.ToString())); counter++; } ScreenCapture.CaptureScreenshot(singleTestReportScreenshotsDirectory); yield return(StartCoroutine(Q.driver.WaitRealTime(1))); FileBroker.CopyFile(singleTestReportScreenshotsDirectory, directory); #endif yield return(null); }
private static void SaveLogEntry(string consoleMessage) { #if UNITY_EDITOR string expectedFileName = string.Format("ConsoleLog{0}{1}{2}.txt", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), DateTime.Now.Day.ToString()); FileBroker.SaveConsoleFile(expectedFileName, consoleMessage, false); #endif }
static void SaveEdits() { StringBuilder newOrderedTabList = new StringBuilder(); for (int x = 0; x < TabPreferences.Count; x++) { newOrderedTabList.Append(string.Format("{0}${1}|", TabPreferences[x].Key, x + 1)); } FileBroker.SaveNonUnityTextResource(FileResource.NexusTabs, newOrderedTabList.ToString()); }
private static string GetReportScripts() { StringBuilder scripts = new StringBuilder(); scripts.Append("<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>"); scripts.Append("<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script>"); scripts.Append("<script type='text/javascript' src='https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js'></script>"); scripts.Append("<script type='text/javascript' src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>"); scripts.Append("<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>"); scripts.Append(string.Format("<script>{0}</script>", FileBroker.GetTextResource(FileResource.ReportJavascript))); return(scripts.ToString()); }
public static void SaveMostRecentsResults(string status) { _testsMeta = new List <KeyValuePair <string, string[]> >(); fileText = new StringBuilder(); string plainText = string.Format("status:{0}|name:{1}|class:{2}|test_categories:{3}", status, AutomationMaster.CurrentTestContext.TestName, AutomationMaster.CurrentTestContext.ClassName, string.Join(", ", AutomationMaster.CurrentTestContext.Categories.ToArray())); GetMostRecentsResults(status, plainText); //Save updated results. FileBroker.SaveNonUnityTextResource(FileResource.LatestTestResults, fileText); }
public void SaveUpdates() { if (ResourceOrigin == FileResource.TrilleonConfig) { throw new UnityEngine.UnityException("Cannot save to TrilleonConfig from ConfigReader at this time. Not implemented."); } StringBuilder configRaw = new StringBuilder(); for (int i = 0; i < _customConfigs.Count; i++) { configRaw.AppendLine(string.Format("{0}={1}", _customConfigs[i].Key, _customConfigs[i].Value)); } for (int i = 0; i < _requiredConfigs.Count; i++) { configRaw.AppendLine(string.Format("{0}={1}", _requiredConfigs[i].Key, _requiredConfigs[i].Value)); } FileBroker.SaveNonUnityTextResource(ResourceOrigin, configRaw.ToString()); }
public static void SaveConsoleMessagesForAppPlay() { //If app is not playing, save console messages, which will be lost when starting the app. if(Application.isEditor && !Application.isPlaying) { ConsoleLog = string.Format("{0}/console_before_start.txt", FileBroker.CONSOLE_LOG_DIRECTORY); //Overwrite the file. FileBroker.SaveUnboundFile(ConsoleLog, string.Empty); for(int x = 0; x < messageListDisplayed.Count; x++) { FileBroker.SaveUnboundFile(ConsoleLog, messageListDisplayed[x].message, false); } } }
void SaveNew() { StringBuilder sb = new StringBuilder(); if (FavoritesList.Count > 0) { sb.Append(AutomationMaster.DELIMITER); } if (isEdit) { keyToDelete = FavoritesList[EditId].Key; DeleteFavorite(); isEdit = false; } sb.Append(newName); sb.Append(internalDelimiter); List <string> handledClasses = new List <string>(); for (int x = 0; x < buildingAdded.Count; x++) { string className = buildingAdded[x].Key; if (handledClasses.Contains(className)) { continue; } List <KeyValuePair <string, string> > sameClass = buildingAdded.FindAll(k => k.Key == className); sameClass = sameClass.OrderByValues(); string nextToAdd = string.Format("{0}{1}{2}{3}", className, classIndicator, buildingAdded[x].Value.Length > 0 ? internalDelimiter : string.Empty, buildingAdded[x].Value.Length > 0 ? (sameClass.Count > 1 ? string.Join(internalDelimiter, sameClass.ExtractListOfValuesFromKeyValList().ToArray()) : buildingAdded[x].Value) : string.Empty); sb.Append(nextToAdd); if (x + 1 != buildingAdded.Count) { sb.Append(internalDelimiter); } handledClasses.Add(className); } FileBroker.SaveNonUnityTextResource(AutomationMaster.UnitTestMode ? FileResource.FavoritesUnit : FileResource.Favorites, sb.ToString(), false); newName = string.Empty; Set(); Nexus.Self.Tests.Update_Data = true; }
//Take raw file data and simply splice out substring that represents this Favorite's data. void DeleteFavorite() { string rawFavoritesData = FileBroker.GetNonUnityTextResource(AutomationMaster.UnitTestMode ? FileResource.FavoritesUnit : FileResource.Favorites); List <string> split = rawFavoritesData.Split(new string[] { string.Format("{0}{1}", AutomationMaster.DELIMITER, keyToDelete) }, StringSplitOptions.None).ToList(); StringBuilder newData = new StringBuilder(); if (split.Count > 1) { //The item to be deleted is the first Favorites list in the file, so there will not be a complete splice. newData.Append(split.First()); } split = split.Last().Split(AutomationMaster.DELIMITER).ToList(); for (int s = 1; s < split.Count; s++) { newData.Append(string.Format("{0}{1}", AutomationMaster.DELIMITER, split[s])); } FileBroker.SaveNonUnityTextResource(AutomationMaster.UnitTestMode ? FileResource.FavoritesUnit : FileResource.Favorites, newData.ToString(), true); Set(); Nexus.Self.Tests.Update_Data = true; }
public static void SaveBuddyHistory(string buddyName) { string saveName = buddyName.Replace(Arbiter.DEVICE_IDENTIFIER_PREFIX, string.Empty); string txt = FileBroker.GetNonUnityTextResource(FileResource.BuddyHistory); List <string> resultsRaw = txt.Split(new string[] { "\n" }, StringSplitOptions.None).ToList(); StringBuilder fileText = new StringBuilder(); if (!resultsRaw.Contains(saveName)) { resultsRaw.Add(saveName); } resultsRaw = resultsRaw.RemoveNullAndEmpty().Distinct(); for (int f = 0; f < resultsRaw.Count; f++) { fileText.AppendLine(saveName); } //Save updated results. FileBroker.SaveNonUnityTextResource(FileResource.BuddyHistory, fileText); }
void GetConfig() { settings = new List <KeyValuePair <string, string> >(); settingsSaved = new List <KeyValuePair <string, string> >(); string[] instructions = FileBroker.GetTextResource(FileResource.TrilleonConfig).Split('\n'); bool customKey = false; for (int i = 0; i < instructions.Length; i++) { if (string.IsNullOrEmpty(instructions[i])) { continue; } if (!instructions[i].StartsWith("**")) { string[] keyValPair = instructions[i].Split('='); if (keyValPair[0].StartsWith("!")) { criticalFields.Add(true); keyValPair[0] = keyValPair[0].Substring(1, keyValPair[0].Length - 1); } else { criticalFields.Add(false); } KeyValuePair <string, string> pair = new KeyValuePair <string, string>(keyValPair[0], keyValPair[1]); settings.Add(pair); settingsSaved.Add(pair); } else { KeyValuePair <string, string> pair = new KeyValuePair <string, string>(string.Empty, !customKey ? "**** TRILLEON CONFIGS REQUIRED ****" : "**** CUSTOM CONFIGS ****"); settings.Add(pair); settingsSaved.Add(pair); criticalFields.Add(false); customKey = !customKey; } } }
private static string GetScreenShotAsInlinePng(string fileName) { _allScreenshots.Add(fileName); string file = string.Empty; #if UNITY_EDITOR file = string.Format("{0}/{1}.png", FileBroker.SCREENSHOTS_DIRECTORY, fileName); #else file = string.Format("{0}/{1}.png", Application.persistentDataPath, fileName); #endif //Application.CaptureScreenshot occassionally fails. This means the file may not exist. if (FileBroker.Exists(file)) { byte[] imageData = File.ReadAllBytes(file); return(Convert.ToBase64String(imageData)); } else { return(string.Empty); } }
public static void GetConsoleMessagesAfterAppPlay() { //If app is not playing, save console messages, which will be lost when starting the app. if(Application.isEditor) { if(string.IsNullOrEmpty(ConsoleLog)) { ConsoleLog = string.Format("{0}/console_before_start.txt", FileBroker.CONSOLE_LOG_DIRECTORY); } //Iverwrite the file. List<string> Messages = FileBroker.ReadUnboundFile(ConsoleLog).ToList(); for(int x = 0; x < Messages.Count; x++) { AutoConsoleMessage message = new AutoConsoleMessage(Messages[x], MessageLevel.Abridged, ConsoleMessageType.TestRunnerUpdate); messageListDisplayed.Add(message); } } }
public static void GenerateFullCodeSnippet() { StringBuilder snippet = new StringBuilder(); snippet.AppendLine("<style> .code_display { border: 1px solid black; border-radius: 6px; padding: 20px; margin: 20px; } .code_line { padding-bottom: 5px; } .object_declaration { color: #0f93b5; font-weight: bold; } .string_text { color: #cc7a00; } .title { padding: 20px; } .value { color: #008080; } .variable { color: #537da5; } </style>"); snippet.AppendLine("<h2 class='title'>GENERATED CODE</h2>"); snippet.AppendLine("<h4 class='title'>Using</h2>"); snippet.AppendLine("<div id='using_statements' class='code_display'>"); snippet.AppendLine("<div class='code_line'><span class='object_declaration'>using</span> System;</div>"); snippet.AppendLine("<div class='code_line'><span class='object_declaration'>using</span> UnityEngine;</div>"); if (AutomationRecorder.RecordedActions.FindAll(x => x.Action == ActableTypes.Input || x.Action == ActableTypes.Scroll).Any()) { snippet.AppendLine("<div class='code_line'><span class='object_declaration'>using</span> UnityEngine.UI;</div>"); } snippet.AppendLine("</div>"); snippet.AppendLine("<h4 class='title'>Test Code</h2>"); snippet.AppendLine("<div id='code_display' class='code_display'>"); snippet.AppendLine("<div class='code_line'><span class='object_declaration'>GameObject</span> <span class='variable'>parentObject</span> = <span class='value'>null</span>;</div>"); bool setCurrentObjectValue = true; bool setMiddleLevelObjectValue = true; for (int x = 0; x < AutomationRecorder.RecordedActions.Count; x++) { snippet.AppendLine("<div class='code_line'>"); bool anyAssertions = AutomationRecorder.RecordedActions[x].Assertions.Any(); if (anyAssertions && setCurrentObjectValue) { setCurrentObjectValue = false; snippet.AppendLine("<div class='code_line'><span class='object_declaration'>GameObject</span> <span class='variable'>currentObject</span> = <span class='value'>null</span>;</div>"); snippet.AppendLine("</div><div class='code_line'>"); } if (setMiddleLevelObjectValue && AutomationRecorder.RecordedActions[x].ParentNames.Count > MAX_NUM_PARENTNAMES_BEFORE_DRILLDOWN) { //Searches for a parent level object closer to the object attempting to be found, to decrease finding of wrong object with identical name. setMiddleLevelObjectValue = false; snippet.AppendLine("<div class='code_line'><span class='object_declaration'>GameObject</span> <span class='variable'>middleLevelObject</span> = <span class='value'>null</span>;</div>"); snippet.AppendLine("</div><div class='code_line'>"); } string assert = RenderAssertions(true, x); switch (AutomationRecorder.RecordedActions[x].Action) { case ActableTypes.Clickable: snippet.AppendLine(GenerateClickCodeStub(AutomationRecorder.RecordedActions[x], anyAssertions, assert)); break; case ActableTypes.Input: snippet.AppendLine(GenerateInputCodeStub(AutomationRecorder.RecordedActions[x], anyAssertions, assert)); break; case ActableTypes.Scroll: snippet.AppendLine(GenerateScrollCodeStub(AutomationRecorder.RecordedActions[x], anyAssertions, assert)); break; case ActableTypes.Draggable: //TODO break; case ActableTypes.KeyDown: //TODO break; case ActableTypes.Screenshot: snippet.AppendLine(string.Format("<div class='code_line'><span class='value'><span class='value'>yield return StartCoroutine</span></span>(<span class='object_declaration'>Q</span>.driver.TakeTestScreenshot(\"{0}\"));</div>", AutomationRecorder.RecordedActions[x].Name)); break; case ActableTypes.Wait: snippet.AppendLine(string.Format("<div class='code_line'><span class='value'><span class='value'>yield return StartCoroutine</span></span>(<span class='object_declaration'>Q</span>.driver.WaitRealTime({0}f));</div>", AutomationRecorder.RecordedActions[x].Duration.ToString())); break; } snippet.AppendLine("</div>"); snippet.AppendLine(RenderAssertions(false, x)); } snippet.AppendLine("</div>"); FileBroker.CreateFileAtPath(string.Format("{0}RecordedTestCodeGen.html", FileBroker.RESOURCES_DIRECTORY), snippet.ToString()); }
static void UpdateDockPreference() { FileBroker.SaveConfig("DEFAULT_DOCK_NEXUS", System.Enum.GetName(typeof(Dock), dock)); }
void OnEnable() { //If AutomationMaster has not been initialized, we may encounter errors using the Nexus window. Attaching the AutoConsole listener will allow for more helpful explanations. if (!AutomationMaster.Initialized) { Application.logMessageReceived -= AutoConsole.GetLog; //Detach if already attached. Application.logMessageReceived += AutoConsole.GetLog; //Attach handler to recieve incoming logs. } Application.logMessageReceived += ExceptionCallback; //Windows Architect = new DependencyArchitecture(); BuddyData = new BuddyData(); Console = new RunnerConsole(); CommandConsoleView = new CommandConsoleView(); Generator = new Generator(); Results = new RunResults(); Settings = new Settings(); Tests = new TestManifest(); Tools = new AdditionalTools(); Favorites = new Favorites(); Manifest = new Manifest(); Application.runInBackground = true; EditorApplication.playmodeStateChanged += PlaymodeStateChangeUpdates; Set(); m_ShowExtraFields = new AnimBool(true); m_ShowExtraFields.valueChanged.AddListener(Repaint); //Custom defined Tab order set from Additional Tools? List <string> tabOrderData = FileBroker.GetNonUnityTextResource(FileResource.NexusTabs).Split(AutomationMaster.DELIMITER).ToList().RemoveNullAndEmpty(); Dictionary <string, int> tabData = new Dictionary <string, int>(); for (int t = 0; t < tabOrderData.Count; t++) { string[] data = tabOrderData[t].Split('$'); tabData.Add(data.First(), data.Last().ToInt()); } TabDetails tab; //Test Manager Tab. int priorityId = 0; tabData.TryGetValue(Tests.GetType().Name, out priorityId); tab = new TabDetails(Tests, priorityId > 0 ? priorityId : 1); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha1 }; tab.Tabs.Add(new SizedTab("⇊", TabSize.Small, 18)); tab.Tabs.Add(new SizedTab("Tests", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Tests View", TabSize.Large)); AddWindowTab(tab); //Automation Console Window Tab. tabData.TryGetValue(Console.GetType().Name, out priorityId); tab = new TabDetails(Console, priorityId > 0 ? priorityId : 2); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha2 }; tab.Tabs.Add(new SizedTab("✦", TabSize.Small, 18)); tab.Tabs.Add(new SizedTab("Console", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Auto Console", TabSize.Large)); tab.OverrideScroll = true; AddWindowTab(tab); //Command Console View Tab. tabData.TryGetValue(CommandConsoleView.GetType().Name, out priorityId); tab = new TabDetails(CommandConsoleView, priorityId > 0 ? priorityId : 3); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha3 }; tab.Tabs.Add(new SizedTab("☊", TabSize.Small, 22)); tab.Tabs.Add(new SizedTab("Commands", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Commands View", TabSize.Large)); tab.OverrideScroll = true; AddWindowTab(tab); //Test Results Window Tab. tabData.TryGetValue(Results.GetType().Name, out priorityId); tab = new TabDetails(Results, priorityId > 0 ? priorityId : 4); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha4 }; tab.Tabs.Add(new SizedTab("☑", TabSize.Small, TextGreen, 18)); tab.Tabs.Add(new SizedTab("Results", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Tests Results", TabSize.Large)); AddWindowTab(tab); //Generator Window Tab. tabData.TryGetValue(Generator.GetType().Name, out priorityId); tab = new TabDetails(Generator, priorityId > 0 ? priorityId : 5); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha5 }; tab.Tabs.Add(new SizedTab("●", TabSize.Small, Color.red, 26)); tab.Tabs.Add(new SizedTab("Generator", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Generator", TabSize.Large)); tab.OverrideScroll = true; AddWindowTab(tab); //Architect Hidden Tab tabData.TryGetValue(Architect.GetType().Name, out priorityId); tab = new TabDetails(Architect, priorityId > 0 ? priorityId : 6); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha6 }; tab.Tabs.Add(new SizedTab("❖", TabSize.Small, 18)); tab.Tabs.Add(new SizedTab("Dep Arc", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Dependency", TabSize.Large)); AddWindowTab(tab); //Buddy Data Hidden Tab tabData.TryGetValue(BuddyData.GetType().Name, out priorityId); tab = new TabDetails(BuddyData, priorityId > 0 ? priorityId : 7); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha7 }; tab.Tabs.Add(new SizedTab("❦", TabSize.Small, 18)); tab.Tabs.Add(new SizedTab("Buddy", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Buddy Data", TabSize.Large)); AddWindowTab(tab); //Settings Hidden Tab tabData.TryGetValue(Settings.GetType().Name, out priorityId); tab = new TabDetails(Settings, priorityId > 0 ? priorityId : 8); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha8 }; tab.Tabs.Add(new SizedTab("✎", TabSize.Small, 18)); tab.Tabs.Add(new SizedTab("Settings", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Settings", TabSize.Large)); AddWindowTab(tab); //Other Tools Tab. tab = new TabDetails(Tools, 0); tab.Shortcut = new List <KeyCode> { KeyCode.Alpha9 }; tab.Tabs.Add(new SizedTab("✙", TabSize.Small, 18)); tab.Tabs.Add(new SizedTab("Tools", TabSize.Medium)); tab.Tabs.Add(new SizedTab("Other Tools", TabSize.Large)); AddWindowTab(tab); //Favorites Tab (Reusable Test Runs). tab = new TabDetails(Favorites, -1); AddWindowTab(tab); //Manifest Tab (Current Test Run). tab = new TabDetails(Manifest, -1); AddWindowTab(tab); AddPopup(ScriptableObject.CreateInstance <SimpleAlert>()); AddPopup(ScriptableObject.CreateInstance <RunTestsAlert>()); AddPopup(ScriptableObject.CreateInstance <RunClassesAlert>()); AddPopup(ScriptableObject.CreateInstance <ConsoleMessage>()); SelectTab(SwatWindows.Find(x => x.PriorityID == 1).Window); //Sets this as the default landing on load. }
public override void Render() { GUIStyle horizontal = new GUIStyle(); horizontal.margin = new RectOffset(10, 11, 0, 0); GUIStyle statusColor = new GUIStyle(GUI.skin.label); statusColor.margin = new RectOffset(0, 0, 3, 0); statusColor.normal.textColor = AutoConsole.Paused ? Color.red : Nexus.TextGreen; statusColor.fixedWidth = 125; statusColor.fontStyle = FontStyle.Bold; GUILayout.Space(15); EditorGUILayout.BeginHorizontal(horizontal); //For "Running" notification and FPS counter. if (Application.isPlaying && AutomationMaster.Busy) { EditorGUILayout.LabelField("Running Test(s)", statusColor); } else { AutomationMaster.Busy = false; EditorGUILayout.LabelField(string.Empty, statusColor); } if (Application.isPlaying) { if (renderPasses == FPS_SAMPLE_RATE && Application.isPlaying) { fpsSample = Math.Round(1 / Time.deltaTime, 0); renderPasses = 0; } GUIStyle fps = new GUIStyle(GUI.skin.label); fps.fontSize = 26; fps.padding = new RectOffset(0, 0, -8, 0); fps.normal.textColor = GetFpsColor(fpsSample); GUILayout.FlexibleSpace(); EditorGUILayout.LabelField(string.Format("FPS {0}", fpsSample), new GUILayoutOption[] { GUILayout.Width(50) }); EditorGUILayout.LabelField(string.Format("◈", fpsSample), fps, new GUILayoutOption[] { GUILayout.Width(35) }); GUILayout.Space(-18); renderPasses++; } EditorGUILayout.EndHorizontal(); //End for "Running" notification and FPS counter. GUIStyle scrollStatus = new GUIStyle(GUI.skin.button); scrollStatus.margin = new RectOffset(0, 0, 0, 0); scrollStatus.fontStyle = _autoScroll ? FontStyle.Bold : FontStyle.Normal; scrollStatus.normal.background = Swat.ToggleButtonBackgroundSelectedTexture; scrollStatus.normal.textColor = _pubsubMode ? Nexus.TextGreen : Swat.WindowDefaultTextColor; EditorGUILayout.Space(); GUILayout.BeginHorizontal(horizontal); EditorGUILayout.LabelField(string.Format("{0} - {1}", AutoConsole.Paused ? "Paused" : "Active", AutoConsole.FilterLevel == MessageLevel.Verbose ? "Verbose" : "Abridged"), statusColor); EditorGUILayout.Space(); GUILayout.Space(-100); Nexus.Self.Button("Pubsub", "Show received Pubsub messages.", new Nexus.SwatDelegate(delegate() { _pubsubMode = !_pubsubMode; }), scrollStatus, new GUILayoutOption[] { GUILayout.Width(75), GUILayout.Height(22) }); GUILayout.Space(0.65f); scrollStatus.normal.textColor = _autoScroll ? Nexus.TextGreen : Color.red; Nexus.Self.Button("Auto Scroll", "Remove all messages in the console.", new Nexus.SwatDelegate(delegate() { _autoScroll = !_autoScroll; }), scrollStatus, new GUILayoutOption[] { GUILayout.Width(75), GUILayout.Height(22) }); GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(horizontal); GUIStyle button = new GUIStyle(GUI.skin.button); button.margin = new RectOffset(0, 0, 0, 0); button.normal.textColor = Swat.ToggleButtonTextColor; button.normal.background = Swat.ToggleButtonBackgroundTexture; Nexus.Self.Button("Clear", "Remove all messages in the console.", new Nexus.SwatDelegate(delegate() { FileBroker.SaveUnboundFile(string.Format("{0}{1}{2}/console_before_start.txt", FileBroker.BASE_NON_UNITY_PATH, ConfigReader.GetString("EDITOR_RESOURCE_CONSOLE_LOG_DIRECTORY"), GameMaster.GAME_NAME), string.Empty); AutoConsole.messageListDisplayed = new List <AutoConsoleMessage>(); AutoConsole.messageListQueued = new List <AutoConsoleMessage>(); _selectedConsoleMessage = null; }), button, new GUILayoutOption[] { GUILayout.Width(60), GUILayout.Height(22) }); GUILayout.Space(0.5f); Nexus.Self.Button(AutoConsole.Paused ? "Resume" : "Pause", "Pause/Continue rendering of new messages in the console. Messages are still received and stored when paused, and will appear immediately when resuming.", new Nexus.SwatDelegate(delegate() { AutoConsole.Paused = !AutoConsole.Paused; }), button, new GUILayoutOption[] { GUILayout.Width(60), GUILayout.Height(22) }); EditorGUILayout.Space(); Nexus.Self.Button("Verbose", "Post ALL messages from the automation framework in the console.", new Nexus.SwatDelegate(delegate() { AutoConsole.FilterLevel = MessageLevel.Verbose; if (_autoScroll) { _scroll.y = 99999; _scroll.x = 0; } }), button, new GUILayoutOption[] { GUILayout.Width(75), GUILayout.Height(22) }); GUILayout.Space(0.65f); GUIStyle abridged = new GUIStyle(GUI.skin.button); abridged.margin = new RectOffset(0, 0, 0, 0); abridged.normal.textColor = Swat.ToggleButtonTextColor; abridged.normal.background = Swat.ToggleButtonBackgroundTexture; Nexus.Self.Button("Abridged", "Post only automation messages marked as high priority in the console.", new Nexus.SwatDelegate(delegate() { AutoConsole.FilterLevel = MessageLevel.Abridged; if (_autoScroll) { _scroll.y = 99999; _scroll.x = 0; } }), abridged, new GUILayoutOption[] { GUILayout.Width(75), GUILayout.Height(22) }); GUILayout.EndHorizontal(); float messageHeight = 15; GUIStyle consoleBox = new GUIStyle(GUI.skin.box); consoleBox.fixedHeight = Nexus.Self.position.height - (Application.isPlaying ? 125 : 105); consoleBox.fixedWidth = Nexus.Self.position.width - 20; consoleBox.margin = new RectOffset(10, 0, 0, 10); consoleBox.normal.background = Swat.TabButtonBackgroundTexture; GUILayout.BeginVertical(consoleBox); //Begin box border around console. _scroll = GUILayout.BeginScrollView(_scroll); GUIStyle messageBox = new GUIStyle(GUI.skin.box); messageBox.normal.background = Swat.TabButtonBackgroundSelectedTexture; messageBox.margin = new RectOffset(2, 2, 1, 1); GUIStyle messageBoxText = new GUIStyle(GUI.skin.label); messageBoxText.normal.textColor = Swat.WindowDefaultTextColor; messageBox.fixedWidth = consoleBox.fixedWidth - 10; messageBoxText.fixedWidth = messageBox.fixedWidth - 5; string lastConsoleMessage = string.Empty; int duplicateCount = 0; List <AutoConsoleMessage> consoleMessages = AutoConsole.messageListDisplayed; for (int m = 0; m < consoleMessages.Count; m++) { if ((_pubsubMode && consoleMessages[m].messageType != ConsoleMessageType.Pubsub) || (!_pubsubMode && consoleMessages[m].messageType == ConsoleMessageType.Pubsub)) { continue; } //If this is a new console message, and auto scroll is on, scroll down automatically. if (_autoScroll && m == _lastPassConsoleMessageCount) { _scroll.y = 99999; _scroll.x = 0; } //Render only messages of the requested filter level. if (_pubsubMode || (AutoConsole.FilterLevel == MessageLevel.Abridged && consoleMessages[m].level == MessageLevel.Abridged) || AutoConsole.FilterLevel == MessageLevel.Verbose) { messageBoxText.normal.textColor = AutoConsole.MessageColor(consoleMessages[m].messageType); GUILayout.BeginHorizontal(messageBox, new GUILayoutOption[] { GUILayout.MinWidth(225), GUILayout.MaxHeight(messageHeight) }); if (lastConsoleMessage == consoleMessages[m].message) { duplicateCount++; consoleMessages.RemoveAt(m - 1); } else { lastConsoleMessage = consoleMessages[m].message; duplicateCount = 0; } if (consoleMessages.Count > m) { if (GUILayout.Button(string.Format("{0} {1}", duplicateCount > 0 ?(duplicateCount + 1).ToString() : string.Empty, consoleMessages[m].message), messageBoxText)) { if (_selectedConsoleMessage == consoleMessages[m]) { //If the message has been double-clicked, open this test failure as a single-test, temporary report. if (DateTime.Now.Subtract(_lastConsoleMessageButtonClick).TotalSeconds < 0.75d && !string.IsNullOrEmpty(consoleMessages[m].testMethod)) { if (_consoleAbridgedReportTypes.Contains(consoleMessages[m].messageType)) { _selectedConsoleMessage = null; //Prevents details panel from appearing. We only want it to appear for a single click, not a double click. AutomationReport.BuildTemporaryReportForSingleConsoleFailure(consoleMessages[m].testMethod); System.Diagnostics.Process.Start(string.Format("{0}SingleTestAsReportTemp.html", FileBroker.RESOURCES_DIRECTORY)); OpenedTestReport = DateTime.UtcNow; } } else { ConsoleMessage.Pop(_selectedConsoleMessage.message, Enum.GetName(typeof(ConsoleMessageType), _selectedConsoleMessage.messageType), Enum.GetName(typeof(MessageLevel), _selectedConsoleMessage.level), _selectedConsoleMessage.timestamp.ToString()); _selectedConsoleMessage = null; } } _selectedConsoleMessage = consoleMessages[m]; _lastConsoleMessageButtonClick = DateTime.Now; } } GUILayout.EndHorizontal(); } } _lastPassConsoleMessageCount = consoleMessages.Count; GUILayout.EndScrollView(); GUILayout.EndVertical(); }
public override void Render() { if (_showFileDeletedMessage) { if (DateTime.Now.Subtract(_fileDeletedTime).TotalSeconds > 2) { _showFileDeletedMessage = false; } } GUIStyle back = new GUIStyle(GUI.skin.button); back.fontSize = 20; back.margin = new RectOffset(25, 0, 10, 20); if (ReDrawAutomationReports) { ReDrawAutomationReports = false; if (!Directory.Exists(Path.GetDirectoryName(FileBroker.REPORTS_DIRECTORY))) { Directory.CreateDirectory(Path.GetDirectoryName(FileBroker.REPORTS_DIRECTORY)); } //Grab any report files. List <string> all = Directory.GetFiles(FileBroker.REPORTS_DIRECTORY, "report.html", SearchOption.AllDirectories).ToList(); automationReports = new List <FileInfo>(); for (int x = 0; x < all.Count; x++) { automationReports.Add(new FileInfo(all[x])); } //Grab meta files for reports. all = Directory.GetFiles(FileBroker.REPORTS_DIRECTORY, "report.meta", SearchOption.AllDirectories).ToList(); metaData = new List <KeyValuePair <string, List <KeyValuePair <string, string> > > >(); for (int m = 0; m < all.Count; m++) { FileInfo info = new FileInfo(all[m]); string[] metaLines = FileBroker.ReadUnboundFile(info.FullName); List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >(); for (int ml = 0; ml < metaLines.Length; ml++) { string[] keyVals = metaLines[ml].Split(':'); values.Add(new KeyValuePair <string, string>(keyVals[0], keyVals[1])); } metaData.Add(new KeyValuePair <string, List <KeyValuePair <string, string> > >(all[m].Split(new string[] { string.Format("{0}{1}", GameMaster.GAME_NAME, FileBroker.FILE_PATH_SPLIT) }, StringSplitOptions.None)[1].Replace(string.Format("{0}report.meta", FileBroker.FILE_PATH_SPLIT), ".html"), values)); } automationReports.Reverse(); } if (!automationReports.Any()) { GUIStyle noResults = new GUIStyle(GUI.skin.label); noResults.padding = new RectOffset(10, 0, 0, 0); noResults.fontSize = 14; noResults.normal.textColor = Color.blue; GUILayout.Space(20); EditorGUILayout.LabelField("No test reports currently exist.", noResults); return; } Color32 boxGreen = new Color32(20, 175, 0, 255); GUIStyle fileLabel = new GUIStyle(GUI.skin.label); fileLabel.normal.textColor = boxGreen; fileLabel.padding = new RectOffset(32, 0, 0, 1); GUIStyle fileNameButton = new GUIStyle(GUI.skin.button); fileNameButton.margin = new RectOffset(35, 0, 0, 0); fileNameButton.normal.background = fileNameButton.active.background = fileNameButton.focused.background = Swat.TabButtonBackgroundTexture; fileNameButton.normal.textColor = Swat.WindowDefaultTextColor; GUIStyle deleteFileButton = new GUIStyle(GUI.skin.button); deleteFileButton.normal.textColor = Color.red; deleteFileButton.fontSize = 14; deleteFileButton.margin = new RectOffset(1, 0, 0, 5); deleteFileButton.normal.background = deleteFileButton.active.background = deleteFileButton.focused.background = Swat.TabButtonBackgroundTexture; deleteFileButton.normal.textColor = Color.red; GUIStyle divider = new GUIStyle(GUI.skin.box); divider.normal.background = Swat.MakeTextureFromColor(boxGreen); divider.margin = new RectOffset(35, 10, 10, 10); GUIStyle deleteAllButton = new GUIStyle(GUI.skin.button); deleteAllButton.fontSize = 12; deleteAllButton.normal.textColor = Color.red; deleteAllButton.fontStyle = FontStyle.Bold; deleteAllButton.fixedHeight = 38; deleteAllButton.margin = new RectOffset(0, 25, 5, 0); deleteAllButton.normal.background = deleteAllButton.active.background = deleteAllButton.focused.background = Swat.TabButtonBackgroundTexture; deleteAllButton.normal.textColor = Color.red; GUILayout.Space(20); GUIStyle padding = new GUIStyle(); padding.margin = new RectOffset(25, 0, 0, 0); GUILayout.BeginHorizontal(padding); EditorGUILayout.Space(); if (_showFileDeletedMessage) { GUIStyle deleteFileAlert = new GUIStyle(GUI.skin.label); deleteFileAlert.normal.textColor = Color.red; deleteFileAlert.fontSize = 14; deleteFileAlert.fixedHeight = 28; deleteFileAlert.padding = new RectOffset(30, 0, 14, 0); EditorGUILayout.LabelField("Deleted!", deleteFileAlert); } EditorGUILayout.Space(); if (GUILayout.Button("Delete All", deleteAllButton, new GUILayoutOption[] { GUILayout.Height(30), GUILayout.Width(75) })) { SimpleAlert.Pop("Are you sure you want to delete all stored test run reports?", new EditorDelegate(DeleteAll)); } GUILayout.EndHorizontal(); GUILayout.Space(20); for (int ar = 0; ar < automationReports.Count; ar++) { bool isNewest = ar == 0; string[] splitTime = automationReports[ar].CreationTime.ToShortTimeString().Split(':'); int hour = int.Parse(splitTime[0]); bool am = true; if (hour >= 12) { am = false; if (hour != 12) { hour -= 12; } } if (!isNewest) { fileNameButton.normal.textColor = fileLabel.normal.textColor = Swat.WindowDefaultTextColor; } string timeOfDay = string.Format("{0}:{1} {2}", hour.ToString(), splitTime[1], am ? "AM" : "PM"); if (isNewest) { EditorGUILayout.LabelField("-----Newest-----", fileLabel); } EditorGUILayout.LabelField(string.Format("{0} {1}", automationReports[ar].CreationTime.ToLongDateString(), timeOfDay), fileLabel); List <KeyValuePair <string, List <KeyValuePair <string, string> > > > matchMetaResults = metaData.FindAll(x => automationReports[ar].Directory.ToString().Contains(x.Key.Replace(".html", string.Empty))); if (matchMetaResults.Any()) { KeyValuePair <string, List <KeyValuePair <string, string> > > matchMeta = matchMetaResults.First(); EditorGUILayout.LabelField(string.Format("{0}:{1} {2}:{3} {4}:{5} {6}:{7}", TestManifest.PASSED, matchMeta.Value.Find(x => x.Key == "Passes").Value, TestManifest.FAILED, matchMeta.Value.Find(x => x.Key == "Fails").Value, TestManifest.SKIPPED, matchMeta.Value.Find(x => x.Key == "Skips").Value, TestManifest.IGNORED, matchMeta.Value.Find(x => x.Key == "Ignores").Value), fileLabel); if (Nexus.Self.MouseOver()) { Nexus.Self.SetToolTip(matchMeta.Value.Find(x => x.Key == "RunCommand").Value.Replace(",", "\n")); } } if (isNewest) { GUILayout.Box(string.Empty, divider, new GUILayoutOption[] { GUILayout.Height(1), GUILayout.Width(180) }); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Open Report", fileNameButton, new GUILayoutOption[] { GUILayout.Height(30), GUILayout.Width(150) })) { System.Diagnostics.Process.Start(automationReports[ar].FullName); } if (GUILayout.Button("X", deleteFileButton, new GUILayoutOption[] { GUILayout.Height(30), GUILayout.Width(30) })) { //Delete report and associated meta file. Directory.Delete(automationReports[ar].Directory.ToString().Replace("/report.html", string.Empty), true); ReDrawAutomationReports = true; _fileDeletedTime = DateTime.Now; _showFileDeletedMessage = true; } GUILayout.EndHorizontal(); if (isNewest) { GUILayout.Box(string.Empty, divider, new GUILayoutOption[] { GUILayout.Height(1), GUILayout.Width(180) }); } EditorGUILayout.Space(); EditorGUILayout.Space(); } }
public static List <string> GetBuddyHistory() { string txt = FileBroker.GetNonUnityTextResource(FileResource.BuddyHistory); return(txt.Split(new string[] { "\n" }, StringSplitOptions.None).ToList().FindAll(x => x.Length > 0)); }
public static void GetMostRecentsResults(string status = "", string plainText = "") { _testsMeta = new List <KeyValuePair <string, string[]> >(); //TODO: Remove tests from file that no longer are automation tests. bool skipCreate = string.IsNullOrEmpty(status); List <string> resultsRaw = new List <string>(); string txt = FileBroker.GetNonUnityTextResource(FileResource.LatestTestResults); resultsRaw = txt.Split(new string[] { "\n" }, StringSplitOptions.None).ToList(); if (resultsRaw.Count == 0 && !skipCreate) { fileText.AppendLine(plainText); } else { List <Type> currentClasses = AutomationMaster.GetAutomationClasses(); List <MethodInfo> currentMethods = new List <MethodInfo>(); currentClasses.ForEach(x => currentMethods.AddRange(x.GetMethods())); //Filter out tests that no longer exist, have been renamed, or are no longer marked as automation methods. currentMethods = currentMethods.FindAll(x => { Automation[] aut = (Automation[])Attribute.GetCustomAttributes(x, typeof(Automation)); return(aut != null && aut.Length > 0); }); for (int i = 0; i < resultsRaw.Count; i++) { if (!string.IsNullOrEmpty(resultsRaw[i])) { string[] row = resultsRaw[i].Split(AutomationMaster.DELIMITER); string testName = string.Empty; for (int r = 0; r < row.Length; r++) { string[] keyVal = row[r].Split(':'); if (keyVal[0] == "name") { testName = keyVal[1]; } } if (!string.IsNullOrEmpty(testName)) { //Ignore references to methods that are no longer valid automation methods for whatever reason. if (currentMethods.FindAll(x => x.Name == testName).Any()) { _testsMeta.Add(new KeyValuePair <string, string[]>(testName, row)); } } } } if (!skipCreate) { List <KeyValuePair <string, string[]> > matches = testsMeta.FindAll(x => x.Key == AutomationMaster.CurrentTestContext.TestName); if (!matches.Any()) { _testsMeta.Add(new KeyValuePair <string, string[]>(AutomationMaster.CurrentTestContext.TestName, plainText.Split(AutomationMaster.DELIMITER))); } else { _testsMeta.Remove(matches.First()); string[] newValues = new string[] { string.Format("status:{0}", status), string.Format("name:{0}", AutomationMaster.CurrentTestContext.TestName), string.Format("class:{0}", AutomationMaster.CurrentTestContext.ClassName), string.Format("test_categories:{0}", string.Join(",", AutomationMaster.CurrentTestContext.Categories.ToArray())), }; KeyValuePair <string, string[]> newInsert = new KeyValuePair <string, string[]>(AutomationMaster.CurrentTestContext.TestName, newValues); _testsMeta.Add(newInsert); } for (int f = 0; f < testsMeta.Count; f++) { fileText.AppendLine(string.Join(AutomationMaster.DELIMITER.ToString(), _testsMeta[f].Value)); } } } }