protected bool IsNameValid(string name)
        {
            if (name.Trim().Length == 0)
            {
                return(false);
            }
            // the following block allows using variables at the beginning of the name without checking for 2 spaces
            var checkForVariables = name.Trim().Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries);

            if (checkForVariables.Length != 0)
            {
                if (StringAndListOperations.StartsWithVariable(checkForVariables[0]))
                {
                    return(true);
                }
            }

            for (var i = 0; i < name.Trim().Length - 1; i++)
            {
                if (name.Trim()[i].Equals(' '))
                {
                    if (name.Trim()[i + 1].Equals(' '))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        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);
            }
        }
        // Enable fields
        public void EnableKeywordFields(int keywordIndex)
        {
            if (Controls.Find("DynamicStep" + keywordIndex + "Label", false).Length != 0)
            {
                Controls["DynamicStep" + keywordIndex + "Label"].Enabled = true;
            }
            if (Controls.Find("DynamicStep" + keywordIndex + "AddImplementation", false).Length != 0)
            {
                Controls["DynamicStep" + keywordIndex + "AddImplementation"].Enabled = true;
                if (!IsNameValid(Controls["DynamicStep" + keywordIndex + "Name"].Text))
                {
                    Controls["DynamicStep" + keywordIndex + "AddImplementation"].Enabled = false;
                }
                else
                {
                    // starts with variable
                    var checkForVariables = Controls["DynamicStep" + keywordIndex + "Name"].Text.Trim().Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (checkForVariables.Length != 0)
                    {
                        if (StringAndListOperations.StartsWithVariable(checkForVariables[0]))
                        {
                            Controls["DynamicStep" + keywordIndex + "AddImplementation"].Enabled = false;
                        }
                    }

                    if (ThisFormKeywords[keywordIndex - 1].IsRecursive(ThisFormKeywords[keywordIndex - 1]))
                    {
                        Controls["DynamicStep" + keywordIndex + "AddImplementation"].Text    = @"Recursive";
                        Controls["DynamicStep" + keywordIndex + "AddImplementation"].Enabled = false;
                        ThisFormKeywords[keywordIndex - 1].Recursive = true;
                    }
                    else
                    {
                        ThisFormKeywords[keywordIndex - 1].Recursive = false;
                    }
                }
            }
            if (Controls.Find("DynamicStep" + keywordIndex + "AddKeyword", false).Length != 0)
            {
                Controls["DynamicStep" + keywordIndex + "AddKeyword"].Enabled = true;
            }
            if (Controls.Find("DynamicStep" + keywordIndex + "RemoveKeyword", false).Length != 0)
            {
                Controls["DynamicStep" + keywordIndex + "RemoveKeyword"].Enabled = true;
            }
            if (Controls.Find("DynamicStep" + keywordIndex + "Params", false).Length != 0)
            {
                Controls["DynamicStep" + keywordIndex + "Params"].Enabled = true;
            }
        }
Ejemplo n.º 4
0
        // 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);
        }
Ejemplo n.º 5
0
        public static void AddIncludesFromSettingsKeyword(Keyword keyword, string fileName)
        {
            if (!File.Exists(fileName))
            {
                return;
            }
            var container = new Includes(fileName);

            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);
                }
            }
        }
        // returns the list of variables in specific file
        public List <Variables> ReadVariablesFromFile()
        {
            var listOfVariables = new List <Variables>();

            var index = HasTag(FormType.Variable);

            if (index == -1)
            {
                return(listOfVariables);
            }

            var names = new List <string>();

            for (int i = index + 1; i < fileLines.Length; i++)
            {
                if (fileLines[i].StartsWith("*"))
                {
                    break;
                }
                if (fileLines[i].Trim().Length == 0)
                {
                    continue;
                }
                if (StringAndListOperations.StartsWithVariable(fileLines[i].Trim()))
                {
                    names.Add(fileLines[i].Trim());
                }
            }

            if (names.Count == 0)
            {
                return(listOfVariables);
            }

            var currentVariables = new Variables(names, fileName);

            listOfVariables.Add(currentVariables);

            return(listOfVariables);
        }
Ejemplo n.º 7
0
        private bool NameCheck(List <string> names)
        {
            foreach (var name in names)
            {
                if (name.Trim().Length == 0)
                {
                    _emptyName = true;
                    _containsTwoEmptySpaces = false;
                    return(false);
                }

                var checkForVariables = name.Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (checkForVariables.Length != 0)
                {
                    if (StringAndListOperations.StartsWithVariable(checkForVariables[0]))
                    {
                        return(true);
                    }
                }

                for (var i = 0; i < name.Trim().Length - 1; i++)
                {
                    if (name.Trim()[i].Equals(' '))
                    {
                        if (name.Trim()[i + 1].Equals(' '))
                        {
                            _emptyName = false;
                            _containsTwoEmptySpaces = true;
                            return(false);
                        }
                    }
                }
            }
            _emptyName = false;
            _containsTwoEmptySpaces = false;
            return(true);
        }
