/// <summary>
        ///
        /// </summary>
        /// <param name="screenList"></param>
        /// <param name="folderPath">="D:\MyTestProject"</param>
        /// <param name="repoFilePath">="D:\ElementsRepo.xml"</param>
        /// <param name="imageCapFilePath">="D:\ImageCapture.xml"</param>
        /// <param name="appFilePath">="D:\app.exe"</param>
        /// <param name="classRepoName">="MyTestProjectDefinition"</param>
        /// <param name="name_space">="MyTestProject"</param>
        /// <param name="mainClassInstance">="Instance"</param>
        /// <param name="myLog"></param>
        /// <returns>map (folder_path, list_files_in_folder)</returns>
        public Tuple <Dictionary <string, string>, List <string> > Generate(List <IScreen> screenList, string folderPath,
                                                                            string repoFilePath, string imageCapFilePath, string appFilePath, string classRepoName,
                                                                            string name_space, string mainClassInstance, MyLog myLog, string instanceName = INSTANCE_NAME)
        {
            //List<string> runningFilePath = new List<string>();
            Dictionary <string, string>      mapFilePathAndId = new Dictionary <string, string>();
            List <UserCodeScriptsExpression> additionScripts  = new List <UserCodeScriptsExpression>();
            List <ClassExpression>           additionClasses  = new List <ClassExpression>();
            SpecScreen aScreen = null;

            foreach (IScreen screen in screenList)
            {
                if (screen is SpecScreen specScreen)
                {
                    if (aScreen == null)
                    {
                        aScreen = specScreen;
                    }
                    ProcessScreen(specScreen, mapFilePathAndId, additionScripts, additionClasses,
                                  folderPath, repoFilePath, imageCapFilePath, appFilePath, classRepoName, name_space,
                                  mainClassInstance, myLog, instanceName);
                }
                else
                {
                    logger.Error("Not handled yet!");
                }
            }
            List <string> otherFilePath = GenerateAdditionClassses(additionScripts, additionClasses, aScreen, myLog, folderPath, repoFilePath,
                                                                   imageCapFilePath, appFilePath, classRepoName, name_space, mainClassInstance, instanceName, mapFilePathAndId);

            return(new Tuple <Dictionary <string, string>, List <string> >(mapFilePathAndId, otherFilePath));
        }
