Exemplo n.º 1
0
 //adds Tags / Documentation / Arguments
 private static int AddTagsDocumentationArguments(string type, string addString, string fileName, int index)
 {
     if (addString == null)
     {
         addString = "";
     }
     if (!addString.Replace(type, "").Trim().Equals(""))
     {
         index++;
         RobotFileHandler.FileLineAdd(addString, fileName, index);
     }
     return(index);
 }
Exemplo n.º 2
0
        //Add includes to test case and keywords files
        public static void WriteIncludesToRobotFiles()
        {
            const FormType tag = FormType.Settings;

            foreach (var temp in Includes)
            {
                if (temp.FilesToInclude.Count > 0)
                {
                    var index        = 0;
                    var fileName     = temp.FileName;
                    var tempTagIndex = RobotFileHandler.HasTag(fileName, tag);
                    if (tempTagIndex == -1)
                    {
                        RobotFileHandler.FileLineAdd("*** Settings ***", fileName, index);
                        index++;
                        RobotFileHandler.FileLineAdd("", fileName, index);
                    }
                    else
                    {
                        index = tempTagIndex + 1;
                    }

                    temp.FilesToInclude.Sort();
                    foreach (var path in temp.FilesToInclude)
                    {
                        if (!path.Contains("\\"))
                        {
                            if (!RobotFileHandler.OccurenceInSettings(fileName, "Library  " + path).Equals(""))
                            {
                                continue;
                            }
                            RobotFileHandler.FileLineAdd("Library  " + path, fileName, index);
                            index++;
                        }
                        else
                        if (RobotFileHandler.OccurenceInSettings(fileName, "Resource  " + path.Replace(FilesAndFolderStructure.GetFolder(FolderType.Root), "").Replace('\\', '/')).Equals(""))
                        {
                            RobotFileHandler.FileLineAdd("Resource  " + path.Replace(FilesAndFolderStructure.GetFolder(FolderType.Root), "").Replace('\\', '/'), fileName, index);
                            index++;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        //Add variables to test case and keywords files
        public static void WriteVariablesToRobotFiles()
        {
            const FormType tag = FormType.Variable;

            foreach (var temp in Forms.RobotAutomationHelper.GlobalVariables)
            {
                if (temp.VariableNames != null && temp.VariableNames.Count > 0)
                {
                    var fileName = temp.OutputFilePath;
                    var index    = RobotFileHandler.HasTag(fileName, FormType.Test);
                    if (index == -1)
                    {
                        index = RobotFileHandler.HasTag(fileName, FormType.Keyword);
                    }
                    if (index == -1)
                    {
                        index = 0;
                    }
                    var tempTagIndex = RobotFileHandler.HasTag(fileName, tag);
                    if (tempTagIndex == -1)
                    {
                        RobotFileHandler.FileLineAdd("*** Variables ***", fileName, index);
                        index++;
                        RobotFileHandler.FileLineAdd("", fileName, index);
                    }
                    else
                    {
                        index = tempTagIndex + 1;
                    }

                    temp.VariableNames.Sort();
                    foreach (var variable in temp.VariableNames)
                    {
                        RobotFileHandler.FileLineAdd(variable, fileName, index);
                        index++;
                    }
                }
            }
        }
Exemplo n.º 4
0
        //Add test case / keyword name to robot file
        private static int AddName(string name, string fileName, int index, FormType tag)
        {
            var tempTagIndex = RobotFileHandler.HasTag(fileName, tag);

            if (tempTagIndex == -1)
            {
                if (tag.Equals(FormType.Keyword))
                {
                    RobotFileHandler.FileLineAdd("*** Keywords ***", fileName, index);
                }
                else
                {
                    if (tag.Equals(FormType.Test))
                    {
                        var tempKeywordsIndex = RobotFileHandler.HasTag(fileName, FormType.Keyword);
                        if (tempKeywordsIndex != -1)
                        {
                            RobotFileHandler.FileLineAdd("*** Test Cases ***", fileName, tempKeywordsIndex);
                            index = tempKeywordsIndex;
                        }
                        else
                        {
                            RobotFileHandler.FileLineAdd("*** Test Cases ***", fileName, index);
                        }
                    }
                }
                index++;
            }
            else
            if (tempTagIndex + 1 != index)
            {
                RobotFileHandler.FileLineAdd("", fileName, index);
                index++;
            }
            RobotFileHandler.FileLineAdd(name, fileName, index);
            return(index);
        }
Exemplo n.º 5
0
        // replaces tags and text when writing settings to the files
        private static void ReplaceInSettings(string replacementText, string tag, string outputFileName)
        {
            var location = RobotFileHandler.LocationInSettings(outputFileName, tag);

            //Add settings tag if not present in the file
            if (RobotFileHandler.HasTag(outputFileName, FormType.Settings) == -1)
            {
                RobotFileHandler.FileLineAdd("*** Settings ***", outputFileName, 0);
                RobotFileHandler.FileLineAdd("", outputFileName, 1);
            }

            if (location[0] == -1)
            {
                RobotFileHandler.FileLineAdd(replacementText
                                             , outputFileName
                                             , 1);
            }
            else
            {
                RobotFileHandler.FileLineReplace(replacementText
                                                 , outputFileName
                                                 , location);
            }
        }
Exemplo n.º 6
0
        //adds Steps
        private static void AddSteps(IReadOnlyCollection <Keyword> keywordKeywords, string fileName, int index, bool addSteps)
        {
            var container = new Includes(fileName);

            if (keywordKeywords == null)
            {
                return;
            }
            foreach (var keyword in keywordKeywords)
            {
                if (addSteps)
                {
                    if (keyword.Type == KeywordType.Custom && !StringAndListOperations.StartsWithVariable(keyword.Name))
                    {
                        Includes[Includes.IndexOf(container)].AddToList(keyword.OutputFilePath);
                    }
                    else
                    if (keyword.Type != KeywordType.Custom)
                    {
                        if (!keyword.KeywordString.Equals("BuiltIn") && !keyword.KeywordString.Equals("ForLoop"))
                        {
                            Includes[Includes.IndexOf(container)].AddToList(keyword.KeywordString);
                        }
                    }

                    //adds test steps
                    if (keyword.Type == KeywordType.ForLoopElements || keyword.Type == KeywordType.ForLoopInRange)
                    {
                        //add actual FOR Loop line + keywords inside it
                        index++;
                        if (keyword.Type == KeywordType.ForLoopElements)
                        {
                            RobotFileHandler.FileLineAdd("\t" + ":FOR" + "\t" + keyword.Params[0].Value + "\t" + "IN" + "\t" + keyword.Params[1].Value, fileName, index);
                        }
                        else
                        if (keyword.Type == KeywordType.ForLoopInRange)
                        {
                            RobotFileHandler.FileLineAdd("\t" + ":FOR" + "\t" + keyword.Params[0].Value + "\t" + "IN RANGE" + "\t" + keyword.Params[1].Value + "\t" + keyword.Params[2].Value, fileName, index);
                        }

                        foreach (var key in keyword.ForLoopKeywords)
                        {
                            index++;
                            RobotFileHandler.FileLineAdd("\t" + "\\" + "\t" + key.GetName() + key.ParamsToString(), fileName, index);

                            if (key.Type == KeywordType.Custom && !StringAndListOperations.StartsWithVariable(keyword.Name))
                            {
                                Includes[Includes.IndexOf(container)].AddToList(key.OutputFilePath);
                            }
                            else
                            if (keyword.Type != KeywordType.Custom)
                            {
                                if (!keyword.KeywordString.Equals("BuiltIn") && !keyword.KeywordString.Equals("ForLoop"))
                                {
                                    Includes[Includes.IndexOf(container)].AddToList(keyword.KeywordString);
                                }
                            }

                            if (!key.Recursive && !StringAndListOperations.StartsWithVariable(key.Name))
                            {
                                AddKeywordToRobot(key);
                            }
                        }
                    }
                    else
                    {
                        index++;
                        RobotFileHandler.FileLineAdd("\t" + keyword.GetName() + keyword.ParamsToString(), fileName, index);
                    }
                }

                if (!keyword.Recursive && !StringAndListOperations.StartsWithVariable(keyword.Name))
                {
                    AddKeywordToRobot(keyword);
                }
            }
        }