Ejemplo n.º 8
0
        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);
                }
            }
        }
Ejemplo n.º 9
0
        public static void WriteSuiteSettingsListToRobot()
        {
            foreach (var suiteSettings in Forms.RobotAutomationHelper.SuiteSettingsList)
            {
                if (suiteSettings.Overwrite)
                {
                    const FolderType type = FolderType.Root;

                    if (suiteSettings.TestTeardown.GetName() != "")
                    {
                        ReplaceInSettings("Test Teardown  " + suiteSettings.TestTeardown.GetName() + suiteSettings.TestTeardown.ParamsToString()
                                          , "Test Teardown",
                                          FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }
                    else
                    {
                        RemoveFromSettings("Test Teardown",
                                           FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }

                    if (suiteSettings.TestSetup.GetName() != "")
                    {
                        ReplaceInSettings("Test Setup  " + suiteSettings.TestSetup.GetName() + suiteSettings.TestSetup.ParamsToString()
                                          , "Test Setup",
                                          FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }
                    else
                    {
                        RemoveFromSettings("Test Setup",
                                           FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }

                    if (suiteSettings.SuiteTeardown.GetName() != "")
                    {
                        ReplaceInSettings("Suite Teardown  " + suiteSettings.SuiteTeardown.GetName() + suiteSettings.SuiteTeardown.ParamsToString()
                                          , "Suite Teardown",
                                          FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }
                    else
                    {
                        RemoveFromSettings("Suite Teardown",
                                           FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }

                    if (suiteSettings.SuiteSetup.GetName() != "")
                    {
                        ReplaceInSettings("Suite Setup  " + suiteSettings.SuiteSetup.GetName() + suiteSettings.SuiteSetup.ParamsToString()
                                          , "Suite Setup",
                                          FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }
                    else
                    {
                        RemoveFromSettings("Suite Setup",
                                           FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }

                    if (suiteSettings.Documentation != null && !suiteSettings.Documentation.Equals(""))
                    {
                        ReplaceInSettings("Documentation  " + suiteSettings.Documentation, "Documentation",
                                          FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }
                    else
                    {
                        RemoveFromSettings("Documentation",
                                           FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                    }

                    if (suiteSettings.SuiteSetup != null && !suiteSettings.SuiteSetup.GetName().Trim().Equals("") &&
                        !StringAndListOperations.StartsWithVariable(suiteSettings.SuiteSetup.Name))
                    {
                        RemoveKeywordChildrenOfKeywordForOverwriting(suiteSettings.SuiteSetup);
                        AddIncludesFromSettingsKeyword(suiteSettings.SuiteSetup, FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                        TestCaseKeywordRemove(suiteSettings.SuiteSetup.GetName(), suiteSettings.SuiteSetup.OutputFilePath, true);
                        AddKeywordToRobot(suiteSettings.SuiteSetup);
                    }
                    if (suiteSettings.SuiteTeardown != null && !suiteSettings.SuiteTeardown.GetName().Trim().Equals("") &&
                        !StringAndListOperations.StartsWithVariable(suiteSettings.SuiteTeardown.Name))
                    {
                        RemoveKeywordChildrenOfKeywordForOverwriting(suiteSettings.SuiteTeardown);
                        AddIncludesFromSettingsKeyword(suiteSettings.SuiteTeardown, FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                        TestCaseKeywordRemove(suiteSettings.SuiteTeardown.GetName(), suiteSettings.SuiteTeardown.OutputFilePath, true);
                        AddKeywordToRobot(suiteSettings.SuiteTeardown);
                    }
                    if (suiteSettings.TestSetup != null && !suiteSettings.TestSetup.GetName().Trim().Equals("") &&
                        !StringAndListOperations.StartsWithVariable(suiteSettings.TestSetup.Name))
                    {
                        RemoveKeywordChildrenOfKeywordForOverwriting(suiteSettings.TestSetup);
                        AddIncludesFromSettingsKeyword(suiteSettings.TestSetup, FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                        TestCaseKeywordRemove(suiteSettings.TestSetup.GetName(), suiteSettings.TestSetup.OutputFilePath, true);
                        AddKeywordToRobot(suiteSettings.TestSetup);
                    }
                    if (suiteSettings.TestTeardown != null && !suiteSettings.TestTeardown.GetName().Trim().Equals("") &&
                        !StringAndListOperations.StartsWithVariable(suiteSettings.TestTeardown.Name))
                    {
                        RemoveKeywordChildrenOfKeywordForOverwriting(suiteSettings.TestTeardown);
                        AddIncludesFromSettingsKeyword(suiteSettings.TestTeardown, FilesAndFolderStructure.ConcatFileNameToFolder(suiteSettings.OutputFilePath, type));
                        TestCaseKeywordRemove(suiteSettings.TestTeardown.GetName(), suiteSettings.TestTeardown.OutputFilePath, true);
                        AddKeywordToRobot(suiteSettings.TestTeardown);
                    }
                }
            }
        }
Ejemplo n.º 10
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);
                }
            }
        }