示例#2
0
        public SpecScreen Clone()
        {
            logger.Info("SpecScreen thread: " + System.Threading.Thread.CurrentThread.ManagedThreadId);

            SpecScreen re = new SpecScreen();

            if (mappingAliasWithNode != null)
            {
                re.MappingAliasWithNode = new Dictionary <string, string>(mappingAliasWithNode);
            }
            if (listSpecNodes != null)
            {
                re.ListSpecNodes = new List <SpecNode>();
                foreach (var specNode in listSpecNodes)
                {
                    re.ListSpecNodes.Add(specNode.Clone() as SpecNode);
                }
            }
            if (listValidationUserCode != null)
            {
                re.ListValidationUserCode = new List <Tuple <int, int> >(listValidationUserCode);
            }
            CopyAttributes(this, re);
            return(re);
        }
 /// <summary>
 /// add pre-conditions to each screnario
 /// </summary>
 /// <param name="screen"></param>
 /// <param name="mapNameAndScreens"></param>
 /// <param name="myLog"></param>
 private void AddPreCondition(SpecScreen screen, Dictionary <string, SpecScreen> mapNameAndScreens, MyLog myLog)
 {
     foreach (IScenario scenario in screen.Scenarios)
     {
         if (scenario is SpecScenario specScenario)
         {
             if (specScenario.PreConditionsExpression != null &&
                 specScenario.PreConditionsExpression.Count > 0)
             {
                 foreach (string preConditionExp in specScenario.PreConditionsExpression)
                 {
                     if (preConditionExp == null || preConditionExp.Equals(""))
                     {
                         continue;
                     }
                     int idx = preConditionExp.LastIndexOf("_");
                     if (idx < 0)
                     {
                         myLog.Warn("Can not find the pre-condiction: " + preConditionExp);
                     }
                     else
                     {
                         string preScreen = preConditionExp.Substring(0, idx);
                         try
                         {
                             int          preScenarioIdx      = Int32.Parse(preConditionExp.Substring(idx + 1));
                             SpecScreen   preConditionScreen  = mapNameAndScreens[preScreen];
                             SpecScenario preConditonScenario = getScenarioByIndex(
                                 preScenarioIdx, preConditionScreen.Scenarios);
                             if (preConditionScreen == null ||
                                 preScenarioIdx > preConditionScreen.Scenarios.Count ||
                                 preConditonScenario == null)
                             {
                                 myLog.Warn("Can not find the pre-condiction: " + preConditionExp);
                             }
                             else
                             {
                                 specScenario.PreConditions.Add(preConditonScenario);
                             }
                         }
                         catch (FormatException e)
                         {
                             myLog.Warn("Invalid pre-condiction: " + preConditionExp);
                         }
                     }
                 }
             }
         }
         else
         {
             myLog.Warn("Not implement this type");
         }
     }
 }
        /// <summary>
        /// generate user code, main file, etc
        /// </summary>
        /// <param name="additionScripts"></param>
        /// <param name="additionClasses"></param>
        /// <param name="aScreen"></param>
        /// <param name="myLog"></param>
        /// <param name="folderPath"></param>
        /// <param name="repoFilePath"></param>
        /// <param name="imageCapFilePath"></param>
        /// <param name="appFilePath"></param>
        /// <param name="classRepoName"></param>
        /// <param name="name_space"></param>
        /// <param name="mainClassInstance"></param>
        /// <param name="instanceName"></param>
        /// <param name="runningFilePath"></param>
        /// <returns></returns>
        protected List <string> GenerateAdditionClassses(List <UserCodeScriptsExpression> additionScripts, List <ClassExpression> additionClasses,
                                                         SpecScreen aScreen, MyLog myLog, string folderPath, string repoFilePath, string imageCapFilePath, string appFilePath,
                                                         string classRepoName, string name_space, string mainClassInstance, string instanceName, Dictionary <string, string> mapFilePathAndId)
        {
            List <string> otherFilePath = new List <string>();

            otherFilePath.AddRange(GenerateAdditionScripts(additionScripts, folderPath, name_space, aScreen.AllUIElements,
                                                           aScreen.MappingAliasWithNode, myLog, instanceName));
            otherFilePath.AddRange(GenerateClassExpScripts(additionClasses, folderPath, name_space, aScreen.AllUIElements,
                                                           aScreen.MappingAliasWithNode, myLog, instanceName));
            GenerateOthers(myLog, folderPath, repoFilePath, imageCapFilePath, appFilePath, classRepoName, name_space,
                           mainClassInstance, instanceName, mapFilePathAndId, otherFilePath);
            return(otherFilePath);
        }
        public TestSpecificationScreen parse(TestSpecificationSheet testSpecSheet,
                                             ListUIElements elementsAndIndicator, MyLog myLog, List <ClassExpression> classExpressions)
        {
            NormalSheetParser normalSheetParser = new NormalSheetParser();
            SpecScreen        screen            = normalSheetParser.Parse(testSpecSheet, elementsAndIndicator, myLog);

            if (screen == null)
            {
                return(null);
            }
            TestSpecificationScreen re = new TestSpecificationScreen();

            re.AllUIElements          = elementsAndIndicator;
            re.ListSpecNodes          = screen.ListSpecNodes;
            re.ListValidationUserCode = screen.ListValidationUserCode;
            re.MappingAliasWithNode   = screen.MappingAliasWithNode;
            re.Name             = testSpecSheet.getFeatureName();
            re.Scenarios        = screen.Scenarios;
            re.ClassExpressions = classExpressions;
            return(re);
        }
 /// <summary>
 /// process for a screen
 /// </summary>
 /// <param name="specScreen"></param>
 /// <param name="aScreen"></param>
 /// <param name="runningFilePath"></param>
 /// <param name="additionScrips"></param>
 /// <param name="additionClasses"></param>
 /// <param name="folderPath"></param>
 /// <param name="repoFilePath"></param>
 /// <param name="imageCapFilePath"></param>
 /// <param name="appFilePath"></param>
 /// <param name="classRepoName"></param>
 /// <param name="name_space"></param>
 /// <param name="mainClassInstance"></param>
 /// <param name="myLog"></param>
 /// <param name="instanceName"></param>
 public void ProcessScreen(SpecScreen specScreen, Dictionary <string, string> mapFilePathAndId,
                           List <UserCodeScriptsExpression> additionScrips, List <ClassExpression> additionClasses,
                           string folderPath, string repoFilePath, string imageCapFilePath, string appFilePath, string classRepoName,
                           string name_space, string mainClassInstance, MyLog myLog, string instanceName = INSTANCE_NAME)
 {
     //Dictionary<string, string> mapFilePathAndId = new Dictionary<string, string>();
     //List<string> listFilePath = new List<string>();
     foreach (IScenario scenario in specScreen.Scenarios)
     {
         if (scenario is SpecScenario specScenario)
         {
             HandleWaitActions(specScenario);
             Tuple <string, List <UserCodeScriptsExpression> > pair = GenerateAScenario(specScenario, myLog, instanceName);
             if (pair == null)
             {
                 continue;
             }
             var fileAndGuid = CreateNewRunCsFile(pair.Item1, pair.Item2,
                                                  folderPath, specScreen.Name, repoFilePath, imageCapFilePath,
                                                  appFilePath, classRepoName, name_space, specScenario.Id, mainClassInstance, instanceName);
             string filePath = fileAndGuid.Item1;
             string guid     = fileAndGuid.Item2;
             mapFilePathAndId.Add(filePath, guid);
             if (pair.Item2 != null && pair.Item2.Count > 0)
             {
                 Utils.MergeUcScriptsEpx(additionScrips, pair.Item2);
                 additionScrips.AddRange(pair.Item2);
             }
         }
         else
         {
             logger.Error("Not handled yet");
         }
     }
     //runningFilePath.AddRange(listFilePath);
     if (specScreen is TestSpecificationScreen testSpecScreen)
     {
         Utils.MergeClassesExpression(additionClasses, testSpecScreen.ClassExpressions);
     }
 }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="elementsAndIndicator">indication to determine root elements or list of all elements</param>
        /// <param name="myLog"></param>
        /// <returns></returns>
        private SpecScreen parserOneSheet(Excel._Worksheet sheet,
                                          ListUIElements elementsAndIndicator,
                                          MyLog myLog)
        {
            Excel.Range xlRange     = sheet.UsedRange;
            int         rowCount    = xlRange.Rows.Count;
            int         columnCount = xlRange.Columns.Count;

            SpecScreen screen = new SpecScreen();
            // get mapping alias
            Dictionary <string, string> mapAliasWithNode = getMappingAlias(sheet, rowCount, columnCount);

            screen.MappingAliasWithNode = mapAliasWithNode;

            /**
             * read first row to get all element Nodes
             */
            //Row firstRow = sheet.getRow(ROW_TITLE_TESTCASE);
            string no = getCellValue(sheet, ROW_TITLE_TESTCASE, 1);
            //if (searchElement(no, null, allUIElements) == null && !no.Equals(NO, stringComparison.OrdinalIgnoreCase))
            //{
            //    logWarnings.add("First column must numbered column!");
            //    logger.error("First column must numbered column!");
            //}

            List <SpecNode> listSpecNodes = new List <SpecNode>();
            // <start, end>-s
            List <Tuple <int, int> > listValidationUsercode = new List <Tuple <int, int> >();
            // get each node element
            //int lastColumn = firstRow.getLastCellNum();
            bool link           = false;
            int  startColumnIdx = 2;

            for (int fi = startColumnIdx; fi <= columnCount; fi++)
            {
                string value = getCellValue(sheet, ROW_TITLE_TESTCASE, fi);
                if (value == null || value.Trim().Equals(""))
                {
                    if (checkLastColumn(sheet, fi, rowCount))
                    {
                        columnCount = fi - 1;
                        break;
                    }
                    else
                    {
                        if (listValidationUsercode.Count == 0)
                        {
                            listValidationUsercode.Add(new Tuple <int, int>(fi - 1 - startColumnIdx, fi - startColumnIdx));
                        }
                        else
                        {
                            Tuple <int, int> lastPair = listValidationUsercode[listValidationUsercode.Count - 1];
                            if ((fi - lastPair.Item2 - startColumnIdx) == 1)
                            {
                                listValidationUsercode.RemoveAt(listValidationUsercode.Count - 1);
                                listValidationUsercode.Add(new Tuple <int, int>(lastPair.Item1, fi - startColumnIdx));
                            }
                            else
                            {
                                listValidationUsercode.Add(new Tuple <int, int>(fi - 1 - startColumnIdx, fi - startColumnIdx));
                            }
                        }
                        listSpecNodes.Add(listSpecNodes.Last());
                    }
                }
                else
                {
                    if (Regex.IsMatch(value, AbstractSpecUserAction.LINKS))
                    {
                        columnCount = fi - 1;
                        link        = true;
                        break;
                    }
                    else
                    {
                        SpecNode specNode = parseNode(value, elementsAndIndicator, mapAliasWithNode, myLog);
                        if (specNode == null)
                        {
                            return(null);
                        }
                        listSpecNodes.Add(specNode);
                    }
                }
            }
            screen.Name                   = sheet.Name;
            screen.AllUIElements          = elementsAndIndicator;
            screen.ListSpecNodes          = listSpecNodes;
            screen.ListValidationUserCode = listValidationUsercode;

            /**
             * parseOneFile each scenario
             */
            for (int fi = ROW_TITLE_TESTCASE + 1; fi <= rowCount; fi++)
            {
                //Row row = sheet.getRow(fi);
                bool isRowNotTest = true;
                if (getCellValue(sheet, fi, 1) == null || getCellValue(sheet, fi, 2) == null)
                {
                    rowCount = fi - 1;
                    break;
                }
                SpecScenario scenario = new SpecScenario();
                for (int se = 2; se <= columnCount; se++)
                {
                    Color  color = Color.Empty;
                    string value = getCellValue(sheet, fi, se);

                    /**
                     * check if result indicate 'not_test'
                     */
                    if (listSpecNodes[se - 2].Expression.Equals(AbstractSpecUserAction.RESULT))
                    {
                        if (value.Equals(AbstractSpecUserAction.NOT_TEST))
                        {
                            isRowNotTest = true;
                            break;
                        }
                        else if (value.Equals(AbstractSpecUserAction.TEST) || value.Equals(""))
                        {
                            ;
                        }
                        else
                        {
                            myLog.Warn("[WARNING] Result must be 'Test' or 'Not Test', not " + value +
                                       ", it will be treated as 'Test' by default", logger);
                        }
                    }
                    color = getCellBgColor(sheet, fi, se);
                    if (color.Equals(Color.Empty) || (
                            !color.Equals(AbstractSpecUserAction.NOT_TEST_COLOR1) &&
                            !color.Equals(AbstractSpecUserAction.NOT_TEST_COLOR2)))
                    {
                        isRowNotTest = false;
                    }
                    scenario.UserActionsInString.Add(value);
                    scenario.Colors.Add(color);
                }
                if (isRowNotTest)
                {
                    continue;
                }

                /**
                 * pre-condition
                 */
                string linkExpress   = "";
                string lastCellValue = getCellValue(sheet, fi, columnCount + 1);
                if (link && lastCellValue != null && !lastCellValue.Equals(""))
                {
                    linkExpress = lastCellValue;
                    string[] preConsExp = linkExpress.Split(',');
                    foreach (string preConExp in preConsExp)
                    {
                        scenario.PreConditionsExpression.Add(preConExp.Trim());
                    }
                }
                scenario.Id = fi - ROW_TITLE_TESTCASE;
                //scenario.ScreenName = screen.Name;
                if (screen.Scenarios == null)
                {
                    screen.Scenarios = new List <IScenario>();
                }
                screen.Scenarios.Add(scenario);
            }
            //release com objects to fully kill excel process from running in the background
            Marshal.ReleaseComObject(xlRange);
            Marshal.ReleaseComObject(sheet);
            return(screen);
        }
 private void DoExpand(SpecScreen screen, string pathToApp, MyLog myLog, List <ClassExpression> allClassesExp)
 {
     for (int fi = 0; fi < screen.Scenarios.Count; fi++)
     {
         IScenario tempScenario = screen.Scenarios[fi];
         if (tempScenario is SpecScenario)
         {
             SpecScenario  scenario      = tempScenario as SpecScenario;
             List <string> listActionExp = scenario.UserActionsInString;
             List <Color>  colors        = scenario.Colors;
             for (int se = 0; se < listActionExp.Count; se++)
             {
                 string actionExp = listActionExp[se];
                 if (actionExp == null)
                 {
                     myLog.Error("NULL at (" + (fi + 1) + "," + (se + 2) + ")");
                     continue;
                 }
                 SpecNode specNode = screen.ListSpecNodes[se];
                 ScriptGenerationParams _params        = null;
                 AbstractSpecUserAction specUserAction = null;
                 int lastInd = IsValidationUserCode(se, screen.ListValidationUserCode);
                 if (lastInd > se)
                 {
                     specUserAction = new ValidationUserCodeSpecUserAction();
                     _params        = new ValidationUCScriptGenerationParams();
                     List <string> listExp = new List <string>();
                     for (int th = se; th <= lastInd; th++)
                     {
                         String tempActionExp        = listActionExp[th];
                         AbstractSpecUserAction temp = handleUserActionExpression(
                             tempActionExp.Trim(), specNode, colors[th], myLog);
                         if (!(temp is ValidationSpecUserAction))
                         {
                             myLog.Warn("Expression: " + tempActionExp + " must be validation", logger);
                             screen = null;
                             return;
                         }
                         else
                         {
                             if (tempActionExp != null && !tempActionExp.Trim().Equals(""))
                             {
                                 listExp.Add(tempActionExp.Trim());
                             }
                         }
                     }
                     (specUserAction as ValidationUserCodeSpecUserAction).ListExps = listExp;
                     ((ValidationUCScriptGenerationParams)_params).ListExps        = listExp;
                     if (screen is TestSpecificationScreen)
                     {
                         ((ValidationUCScriptGenerationParams)_params).ClassExpressions = allClassesExp;
                     }
                     ((ValidationUCScriptGenerationParams)_params).ClassName =
                         AbstractSpecUserAction.GetFolderNameFromScreen(screen) + "_Validation";
                     ((ValidationUCScriptGenerationParams)_params).FunctionName = "Validate_" +
                                                                                  Regex.Replace(specNode.Expression, "[^A-Za-z0-9]", "_");
                     SetAttributes(scenario, specUserAction, specNode,
                                   screen, pathToApp, colors, _params, se, myLog);
                     se = lastInd;
                 }
                 else
                 {
                     string[] listActionsEpx = splitAction(actionExp, AbstractSpecUserAction.AND);
                     foreach (string action in listActionsEpx)
                     {
                         specUserAction = handleUserActionExpression(action.Trim(), specNode, colors[se], myLog);
                         if (specUserAction != null)
                         {
                             if (specUserAction is UserCodeSpecUserAction userCodeExpression)
                             {
                                 _params = new UserCodeScriptGenerationParams();
                                 ((UserCodeScriptGenerationParams)_params).MapAliasWithNode = screen.MappingAliasWithNode;
                                 if (screen is TestSpecificationScreen testSpecScreen)
                                 {
                                     ((UserCodeScriptGenerationParams)_params).ClassExpressions = allClassesExp;
                                 }
                             }
                             else if (specUserAction is WaitValidateSpecUserAction waitUserAction)
                             {
                                 _params = new WaitValidateScriptGenerationParams();
                             }
                             else
                             {
                                 _params = new ScriptGenerationParams();
                             }
                             SetAttributes(scenario, specUserAction, specNode,
                                           screen, pathToApp, colors, _params, se, myLog);
                         }
                     }
                 }
             }
         }
     }
 }
