public void GetTheDataFromAllTheRobotFilesTest()
 {
     SuggestionsClass.PopulateSuggestionsList();
     FilesAndFolderStructure.SetFolder("C:\\Development\\robot-scripts\\jennyvegas_v005\\jennyvegas");
     FilesAndFolderStructure.FindAllRobotFilesAndAddToStructure();
     DataGetter = new RobotFileDataGetter();
     DataGetter.GetTheDataFromAllTheRobotFiles();
 }
Пример #2
0
 public void FormSetup(string path)
 {
     Cache.ClearCache();
     SuggestionsClass.PopulateSuggestionsList();
     ClearDynamicElements();
     settingsToolStripMenuItem.Visible   = true;
     librariesToolStripMenuItem.Visible  = true;
     variablesToolStripMenuItem.Visible  = true;
     runOptionsToolStripMenuItem.Visible = true;
     OutputLabel.Visible = true;
     OutputFile.Visible  = true;
     SetStructureFolder(path);
 }
Пример #3
0
        public void CheckForExistingCodeAndShowAlert()
        {
            var projectTestCases = ReadRobotFiles.ReadAllTests();

            SuiteSettingsList = ReadRobotFiles.ReadAllSettings();
            GlobalVariables   = ReadRobotFiles.ReadAllVariables();

            if (projectTestCases.Count == 0)
            {
                return;
            }
            var result = MessageBox.Show(@"Use existing Test Cases in project folder?",
                                         @"Alert",
                                         MessageBoxButtons.YesNo);

            if (!result.Equals(DialogResult.Yes))
            {
                return;
            }
            TestCases = projectTestCases;

            foreach (var testCase in projectTestCases)
            {
                if (testCase.Steps == null)
                {
                    continue;
                }
                foreach (var keyword in testCase.Steps)
                {
                    KeywordToSuggestions(keyword);
                }
            }

            if (SuiteSettingsList.Count != 0)
            {
                return;
            }
            foreach (var suiteSetting in SuiteSettingsList)
            {
                if (suiteSetting.GetKeywords().Count == 0)
                {
                    continue;
                }
                foreach (Keyword keyword in suiteSetting.GetKeywords())
                {
                    KeywordToSuggestions(keyword);
                }
            }

            SuggestionsClass.UpdateSuggestionsToIncludes(TestCases, SuiteSettingsList);
        }
Пример #4
0
        private void BrowseFolderButtonExistingProject()
        {
            FormSetup(folderBrowserDialog2.SelectedPath);

            TestCases = ReadRobotFiles.ReadAllTests();
            if (TestCases.Count != 0)
            {
                SuiteSettingsList = ReadRobotFiles.ReadAllSettings();
                GlobalVariables   = ReadRobotFiles.ReadAllVariables();

                if (SuiteSettingsList.Count != 0)
                {
                    foreach (var tempKeyword in SuiteSettingsList)
                    {
                        if (tempKeyword.GetKeywords().Count == 0)
                        {
                            continue;
                        }
                        foreach (var keyword in tempKeyword.GetKeywords())
                        {
                            KeywordToSuggestions(keyword);
                        }
                    }
                }

                foreach (var testCase in TestCases)
                {
                    if (testCase.Steps == null)
                    {
                        continue;
                    }
                    foreach (var tempKeyword in testCase.Steps)
                    {
                        KeywordToSuggestions(tempKeyword);
                    }
                }

                TestCases.Sort();

                SuggestionsClass.UpdateSuggestionsToIncludes(TestCases, SuiteSettingsList);
                AddTestCaseToFormAndShow(false);
            }
            else
            {
                MessageBox.Show(@"No test cases in the selected folder!",
                                @"Alert",
                                MessageBoxButtons.OK);
            }
        }
