private void Save_Click(object sender, EventArgs e) { var formParams = new List <Param>(); for (var i = 1; i <= ParamsCount; i++) { formParams.Add(new Param(Controls["DynamicStep" + i + "ParamName"].Text, Controls["DynamicStep" + i + "ParamValue"].Text)); } if (_кeyword.Type.Equals(KeywordType.ForLoopElements) || _кeyword.Type.Equals(KeywordType.ForLoopInRange)) { if (ThisFormKeywords != null && ThisFormKeywords.Count != 0) { _кeyword.ForLoopKeywords = new List <Keyword>(); foreach (var step in ThisFormKeywords) { var temp = new Keyword(step.Parent); temp.CopyKeyword(step); _кeyword.ForLoopKeywords.Add(temp); } } } _кeyword.Params = formParams; Close(); }
private static void OverwriteOccurrencesInChildrenKeywords(string name, Keyword keyword, string fileName, Keyword thisKeyword) { if (!ReferenceEquals(keyword, thisKeyword) && keyword.Implemented && keyword.Name.Trim().ToLower().Equals(name.ToLower()) && keyword.OutputFilePath.ToLower().Equals(fileName.ToLower())) { if (keyword.SuggestionIndex == thisKeyword.SuggestionIndex) { keyword.CopyKeyword(thisKeyword); } } if (keyword.Keywords != null) { foreach (var key in keyword.Keywords) { if (!key.Recursive) { OverwriteOccurrencesInChildrenKeywords(name, key, fileName, thisKeyword); } } } }
private static void KeywordToSuggestions(Keyword tempKeyword) { //TODO if (tempKeyword.Name.ToLower().Equals("[return]")) { return; } if (tempKeyword.Name.Equals("")) { return; } if (tempKeyword.SuggestionIndex == -1 && !tempKeyword.OutputFilePath.Equals("") && !StringAndListOperations.StartsWithVariable(tempKeyword.Name)) { var toAdd = true; foreach (var lib in SuggestionsClass.Suggestions) { if (lib.ToInclude) { foreach (var suggested in lib.LibKeywords) { if (!suggested.Name.ToLower().Equals(tempKeyword.Name.ToLower())) { continue; } if (lib.Name.Equals("Custom") && !suggested.OutputFilePath.ToLower().Equals(tempKeyword.OutputFilePath.ToLower())) { continue; } toAdd = false; break; } } } if (toAdd) { tempKeyword.SuggestionIndex = SuggestionsClass.GetLibKeywordsByName("Custom").Count; Keyword temp = new Keyword(null); temp.CopyKeyword(tempKeyword); if (temp.Params != null && temp.Params.Count > 0) { foreach (Param param in temp.Params) { if (!temp.Arguments.ToLower().Contains(param.Name + @"=" + param.Value)) { param.Value = ""; } } } SuggestionsClass.GetLibKeywordsByName("Custom").Add(temp); } } if (tempKeyword.Keywords != null) { foreach (var nestedKeyword in tempKeyword.Keywords) { KeywordToSuggestions(nestedKeyword); } } if (tempKeyword.ForLoopKeywords == null) { return; } { foreach (var nestedKeyword in tempKeyword.ForLoopKeywords) { KeywordToSuggestions(nestedKeyword); } } }
// adds all field data to parentKeyword or testCaseAddForm if not nested private void SaveChangesToKeyword() { var finalPath = FilesAndFolderStructure.ConcatFileNameToFolder(OutputFile.Text, FolderType.Resources); var args = StringAndListOperations.ReturnListOfArgs(KeywordArguments.Text); if (args != null) { foreach (var arg in args) { if (_parentKeywords[ImplementationIndexFromTheParent].Params != null && (_parentKeywords[ImplementationIndexFromTheParent].Params.Count > 0)) { var foundMatch = false; foreach (var parentParam in _parentKeywords[ImplementationIndexFromTheParent].Params) { if (parentParam.Name.Equals(arg)) { _thisKeywordParams.Add(parentParam); foundMatch = true; break; } } if (!foundMatch) { _thisKeywordParams.Add(new Param(arg, "")); } } else { _thisKeywordParams.Add(new Param(arg, "")); } } } var addToSuggestions = _parentKeywords[ImplementationIndexFromTheParent].SuggestionIndex == -1; _parentKeywords[ImplementationIndexFromTheParent] = new Keyword(KeywordName.Text.Trim(), "[Documentation] " + KeywordDocumentation.Text.Trim(), ThisFormKeywords, "[Arguments] " + KeywordArguments.Text.Trim(), _thisKeywordParams, finalPath, KeywordType.Custom, _parentKeywords[ImplementationIndexFromTheParent].SuggestionIndex, "Custom", _parentKeywords[ImplementationIndexFromTheParent].Parent, _parentKeywords[ImplementationIndexFromTheParent].IncludeImportFile); if (addToSuggestions) { _parentKeywords[ImplementationIndexFromTheParent].SuggestionIndex = SuggestionsClass.GetLibKeywordsByName("Custom").Count; var temp = new Keyword(_parentKeywords[ImplementationIndexFromTheParent].Parent); temp.CopyKeyword(_parentKeywords[ImplementationIndexFromTheParent]); //CopyKeyword SuggestionsClass.GetLibKeywordsByName("Custom").Add(temp); } else { SuggestionsClass.GetLibKeywordsByName("Custom")[_parentKeywords[ImplementationIndexFromTheParent].SuggestionIndex].CopyKeyword(_parentKeywords[ImplementationIndexFromTheParent]); //CopyKeyword } }
// returns the index of the specific tag - keyword / test cases / settings / variables public List <TestCase> GetTheDataFromAllTheRobotFiles() { var testCases = new List <TestCase>(); var listOfVariables = new List <Variables>(); foreach (RobotFile currentFile in RobotFiles) { if (currentFile.TestCasesList != null && currentFile.TestCasesList.Count > 0) { foreach (TestCase currentTestCase in currentFile.TestCasesList) { var tempTestCase = new TestCase(currentTestCase.Name, currentFile.fileName) { Steps = new List <Keyword>() }; if (currentTestCase.Steps != null && currentTestCase.Steps.Count > 0) { foreach (Keyword currentKeyword in currentTestCase.Steps) { var tempKeyword = new Keyword(null); if (currentKeyword.Type == KeywordType.Custom) { tempKeyword.CopyKeyword(currentKeyword); if (currentKeyword.ImportFileName != null && !currentKeyword.ImportFileName.Equals("")) { foreach (RobotFile importFile in RobotFiles) { if (importFile.fileName.EndsWith("\\" + currentKeyword.ImportFileName + ".robot")) { foreach (Keyword importKeyword in importFile.KeywordsList) { if (importKeyword.Name.Equals(currentKeyword.Name)) { if (currentKeyword.Params != null && currentKeyword.Params.Count > 0) { for (int i = 0; i < currentKeyword.Params.Count; i++) { tempKeyword.Params[i].Name = importKeyword.Params[i].Name; } } tempKeyword.Keywords.AddRange(importKeyword.Keywords); tempKeyword.OutputFilePath = importFile.fileName; break; } } break; } } } else { bool isFound = false; foreach (string fileName in currentFile.resources) { foreach (RobotFile importFile in RobotFiles) { if (importFile.fileName.Equals(fileName)) { foreach (Keyword importKeyword in importFile.KeywordsList) { if (importKeyword.Name.Equals(currentKeyword.Name)) { if (currentKeyword.Params != null && currentKeyword.Params.Count > 0) { for (int i = 0; i < currentKeyword.Params.Count; i++) { tempKeyword.Params[i].Name = importKeyword.Params[i].Name; } } tempKeyword.Keywords.AddRange(importKeyword.Keywords); tempKeyword.OutputFilePath = importFile.fileName; isFound = true; break; } } break; } } if (isFound) { break; } } } if (tempKeyword.Keywords != null && tempKeyword.Keywords.Count > 0) { tempKeyword.CopyKeyword(GetDataForInternalKeywords(tempKeyword, currentFile)); } } else { tempKeyword.CopyKeyword(currentKeyword); } tempTestCase.Steps.Add(tempKeyword); } } testCases.Add(tempTestCase); } } } return(testCases); }
public Keyword GetDataForInternalKeywords(Keyword keyword, RobotFile file) { var returnKeyword = new Keyword(keyword.Parent); returnKeyword.CopyKeyword(keyword); returnKeyword.Keywords = new List <Keyword>(); foreach (Keyword currentKeyword in keyword.Keywords) { var tempKeyword = new Keyword(keyword); tempKeyword.CopyKeyword(currentKeyword); if (currentKeyword.Type == KeywordType.Custom) { if (currentKeyword.ImportFileName != null && !currentKeyword.ImportFileName.Equals("")) { foreach (RobotFile importFile in RobotFiles) { if (importFile.fileName.EndsWith("\\" + currentKeyword.ImportFileName + ".robot")) { foreach (Keyword importKeyword in importFile.KeywordsList) { if (importKeyword.Name.Equals(currentKeyword.Name)) { if (currentKeyword.Params != null && currentKeyword.Params.Count > 0) { for (int i = 0; i < currentKeyword.Params.Count; i++) { tempKeyword.Params[i].Name = importKeyword.Params[i].Name; } } tempKeyword.Keywords.AddRange(importKeyword.Keywords); tempKeyword.OutputFilePath = importFile.fileName; break; } } break; } } } else { bool isFound = false; foreach (string fileName in file.resources) { foreach (RobotFile importFile in RobotFiles) { if (importFile.fileName.Equals(fileName)) { foreach (Keyword importKeyword in importFile.KeywordsList) { if (importKeyword.Name.Equals(currentKeyword.Name)) { if (currentKeyword.Params != null && currentKeyword.Params.Count > 0) { for (int i = 0; i < currentKeyword.Params.Count; i++) { tempKeyword.Params[i].Name = importKeyword.Params[i].Name; } } tempKeyword.Keywords.AddRange(importKeyword.Keywords); tempKeyword.OutputFilePath = importFile.fileName; isFound = true; break; } } break; } } if (isFound) { break; } } } if (tempKeyword.Keywords != null && tempKeyword.Keywords.Count > 0) { foreach (RobotFile importFile in RobotFiles) { if (importFile.fileName.Equals(tempKeyword.OutputFilePath)) { GetDataForInternalKeywords(tempKeyword, importFile); break; } } } } returnKeyword.Keywords.Add(tempKeyword); } return(returnKeyword); }
private void CheckKeywordTypeAndEvaluateKeywordData(Keyword keyword, string name, string keywordType) { if (RobotAutomationHelper.Log) { Console.WriteLine(@"CheckKeywordTypeAndReturnKeyword " + keyword.Name + @" " + name); } foreach (var lib in SuggestionsClass.Suggestions) { if (lib.ToInclude) { foreach (var suggestedKeyword in lib.LibKeywords) { if (keywordType != null && keywordType.StartsWith("[")) { if (keyword.GetTypeBasedOnSuggestionStart(keywordType) != suggestedKeyword.Type) { break; } } if (!suggestedKeyword.Name.Trim().ToLower().Equals(name.ToLower())) { continue; } if (!keyword.Name.Trim().ToLower().Equals(name.Trim().ToLower()) || !keyword.Type.Equals(suggestedKeyword.Type)) { keyword.CopyKeyword(suggestedKeyword); } else if (!keyword.Implemented) { keyword.CopyKeyword(suggestedKeyword); } return; } } } if (keyword.Type != KeywordType.Custom) { keyword.CopyKeyword(new Keyword(name, FilesAndFolderStructure.GetFolder(FilesAndFolderStructure.ConvertFormTypeToFolderType(FormType)) + "Auto.robot", keyword.Parent)); //CopyKeyword keyword.Type = KeywordType.Custom; return; } foreach (var lib in SuggestionsClass.Suggestions) { if (lib.ToInclude) { foreach (var seleniumKeyword in lib.LibKeywords) { if (seleniumKeyword.Name.Trim().ToLower().Equals(keyword.Name.Trim().ToLower())) { keyword.CopyKeyword(new Keyword(name, FilesAndFolderStructure.GetFolder(FilesAndFolderStructure.ConvertFormTypeToFolderType(FormType)) + "Auto.robot", keyword.Parent)); //CopyKeyword keyword.Type = KeywordType.Custom; return; } } } } keyword.Name = name; keyword.Type = KeywordType.Custom; }
// returns the index of the specific tag - keyword / test cases / settings / variables public static List <TestCase> ReadAllTests() { _testCases = new List <TestCase>(); _currentTestCaseTestSteps = new List <Keyword>(); _currentTestCase = ""; foreach (var fileName in FilesAndFolderStructure.GetFullSavedFiles(FolderType.Tests)) { if (!File.Exists(fileName)) { continue; } var arrLine = File.ReadAllLines(fileName); if (arrLine.Length == 0) { continue; } var start = false; for (var i = 0; i < arrLine.Length; i++) { if (start && arrLine[i].StartsWith("***")) { if (!_currentTestCase.Equals("")) { //Setup test creation for previous Test case AddTestCaseAndResetValues(fileName); _currentTestCase = !_currentTestCase.Equals(arrLine[i]) ? arrLine[i] : ""; } else { _currentTestCase = arrLine[i]; } break; } if (start && !arrLine[i].StartsWith(" ") && !arrLine[i].StartsWith("\t") && !arrLine[i].Trim().Equals("")) { if (_currentTestCase != "") { AddTestCaseAndResetValues(fileName); } _currentTestCase = arrLine[i]; } else { if (start && !arrLine[i].Trim().Equals("")) { if (arrLine[i].Trim().StartsWith("[Documentation]")) { _currentTestCaseDocumentation = arrLine[i]; } else if (arrLine[i].Trim().StartsWith("[Tags]")) { _currentTestCaseTags = arrLine[i]; } else { if (!arrLine[i].Trim().ToLower().StartsWith(":for") && !arrLine[i].Trim().ToLower().StartsWith("\\")) { 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(); } _currentTestCaseTestSteps.Add(new Keyword(arrLine[j] + multiLine, FilesAndFolderStructure.GetFolder(FolderType.Resources) + "Auto.robot", GetLibs(fileName), null)); AddKeywordsFromKeyword(_currentTestCaseTestSteps[_currentTestCaseTestSteps.Count - 1], GetResourcesFromFile(fileName)); } else { if (arrLine[i].Trim().ToLower().StartsWith(":for")) { if (arrLine[i].Trim().ToLower().Contains("range")) { var temp = new Keyword(null); temp.CopyKeyword(SuggestionsClass.GetForLoop(KeywordType.ForLoopInRange)); var splitKeyword = arrLine[i].Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries); if (splitKeyword.Length == 1) { splitKeyword = arrLine[i].Split(new [] { "\t" }, StringSplitOptions.RemoveEmptyEntries); } if (splitKeyword.Length >= 5) { temp.Params[0].Value = splitKeyword[1]; temp.Params[1].Value = splitKeyword[3]; temp.Params[2].Value = splitKeyword[4]; } _currentTestCaseTestSteps.Add(temp); _currentTestCaseTestSteps[_currentTestCaseTestSteps.Count - 1].ForLoopKeywords = new List <Keyword>(); } else { var temp = new Keyword(null); temp.CopyKeyword(SuggestionsClass.GetForLoop(KeywordType.ForLoopElements)); var splitKeyword = arrLine[i].Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries); if (splitKeyword.Length == 1) { splitKeyword = arrLine[i].Split(new [] { "\t" }, StringSplitOptions.RemoveEmptyEntries); } if (splitKeyword.Length >= 4) { temp.Params[0].Value = splitKeyword[1]; temp.Params[1].Value = splitKeyword[3]; } _currentTestCaseTestSteps.Add(temp); _currentTestCaseTestSteps[_currentTestCaseTestSteps.Count - 1].ForLoopKeywords = new List <Keyword>(); } } else { _currentTestCaseTestSteps[_currentTestCaseTestSteps.Count - 1].ForLoopKeywords.Add( new Keyword(arrLine[i].Trim().Remove(0, 1).Trim(), FilesAndFolderStructure.GetFolder(FolderType.Resources) + "Auto.robot", GetLibs(fileName), null)); AddKeywordsFromKeyword(_currentTestCaseTestSteps[_currentTestCaseTestSteps.Count - 1].ForLoopKeywords[_currentTestCaseTestSteps[_currentTestCaseTestSteps.Count - 1].ForLoopKeywords.Count - 1], GetResourcesFromFile(fileName)); } } } } } if (i + 1 == arrLine.Length) { if (!_currentTestCase.Equals("")) { //Setup test creation for previous Test case AddTestCaseAndResetValues(fileName); _currentTestCase = ""; } } if (arrLine[i].ToLower().Trim().StartsWith("*** test cases ***")) { start = true; } } } return(_testCases); }
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; } }