// returns the index of the specific tag - keyword / test cases / settings / variables public static List <Variables> ReadAllVariables() { var listOfVariables = new List <Variables>(); foreach (var fileName in FilesAndFolderStructure.GetFullSavedFiles(FolderType.Root)) { if (!File.Exists(fileName)) { continue; } var arrLine = File.ReadAllLines(fileName); var index = RobotFileHandler.HasTag(fileName, FormType.Variable); if (index == -1) { continue; } var names = new List <string>(); for (int i = index + 1; i < arrLine.Length; i++) { if (arrLine[i].StartsWith("***")) { break; } if (arrLine[i].Trim().Length == 0) { continue; } if (StringAndListOperations.StartsWithVariable(arrLine[i].Trim())) { names.Add(arrLine[i].Trim()); } } if (names.Count == 0) { continue; } var currentSuiteSettings = new Variables(names, fileName); listOfVariables.Add(currentSuiteSettings); } return(listOfVariables); }
// returns the index of the specific tag - keyword / test cases / settings / variables public List <SuiteSettings> ReadSettingsFromFile() { var suiteSettings = new List <SuiteSettings>(); foreach (var fileName in FilesAndFolderStructure.GetFullSavedFiles(FolderType.Tests)) { var currentSuiteSettings = new SuiteSettings(fileName.Replace(FilesAndFolderStructure.GetFolder(FolderType.Root), "")) { Documentation = RobotFileHandler.OccurenceInSettings(fileName, "Documentation").Replace("Documentation", "").Trim(), TestSetup = new Keyword(RobotFileHandler.OccurenceInSettings(fileName, "Test Setup").Replace("Test Setup", "").Trim(), fileName, libraries, null) }; currentSuiteSettings.TestTeardown = new Keyword(RobotFileHandler.OccurenceInSettings(fileName, "Test Teardown").Replace("Test Teardown", "").Trim(), fileName, libraries, null); currentSuiteSettings.SuiteSetup = new Keyword(RobotFileHandler.OccurenceInSettings(fileName, "Suite Setup").Replace("Suite Setup", "").Trim(), fileName, libraries, null); currentSuiteSettings.SuiteTeardown = new Keyword(RobotFileHandler.OccurenceInSettings(fileName, "Suite Teardown").Replace("Suite Teardown", "").Trim(), fileName, libraries, null); currentSuiteSettings.Overwrite = true; suiteSettings.Add(currentSuiteSettings); } return(suiteSettings); }
private void SaveToRobotToolStripMenuItem_Click(object sender, EventArgs e) { WriteToRobot.Includes = new List <Includes>(); //Cleanup FilesAndFolderStructure.DeleteAllFiles(); TestCases.Sort(); foreach (var testCase in TestCases) { WriteToRobot.AddTestCaseToRobot(testCase); } Console.WriteLine(@"WriteSuiteSettingsListToRobot ==============================="); WriteToRobot.WriteSuiteSettingsListToRobot(); Console.WriteLine(@"WriteIncludesToRobotFiles ==================================="); WriteToRobot.WriteIncludesToRobotFiles(); Console.WriteLine(@"WriteVariablesToRobotFiles ==================================="); WriteToRobot.WriteVariablesToRobotFiles(); foreach (var fileName in FilesAndFolderStructure.GetShortSavedFiles(FolderType.Root)) { RobotFileHandler.TrimFile(FilesAndFolderStructure.ConcatFileNameToFolder(fileName, FolderType.Root)); } }
private void SetupsSettingsAddForm() { UpdateOutputFileSuggestions(OutputFile, FormType); OutputFile.SelectedIndex = _selectedIndex; foreach (var fileName in FilesAndFolderStructure.GetShortSavedFiles(FolderType.Root)) { var add = true; if (RobotAutomationHelper.SuiteSettingsList.Count != 0) { foreach (var temp in RobotAutomationHelper.SuiteSettingsList) { if (!temp.ToString().Equals(fileName)) { continue; } add = false; break; } } if (add) { RobotAutomationHelper.SuiteSettingsList.Add(new SuiteSettings(fileName)); } } ActiveControl = AddSettingsLabel; foreach (var temp in RobotAutomationHelper.SuiteSettingsList) { if (temp.ToString().Equals(OutputFile.Items[OutputFile.SelectedIndex])) { CurrentSuiteSettings = temp; break; } } var folderType = FolderType.Root; if (CurrentSuiteSettings.OutputFilePath.Contains(FilesAndFolderStructure.Resources)) { folderType = FolderType.Resources; } if (CurrentSuiteSettings.OutputFilePath.Contains(FilesAndFolderStructure.Tests)) { folderType = FolderType.Tests; } if (!CurrentSuiteSettings.Overwrite) { var realOutput = CurrentSuiteSettings.OutputFilePath; switch (folderType) { case FolderType.Tests: realOutput = realOutput.Remove(0, 5); break; case FolderType.Resources: realOutput = realOutput.Remove(0, 9); break; case FolderType.Root: break; default: throw new ArgumentOutOfRangeException(); } CurrentSuiteSettings.Documentation = RobotFileHandler.OccurenceInSettings(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root), "Documentation").Replace("Documentation", "").Trim(); CurrentSuiteSettings.TestSetup = new Keyword(RobotFileHandler.OccurenceInSettings(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root), "Test Setup").Replace("Test Setup", "").Trim(), realOutput, ReadRobotFiles.GetLibs(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root)), null); CurrentSuiteSettings.TestTeardown = new Keyword(RobotFileHandler.OccurenceInSettings(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root), "Test Teardown").Replace("Test Teardown", "").Trim(), realOutput, ReadRobotFiles.GetLibs(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root)), null); CurrentSuiteSettings.SuiteSetup = new Keyword(RobotFileHandler.OccurenceInSettings(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root), "Suite Setup").Replace("Suite Setup", "").Trim(), realOutput, ReadRobotFiles.GetLibs(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root)), null); CurrentSuiteSettings.SuiteTeardown = new Keyword(RobotFileHandler.OccurenceInSettings(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root), "Suite Teardown").Replace("Suite Teardown", "").Trim(), realOutput, ReadRobotFiles.GetLibs(FilesAndFolderStructure.ConcatFileNameToFolder(CurrentSuiteSettings.OutputFilePath, FolderType.Root)), null); } ThisFormKeywords = new List <Keyword>(); if (CurrentSuiteSettings.TestSetup == null) { CurrentSuiteSettings.TestSetup = new Keyword("", "Auto.robot", null); } ThisFormKeywords.Add(CurrentSuiteSettings.TestSetup); if (CurrentSuiteSettings.TestTeardown == null) { CurrentSuiteSettings.TestTeardown = new Keyword("", "Auto.robot", null); } ThisFormKeywords.Add(CurrentSuiteSettings.TestTeardown); if (CurrentSuiteSettings.SuiteSetup == null) { CurrentSuiteSettings.SuiteSetup = new Keyword("", "Auto.robot", null); } ThisFormKeywords.Add(CurrentSuiteSettings.SuiteSetup); if (CurrentSuiteSettings.SuiteTeardown == null) { CurrentSuiteSettings.SuiteTeardown = new Keyword("", "Auto.robot", null); } ThisFormKeywords.Add(CurrentSuiteSettings.SuiteTeardown); SuiteDocumentation.Text = CurrentSuiteSettings.Documentation; if (folderType != FolderType.Tests) { return; } for (var i = 1; i <= 4; i++) { if (Controls["DynamicStep" + i + "Name"] != null) { Controls["DynamicStep" + i + "Name"].Text = ThisFormKeywords[i - 1].Name; } else { AddKeywordField(ThisFormKeywords[i - 1], i, false, false); } } }
private static void AddKeywordsFromKeyword(Keyword keyword, List <string> filesList) { foreach (var fileName in filesList) { var continueLoop = !(keyword.IncludeImportFile && !fileName.Contains(keyword.ImportFileName + ".robot")); if (!continueLoop) { continue; } var index = RobotFileHandler.LocationOfTestCaseOrKeywordInFile(fileName, keyword.Name == null? "":keyword.Name.Trim(), FormType.Keyword); if (index == -1) { continue; } keyword.OutputFilePath = fileName; var arrLine = File.ReadAllLines(fileName); for (var i = index; i < arrLine.Length; i++) { if (!arrLine[i].StartsWith(" ") && !arrLine[i].StartsWith("\t") && !arrLine[i].Trim().Equals("")) { if (i != index) { break; } keyword.Name = arrLine[i]; } else if (!arrLine[i].Trim().Equals("")) { if (arrLine[i].Trim().StartsWith("[Documentation]")) { keyword.Documentation = arrLine[i]; } else if (arrLine[i].Trim().StartsWith("[Arguments]")) { var j = i; var multiLine = ""; if (i + 1 < arrLine.Length) { while (arrLine[i + 1].Trim().StartsWith("...")) { multiLine += " " + arrLine[i + 1].Replace("...", ""); i++; if (i + 1 >= arrLine.Length) { break; } } multiLine.TrimEnd(); } var splitKeyword = (arrLine[j] + multiLine).Replace("[Arguments]", "").Trim().Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries); for (var counter = 0; counter < splitKeyword.Length; counter++) { if (!splitKeyword[counter].Contains("=")) { if (keyword.Params != null) { keyword.Params[counter].Name = splitKeyword[counter]; } else { keyword.Params = new List <Param>() { new Param(splitKeyword[counter], "") }; } } else { // check if after splitting the first string matches any param name var temp = splitKeyword[counter].Split('='); var toAdd = true; foreach (var par in keyword.Params) { if (!par.Name.Equals(temp[0])) { continue; } toAdd = false; break; } if (toAdd) { keyword.Params.Add(new Param(temp[0], temp[1])); } } } keyword.Arguments = arrLine[j]; } else { var j = i; var multiLine = ""; if (i + 1 < arrLine.Length) { while (arrLine[i + 1].Trim().StartsWith("...")) { multiLine += " " + arrLine[i + 1].Replace("...", ""); i++; if (i + 1 >= arrLine.Length) { break; } } multiLine.TrimEnd(); } if (keyword.Keywords == null) { keyword.Keywords = new List <Keyword>(); } if (!arrLine[j].Trim().ToLower().StartsWith(":for") && !arrLine[j].Trim().ToLower().StartsWith("\\")) { keyword.Keywords.Add(new Keyword(arrLine[j] + multiLine, FilesAndFolderStructure.GetFolder(FolderType.Resources) + "Auto.robot", GetLibs(fileName), keyword)); if (keyword.Keywords[keyword.Keywords.Count - 1].IsRecursive(keyword.Keywords[keyword.Keywords.Count - 1])) { keyword.Keywords[keyword.Keywords.Count - 1].Recursive = true; } else { AddKeywordsFromKeyword(keyword.Keywords[keyword.Keywords.Count - 1], GetResourcesFromFile(fileName)); } } else { if (arrLine[j].Trim().ToLower().StartsWith(":for")) { if (arrLine[j].Trim().ToLower().Contains("range")) { var temp = new Keyword(keyword); temp.CopyKeyword(SuggestionsClass.GetForLoop(KeywordType.ForLoopInRange)); var splitKeyword = arrLine[j].Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries); if (splitKeyword.Length == 1) { splitKeyword = arrLine[j].Split(new [] { "\t" }, StringSplitOptions.RemoveEmptyEntries); } temp.Params[0].Value = splitKeyword[1]; temp.Params[1].Value = splitKeyword[3]; temp.Params[2].Value = splitKeyword[4]; keyword.Keywords.Add(temp); keyword.Keywords[keyword.Keywords.Count - 1].ForLoopKeywords = new List <Keyword>(); } else { var temp = new Keyword(keyword); temp.CopyKeyword(SuggestionsClass.GetForLoop(KeywordType.ForLoopElements)); var splitKeyword = arrLine[j].Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries); if (splitKeyword.Length == 1) { splitKeyword = arrLine[j].Split(new [] { "\t" }, StringSplitOptions.RemoveEmptyEntries); } temp.Params[0].Value = splitKeyword[1]; temp.Params[1].Value = splitKeyword[3]; keyword.Keywords.Add(temp); keyword.Keywords[keyword.Keywords.Count - 1].ForLoopKeywords = new List <Keyword>(); } } else { keyword.Keywords[keyword.Keywords.Count - 1].ForLoopKeywords.Add( new Keyword(arrLine[j].Trim().Remove(0, 1).Trim(), FilesAndFolderStructure.GetFolder(FolderType.Resources) + "Auto.robot", GetLibs(fileName), keyword)); if (keyword.Keywords[keyword.Keywords.Count - 1].IsRecursive(keyword.Keywords[keyword.Keywords.Count - 1])) { keyword.Keywords[keyword.Keywords.Count - 1].Recursive = true; } else { AddKeywordsFromKeyword(keyword.Keywords[keyword.Keywords.Count - 1].ForLoopKeywords[keyword.Keywords[keyword.Keywords.Count - 1].ForLoopKeywords.Count - 1], GetResourcesFromFile(fileName)); } } } } } } break; } }