Пример #5
0
 private void Save_Click(object sender, EventArgs e)
 {
     foreach (var lib in SuggestionsClass.Suggestions)
     {
         if (lib.KeyType.Equals(KeywordType.Standard))
         {
             lib.ToInclude = SuggestionsClass.ContainsName(lib.Name, ((CheckBox)Controls["checkbox" + lib.Name]).Checked, false);
         }
         else
         {
             if (!lib.KeyType.Equals(KeywordType.ForLoopElements) && !lib.KeyType.Equals(KeywordType.ForLoopInRange) && !lib.KeyType.Equals(KeywordType.Custom))
             {
                 lib.ToInclude = SuggestionsClass.ContainsName(lib.Name, ((CheckBox)Controls["checkbox" + lib.Name]).Checked, false);
             }
         }
     }
     Close();
 }
Пример #6
0
        public void ShowLibrariesContent()
        {
            var stdLibsCounter = 0;
            var extLibsCounter = 0;

            var lockedIncludes = SuggestionsClass.UpdateSuggestionsToIncludes(RobotAutomationHelper.TestCases, RobotAutomationHelper.SuiteSettingsList);

            foreach (var lib in SuggestionsClass.Suggestions)
            {
                if (lib.KeyType.Equals(KeywordType.Standard))
                {
                    ShowLibField(STDLIBlabel.Location.X, InitialY + stdLibsCounter * FieldHeight, lib.Name, lib.ToInclude);
                    if (lockedIncludes.Contains(lib.Name))
                    {
                        DisableLibField(lib.Name);
                    }
                    stdLibsCounter++;
                }
                else
                {
                    if (lib.KeyType.Equals(KeywordType.ForLoopElements) ||
                        lib.KeyType.Equals(KeywordType.ForLoopInRange) ||
                        lib.KeyType.Equals(KeywordType.Custom))
                    {
                        continue;
                    }
                    ShowLibField(EXTLIBlabel.Location.X, InitialY + extLibsCounter * FieldHeight, lib.Name, lib.ToInclude);
                    if (lockedIncludes.Contains(lib.Name))
                    {
                        DisableLibField(lib.Name);
                    }
                    extLibsCounter++;
                }
            }

            StartPosition = FormStartPosition.Manual;
            ShowDialog();
        }
