public static void AddKeywordToRobot(Keyword keyword) { var fileName = keyword.OutputFilePath; var index = 0; if (fileName != "") { index = RobotFileHandler.GetLineAfterLastKeyword(fileName); } if (index < 0) { index = 0; } var addKeywordSteps = RobotFileHandler.LocationOfTestCaseOrKeywordInFile(fileName, keyword.Name.Trim(), FormType.Keyword) == -1; if (addKeywordSteps) { if (keyword.Type == KeywordType.Custom && !StringAndListOperations.StartsWithVariable(keyword.Name)) { var candidate = new Includes(fileName); if (!Includes.Contains(candidate)) { Includes.Add(candidate); } } } if (addKeywordSteps && (keyword.Type == KeywordType.Custom)) { //Add keyword to robot file index = AddName(keyword.Name.Trim(), fileName, index, FormType.Keyword); //adds documentation if (keyword.Documentation != null) { index = AddTagsDocumentationArguments("[Documentation]", "\t" + keyword.Documentation.Trim(), fileName, index); } //adds arguments if (keyword.Arguments != null) { index = AddTagsDocumentationArguments("[Arguments]", "\t" + keyword.Arguments.Trim(), fileName, index); } } if (keyword.Type == KeywordType.Custom) { AddSteps(keyword.Keywords, fileName, index, addKeywordSteps); } }
// Methods ================================================================= public static void AddTestCaseToRobot(TestCase testCase) { var fileName = testCase.OutputFilePath; var index = RobotFileHandler.GetLineAfterLastTestCase(fileName); if (index < 0) { index = 0; } var addTestCase = RobotFileHandler.LocationOfTestCaseOrKeywordInFile(fileName, testCase.Name.Trim(), FormType.Test) == -1; if (addTestCase) { var candidate = new Includes(fileName); if (!Includes.Contains(candidate)) { Includes.Add(candidate); } //Add test case to robot file index = AddName(testCase.Name.Trim(), fileName, index, FormType.Test); //adds documentation if (testCase.Documentation != null) { index = AddTagsDocumentationArguments("[Documentation]", "\t" + testCase.Documentation.Trim(), fileName, index); } //adds tags if (testCase.Tags != null) { index = AddTagsDocumentationArguments("[Tags]", "\t" + testCase.Tags.Trim(), fileName, index); } } AddSteps(testCase.Steps, fileName, index, addTestCase); }
public static void TestCaseKeywordRemove(string name, string fileName, bool isKeyword) { if (fileName.Equals("")) { return; } Console.WriteLine(@"Overwrite (remove): " + name + @" " + (isKeyword ? "Keyword" : "Test") + @"\t" + fileName.Replace(FilesAndFolderStructure.GetFolder(FolderType.Root), "")); string[] arrLine; if (File.Exists(fileName)) { arrLine = File.ReadAllLines(fileName); } else { var directory = fileName.Replace(fileName.Split('\\')[fileName.Split('\\').Length - 1], ""); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } var myFile = File.Create(fileName); myFile.Close(); arrLine = File.ReadAllLines(fileName); } var index = RobotFileHandler.LocationOfTestCaseOrKeywordInFile(fileName, name, isKeyword ? FormType.Keyword : FormType.Test); if (index == -1) { return; } var endOfTestCaseKeyword = false; var temp = new List <string>(); temp.AddRange(arrLine); while (!endOfTestCaseKeyword) { if (index < temp.Count) { if (!temp[index].Trim().Equals("")) { Console.WriteLine(@"TestCaseKeywordRemove | Remove line: " + temp[index] + @"\t" + fileName.Replace(FilesAndFolderStructure.GetFolder(FolderType.Root), "")); } temp.RemoveAt(index); } else { endOfTestCaseKeyword = true; } if (index >= temp.Count) { continue; } if (temp[index].StartsWith(" ")) { continue; } if (temp[index].StartsWith("\t")) { continue; } if (temp[index].StartsWith("\\")) { continue; } if (temp[index].StartsWith(".")) { continue; } if (!temp[index].Equals("")) { endOfTestCaseKeyword = true; } } File.WriteAllLines(fileName, temp); }