示例#9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="elementsAndIndicator">indication to determine root elements or list of all elements</param>
        /// <param name="myLog"></param>
        /// <returns></returns>
        private List <SpecScreen> DoParse(string filePath, ListUIElements elementsAndIndicator, MyLog myLog)
        {
            string newFilePath = Utils.CreateTempFile(filePath);

            //Create COM Objects. Create a COM object for everything that is referenced
            Excel.Application xlApp      = new Excel.Application();
            Excel.Workbook    xlWorkbook = xlApp.Workbooks.Open(newFilePath);
            //Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];

            List <AbstractSheet> listAbstractSheets = new List <AbstractSheet>();

            for (int fi = 1; fi <= xlWorkbook.Sheets.Count; fi++)
            {
                Excel._Worksheet sheet         = xlWorkbook.Sheets[fi];
                string           name          = sheet.Name;
                AbstractSheet    abstractSheet = null;
                foreach (Tuple <string, string> pairSheetNameRule in SHEET_NAME_TEMPLATE_LIST)
                {
                    Regex           regex   = new Regex(pairSheetNameRule.Item1);
                    MatchCollection matches = regex.Matches(name);
                    if (matches.Count > 0)
                    {
                        string featureName = matches[0].Groups[1].Value;
                        abstractSheet = new TestSpecificationSheet(featureName, sheet);
                    }
                    else
                    {
                        Regex           regex2   = new Regex(pairSheetNameRule.Item2);
                        MatchCollection matches2 = regex2.Matches(name);
                        if (matches2.Count > 0)
                        {
                            string featureName = matches2[0].Groups[1].Value;
                            abstractSheet = new FunctionDescriptionSheet(featureName, sheet);
                        }
                    }
                }
                if (abstractSheet == null)
                {
                    abstractSheet = new NormalSheet(name, sheet);
                }
                listAbstractSheets.Add(abstractSheet);
            }
            List <NormalSheet> normalSheets = new List <NormalSheet>();
            List <Tuple <TestSpecificationSheet, FunctionDescriptionSheet> > pairSheets =
                new List <Tuple <TestSpecificationSheet, FunctionDescriptionSheet> >();

            foreach (AbstractSheet abstractSheet in listAbstractSheets)
            {
                if (abstractSheet is NormalSheet)
                {
                    normalSheets.Add((NormalSheet)abstractSheet);
                }
                else if (abstractSheet is TestSpecificationSheet)
                {
                    FunctionDescriptionSheet funcDescSheet =
                        findFuncDesc(abstractSheet.getFeatureName(), listAbstractSheets);
                    pairSheets.Add(new Tuple <TestSpecificationSheet, FunctionDescriptionSheet>(
                                       (TestSpecificationSheet)abstractSheet, funcDescSheet));
                }
            }
            List <SpecScreen> screenList = new List <SpecScreen>();

            foreach (Tuple <TestSpecificationSheet, FunctionDescriptionSheet> pairSheet in pairSheets)
            {
                SpecScreen screen = parsePairSheet(pairSheet, elementsAndIndicator, myLog);
                if (screen != null)
                {
                    screenList.Add(screen);
                }
            }
            foreach (NormalSheet normalSheet in normalSheets)
            {
                SpecScreen screen = parseNormalSheet(normalSheet, elementsAndIndicator, myLog);
                if (screen != null)
                {
                    screenList.Add(screen);
                }
            }
            //return screenList;
            //cleanup
            //GC.Collect();
            //GC.WaitForPendingFinalizers();

            //rule of thumb for releasing com objects:
            //  never use two dots, all COM objects must be referenced and released individually
            //  ex: [somthing].[something].[something] is bad

            //close and release
            xlWorkbook.Close(false);
            Marshal.ReleaseComObject(xlWorkbook);

            //quit and release
            xlApp.Quit();
            Marshal.ReleaseComObject(xlApp);
            return(screenList);
        }