Пример #7
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);
                }
            }
        }
        // returns the list of test cases in specific file
        public List <TestCase> ReadTestCasesFromFile()
        {
            var listOfTestCases = new List <TestCase>();

            var index = HasTag(FormType.Test);

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

            var currentTestCase = new TestCase("", fileName);

            for (int i = index + 1; i < fileLines.Length; i++)
            {
                if (fileLines[i].StartsWith("*"))
                {
                    if (currentTestCase.Name != "")
                    {
                        listOfTestCases.Add(currentTestCase);
                    }
                    break;
                }

                if (fileLines[i].Trim().Length == 0)
                {
                    continue;
                }

                if (!fileLines[i].StartsWith(" ") && !fileLines[i].StartsWith("\t") && !fileLines[i].Trim().StartsWith("#"))
                {
                    if (currentTestCase.Name != "")
                    {
                        listOfTestCases.Add(currentTestCase);
                        currentTestCase = new TestCase("", fileName);
                    }
                    currentTestCase.Name = fileLines[i].Trim();
                    continue;
                }

                if (fileLines[i].Trim().StartsWith("[Documentation]"))
                {
                    currentTestCase.Documentation = fileLines[i];
                    for (int j = i + 1; j < fileLines.Length; j++)
                    {
                        if (!fileLines[j].Trim().StartsWith("."))
                        {
                            break;
                        }
                        currentTestCase.Documentation += fileLines[j].Trim().Replace("...", "");
                    }
                    continue;
                }

                if (fileLines[i].Trim().StartsWith("[Tags]"))
                {
                    var j         = i;
                    var multiLine = "";
                    if (i + 1 < fileLines.Length)
                    {
                        while (fileLines[i + 1].Trim().StartsWith("..."))
                        {
                            multiLine += "  " + fileLines[i + 1].Replace("...", "");
                            i++;
                            if (i + 1 >= fileLines.Length)
                            {
                                break;
                            }
                        }
                        multiLine.TrimEnd();
                    }
                    currentTestCase.Tags = fileLines[j] + multiLine;
                    continue;
                }

                // for loops
                if (!fileLines[i].Trim().ToLower().StartsWith(":for") &&
                    !fileLines[i].Trim().ToLower().StartsWith("\\"))
                {
                    var j         = i;
                    var multiLine = "";
                    if (i + 1 < fileLines.Length)
                    {
                        while (fileLines[i + 1].Trim().StartsWith("..."))
                        {
                            multiLine += "  " + fileLines[i + 1].Replace("...", "");
                            i++;
                            if (i + 1 >= fileLines.Length)
                            {
                                break;
                            }
                        }
                        multiLine.TrimEnd();
                    }

                    if (fileLines[j].Trim().StartsWith("#"))
                    {
                        continue;
                    }
                    if (currentTestCase.Steps == null)
                    {
                        currentTestCase.Steps = new List <Keyword>();
                    }
                    currentTestCase.Steps.Add(new Keyword(fileLines[j] + multiLine,
                                                          FilesAndFolderStructure.GetFolder(FolderType.Resources) + "Auto.robot", libraries, null));
                    continue;
                }
                else
                {
                    if (fileLines[i].Trim().ToLower().StartsWith(":for"))
                    {
                        if (fileLines[i].Trim().ToLower().Contains("range"))
                        {
                            var temp = new Keyword(null);
                            temp.CopyKeyword(SuggestionsClass.GetForLoop(KeywordType.ForLoopInRange));
                            var splitKeyword = fileLines[i].Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries);
                            if (splitKeyword.Length == 1)
                            {
                                splitKeyword = fileLines[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];
                            }
                            currentTestCase.Steps.Add(temp);
                            currentTestCase.Steps[currentTestCase.Steps.Count - 1].ForLoopKeywords = new List <Keyword>();
                        }
                        else
                        {
                            var temp = new Keyword(null);
                            temp.CopyKeyword(SuggestionsClass.GetForLoop(KeywordType.ForLoopElements));
                            var splitKeyword = fileLines[i].Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries);
                            if (splitKeyword.Length == 1)
                            {
                                splitKeyword = fileLines[i].Split(new[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);
                            }
                            if (splitKeyword.Length >= 4)
                            {
                                temp.Params[0].Value = splitKeyword[1];
                                temp.Params[1].Value = splitKeyword[3];
                            }
                            currentTestCase.Steps.Add(temp);
                            currentTestCase.Steps[currentTestCase.Steps.Count - 1].ForLoopKeywords = new List <Keyword>();
                        }
                    }
                    else
                    {
                        if (currentTestCase.Steps == null)
                        {
                            currentTestCase.Steps = new List <Keyword>();
                        }
                        currentTestCase.Steps[currentTestCase.Steps.Count - 1].ForLoopKeywords.Add(
                            new Keyword(fileLines[i].Trim().Remove(0, 1).Trim(),
                                        FilesAndFolderStructure.GetFolder(FolderType.Resources) + "Auto.robot", libraries, null));
                    }
                    continue;
                }
            }

            if (currentTestCase.Name != null)
            {
                if (!listOfTestCases.Contains(currentTestCase))
                {
                    listOfTestCases.Add(currentTestCase);
                }
            }

            return(listOfTestCases);
        }
        // returns the list of keywords in specific file
        public List <Keyword> ReadKeywordsFromFile()
        {
            var listOfKeywords = new List <Keyword>();

            var index = HasTag(FormType.Keyword);

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

            var currentKeyword = new Keyword(null)
            {
                OutputFilePath = fileName
            };

            for (int i = index + 1; i < fileLines.Length; i++)
            {
                if (fileLines[i].StartsWith("*"))
                {
                    if (currentKeyword.Name != null)
                    {
                        listOfKeywords.Add(currentKeyword);
                    }
                    break;
                }

                if (fileLines[i].Trim().Length == 0)
                {
                    continue;
                }

                if (!fileLines[i].StartsWith(" ") && !fileLines[i].StartsWith("\t"))
                {
                    if (currentKeyword.Name != null)
                    {
                        listOfKeywords.Add(currentKeyword);
                        currentKeyword = new Keyword(null)
                        {
                            OutputFilePath = fileName
                        };
                    }
                    currentKeyword.Name = fileLines[i].Trim();
                    continue;
                }

                if (fileLines[i].Trim().StartsWith("[Documentation]"))
                {
                    currentKeyword.Documentation = fileLines[i];
                    for (int p = i + 1; p < fileLines.Length; p++)
                    {
                        if (!fileLines[p].Trim().StartsWith("."))
                        {
                            break;
                        }
                        currentKeyword.Documentation += fileLines[p].Trim().Replace("...", "");
                    }
                    continue;
                }

                var j         = i;
                var multiLine = "";
                if (fileLines[i].Trim().StartsWith("[Arguments]"))
                {
                    if (i + 1 < fileLines.Length)
                    {
                        while (fileLines[i + 1].Trim().StartsWith("..."))
                        {
                            multiLine += "  " + fileLines[i + 1].Replace("...", "");
                            i++;
                            if (i + 1 >= fileLines.Length)
                            {
                                break;
                            }
                        }
                        multiLine.TrimEnd();
                    }

                    var splitKeyword = (fileLines[j] + multiLine).Replace("[Arguments]", "").Trim().Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries);
                    for (var counter = 0; counter < splitKeyword.Length; counter++)
                    {
                        if (!splitKeyword[counter].Contains("="))
                        {
                            if (currentKeyword.Params != null)
                            {
                                if (currentKeyword.Params.Count <= counter)
                                {
                                    currentKeyword.Params.Add(new Param(splitKeyword[counter], ""));
                                }
                                else
                                {
                                    currentKeyword.Params[counter].Name = splitKeyword[counter];
                                }
                            }
                            else
                            {
                                currentKeyword.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 currentKeyword.Params)
                            {
                                if (!par.Name.Equals(temp[0]))
                                {
                                    continue;
                                }
                                toAdd = false;
                                break;
                            }
                            if (toAdd)
                            {
                                currentKeyword.Params.Add(new Param(temp[0], temp[1]));
                            }
                        }
                    }
                    currentKeyword.Arguments = fileLines[j];
                    continue;
                }

                // for loops
                j         = i;
                multiLine = "";
                if (i + 1 < fileLines.Length)
                {
                    while (fileLines[i + 1].Trim().StartsWith("..."))
                    {
                        multiLine += "  " + fileLines[i + 1].Replace("...", "");
                        i++;
                        if (i + 1 >= fileLines.Length)
                        {
                            break;
                        }
                    }
                    multiLine.TrimEnd();
                }

                if (!fileLines[j].Trim().ToLower().StartsWith(":for") &&
                    !fileLines[j].Trim().ToLower().StartsWith("\\"))
                {
                    if (fileLines[j].Trim().StartsWith("#"))
                    {
                        continue;
                    }
                    if (currentKeyword.Keywords == null)
                    {
                        currentKeyword.Keywords = new List <Keyword>();
                    }
                    currentKeyword.Keywords.Add(new Keyword(fileLines[j] + multiLine,
                                                            FilesAndFolderStructure.GetFolder(FolderType.Resources) + "Auto.robot", libraries, currentKeyword));
                    if (currentKeyword.Keywords[currentKeyword.Keywords.Count - 1].IsRecursive(currentKeyword.Keywords[currentKeyword.Keywords.Count - 1]))
                    {
                        currentKeyword.Keywords[currentKeyword.Keywords.Count - 1].Recursive = true;
                    }
                    continue;
                }
                else
                {
                    if (fileLines[j].Trim().ToLower().StartsWith(":for"))
                    {
                        if (fileLines[j].Trim().ToLower().Contains("range"))
                        {
                            var temp = new Keyword(currentKeyword);
                            temp.CopyKeyword(SuggestionsClass.GetForLoop(KeywordType.ForLoopInRange));
                            var splitKeyword = fileLines[j].Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries);
                            if (splitKeyword.Length == 1)
                            {
                                splitKeyword = fileLines[j].Split(new[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);
                            }
                            temp.Params[0].Value = splitKeyword[1];
                            temp.Params[1].Value = splitKeyword[3];
                            temp.Params[2].Value = splitKeyword[4];
                            currentKeyword.Keywords.Add(temp);
                            currentKeyword.Keywords[currentKeyword.Keywords.Count - 1].ForLoopKeywords = new List <Keyword>();
                        }
                        else
                        {
                            var temp = new Keyword(currentKeyword);
                            temp.CopyKeyword(SuggestionsClass.GetForLoop(KeywordType.ForLoopElements));
                            var splitKeyword = fileLines[j].Split(new[] { "  " }, StringSplitOptions.RemoveEmptyEntries);
                            if (splitKeyword.Length == 1)
                            {
                                splitKeyword = fileLines[j].Split(new[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);
                            }
                            temp.Params[0].Value = splitKeyword[1];
                            temp.Params[1].Value = splitKeyword[3];
                            currentKeyword.Keywords.Add(temp);
                            currentKeyword.Keywords[currentKeyword.Keywords.Count - 1].ForLoopKeywords = new List <Keyword>();
                        }
                    }
                    else
                    {
                        if (currentKeyword.Keywords == null)
                        {
                            currentKeyword.Keywords = new List <Keyword>();
                        }
                        currentKeyword.Keywords[currentKeyword.Keywords.Count - 1].ForLoopKeywords.Add(
                            new Keyword(fileLines[j].Trim().Remove(0, 1).Trim(),
                                        FilesAndFolderStructure.GetFolder(FolderType.Resources) + "Auto.robot", libraries, currentKeyword));
                        if (currentKeyword.Keywords[currentKeyword.Keywords.Count - 1].IsRecursive(currentKeyword.Keywords[currentKeyword.Keywords.Count - 1]))
                        {
                            currentKeyword.Keywords[currentKeyword.Keywords.Count - 1].Recursive = true;
                        }
                    }
                    continue;
                }
            }

            if (currentKeyword.Name != null)
            {
                if (!listOfKeywords.Contains(currentKeyword))
                {
                    listOfKeywords.Add(currentKeyword);
                }
            }

            return(listOfKeywords);
        }
Пример #10
0
 public static void ClearCache()
 {
     FilesAndFolderStructure.CleanUp();
     SuggestionsClass.CleanUp();
 }
        // 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
            }
        }
Пример #12
0
        // 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);
        }
Пример #13
0
        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;
            }
        }
        private void UpdateSaveButtonState()
        {
            string name;

            if (_parentType.Equals(FormType.Test))
            {
                name = ContentName.Text;
            }
            else
            {
                name = Controls.Find("DynamicStep1Name", false).Length > 0 ? Controls["DynamicStep1Name"].Text : "";
            }

            if (_parentType.Equals(FormType.Keyword))
            {
                if (Controls.Find("DynamicStep1Name", false).Length > 0)
                {
                    if (SuggestionsClass.IsInSuggestionsList(Controls["DynamicStep1Name"].Text))
                    {
                        OutputFile.Enabled = false;
                        if (IsNameValid(name))
                        {
                            _toolTip.Hide(this);
                            Save.Enabled = true;
                        }
                    }
                    else
                    {
                        OutputFile.Enabled = true;
                        if (IsNameValid(name) && OutputFileCheck(OutputFile.Text))
                        {
                            _toolTip.Hide(this);
                            Save.Enabled = true;
                        }
                        else
                        {
                            _toolTip.Show("Invalid Name or OutputFile", Save, 0, Save.Size.Height);
                            Save.Enabled = false;
                        }
                    }
                }
                else
                {
                    OutputFile.Enabled = true;
                    if (IsNameValid(name) && OutputFileCheck(OutputFile.Text))
                    {
                        _toolTip.Hide(this);
                        Save.Enabled = true;
                    }
                    else
                    {
                        _toolTip.Show("Invalid Name or OutputFile", Save, 0, Save.Size.Height);
                        Save.Enabled = false;
                    }
                }
            }
            else
            {
                if (IsNameValid(name) && OutputFileCheck(OutputFile.Text))
                {
                    _toolTip.Hide(this);
                    Save.Enabled = true;
                }
                else
                {
                    _toolTip.Show("Invalid Name or OutputFile", Save, 0, Save.Size.Height);
                    Save.Enabled = false;
                }
            }
        }