Exemple #1
0
        public static string getRealAttribute(SpecNode nodeAndAttribute)
        {
            string attribute = nodeAndAttribute.Attribute;

            if (attribute == null || attribute.Equals(""))
            {
                return("Text");
            }
            if (Regex.IsMatch(attribute, "\\w+"))
            {
                return(attribute);
            }
            else if (Regex.IsMatch(attribute, "Cell\\s*\\((\\d+?),\\s*(\\d+?)\\)") ||
                     Regex.IsMatch(attribute, "Row\\s*\\((\\d+?)\\)"))
            {
                return("Text");
            }
            else
            {
                int idx = attribute.LastIndexOf(".");
                if (idx < 0)
                {
                    return(null);
                }
                return(attribute.Substring(attribute.LastIndexOf(".") + 1));
            }
        }
Exemple #2
0
        public static string getScriptAccessRanorexObject(IRanorexScriptGenerationParams _params)
        {
            SpecNode nodeAndAttribute = _params.SpecNode;
            IElement node             = nodeAndAttribute.UIElement;
            string   attribute        = nodeAndAttribute.Attribute;
            string   re = getScriptAccessRanorexElement(nodeAndAttribute, _params.InstanceName);

            if (node is AppFolderRanorexElement ||
                node is FolderRanorexElement)
            {
                re += ".SelfInfo";
            }
            else
            {
                if (attribute == null || attribute.Equals(""))
                {
                    re += "Info";
                }
                else if (Regex.IsMatch(attribute, "Cell\\s*\\((\\d+?),\\s*(\\d+?)\\)(\\.\\w+)*") ||
                         Regex.IsMatch(attribute, "Row\\s*\\((\\d+?)\\)(\\.\\w+)*"))
                {
                    re += ".Element";
                }
                else
                {
                    re += "Info";
                }
            }
            return(re);
        }
Exemple #3
0
        public string getScriptAccessRanorexObject(RanorexScriptGenerationParams param)
        {
            SpecNode nodeAndAttribute = param.SpecNode;
            IElement node             = nodeAndAttribute.UIElement;
            String   re = getScriptAccessRanorexElement(nodeAndAttribute, param.InstanceName);

            if (node is AppFolderRanorexElement ||
                node is FolderRanorexElement)
            {
                re += ".Self";
            }
            return(re + ".Element");
        }
Exemple #4
0
        protected string getValidation(string objectElement, SpecNode nodeAndAttribute,
                                       string nameAttr, string value, string screenName, int scenarioId, string imageName)
        {
            //String re = RanorexScriptGeneration.FORMAT;
            string re = "";

            re += "try" + NEW_LINE +
                  "{" + NEW_LINE +
                  "Validate.Attribute(" + objectElement + ", \"" + nameAttr + "\", \"" + value + "\");" + NEW_LINE +
                  "}" + NEW_LINE +
                  "catch (Exception e)" + NEW_LINE +
                  "{" + NEW_LINE;
            re += getRanorexScriptCapture(
                getAppFolderObjectElement(nodeAndAttribute.UIElement),
                screenName, scenarioId, nodeAndAttribute.GetNormalizedName());
            re += NEW_LINE +
                  "}";
            return(re);
        }
Exemple #5
0
        /// <summary>
        /// getFullNodeName
        /// </summary>
        /// <param name="nodeAndAttribute"></param>
        /// <param name="instanceName"></param>
        /// <returns></returns>
        public static string getScriptAccessRanorexElement(SpecNode nodeAndAttribute, string instanceName)
        {
            string attribute = nodeAndAttribute.Attribute;
            string re        = GetScriptAccessElement(nodeAndAttribute.UIElement, instanceName);

            //Textbox
            if (attribute == null || attribute.Equals(""))
            {
                return(re);
            }
            else
            {
                /**
                 * Dg.Cell(1,1)
                 */
                Regex pattern1 = new Regex("Cell\\s*\\((\\d+?),\\s*(\\d+?)\\)(\\.\\w+)*");
                Match matcher1 = pattern1.Match(attribute);

                /**
                 * Dg.Row(1)
                 */
                Regex pattern2 = new Regex("Row\\s*\\((\\d+?)\\)(\\.\\w+)*");
                Match matcher2 = pattern2.Match(attribute);

                if (matcher1.Success)
                {
                    re += ".Rows[";
                    string arg1Str = matcher1.Groups[1].Value;
                    string arg2Str = matcher1.Groups[2].Value;
                    re += Int32.Parse(arg1Str) + "].Cells[" + Int32.Parse(arg2Str) + "]";
                }
                else if (matcher2.Success)
                {
                    re += ".Rows[";
                    String arg1Str = matcher2.Groups[1].Value;
                    re += Int32.Parse(arg1Str) + "]";
                }
            }
            return(re);
        }
Exemple #6
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);
                         }
                     }
                 }
             }
         }
     }
 }
        /// <summary>
        /// type expression
        /// </summary>
        /// <param name="actionEpx"></param>
        /// <param name="specNode"></param>
        /// <param name="color"></param>
        /// <param name="myLog"></param>
        /// <returns></returns>
        private AbstractSpecUserAction handleUserActionExpression(String actionEpx,
                                                                  SpecNode specNode,
                                                                  Color color,
                                                                  MyLog myLog)
        {
            if (actionEpx == null || actionEpx.Equals("") ||
                actionEpx.Equals(AbstractSpecUserAction.NA) ||
                actionEpx.Equals(AbstractSpecUserAction.DO_NOTHING) ||
                actionEpx.Equals(AbstractSpecUserAction.EMPTY) ||
                color.Equals(AbstractSpecUserAction.NOT_TEST_COLOR1) ||
                color.Equals(AbstractSpecUserAction.NOT_TEST_COLOR2))    // ||
//                color.Equals(AbstractSpecUserAction.NOT_TEST_COLOR3))
            {
                return(null);
            }

            /**
             * determine if delay, wait, keyboard press
             */
            if (specNode.UIElement == null)
            {
                // delay
                if (Regex.IsMatch(specNode.Expression, AbstractSpecUserAction.DELAY_TITLE_EXPRESSION))
                {
                    DelaySpecUserAction delaySpecUserAction = new DelaySpecUserAction();
                    delaySpecUserAction.Expression = actionEpx;
                    return(delaySpecUserAction);
                }
                // wait
                else if (Regex.IsMatch(specNode.Expression, AbstractSpecUserAction.PRE_WAIT + "(_\\d*)*"))
                {
                    PreWaitValidateSpecUserAction waitValidateSpecUserAction = new PreWaitValidateSpecUserAction();
                    waitValidateSpecUserAction.Expression = actionEpx;
                    return(waitValidateSpecUserAction);
                }
                else if (Regex.IsMatch(specNode.Expression, AbstractSpecUserAction.POST_WAIT + "(_\\d*)*"))
                {
                    PostWaitValidateSpecUserAction waitValidateSpecUserAction = new PostWaitValidateSpecUserAction();
                    waitValidateSpecUserAction.Expression = actionEpx;
                    return(waitValidateSpecUserAction);
                }
                //keyboard press
                else if (Regex.IsMatch(specNode.Expression, AbstractSpecUserAction.KEYBOARD_PRESS_REGEX))
                {
                    KeyboardSpecUserAction keyboardPressSpecUserAction = new KeyboardSpecUserAction();
                    keyboardPressSpecUserAction.Expression = actionEpx;
                    return(keyboardPressSpecUserAction);
                }
                //test - not test
                else if (Regex.IsMatch(specNode.Expression, AbstractSpecUserAction.RESULT))
                {
                    return(null);
                }
                // usercode
                else if (Regex.IsMatch(specNode.Expression, AbstractSpecUserAction.USER_CODE) ||
                         Regex.IsMatch(specNode.Expression, AbstractSpecUserAction.USER_CODE_WITH_VARIABLE_DECLARE))
                {
                    UserCodeSpecUserAction userCodeExpression = new UserCodeSpecUserAction();
                    userCodeExpression.Expression = actionEpx;
                    return(userCodeExpression);
                }
            }
            AbstractSpecUserAction specUserAction = null;
            string attribute = specNode.Attribute;

            if (actionEpx.Equals(AbstractSpecUserAction.OPEN))
            {
                specUserAction = new OpenAppSpecUserAction();
            }
            else if (actionEpx.Equals(AbstractSpecUserAction.CLOSE))
            {
                specUserAction = new CloseAppSpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.CLICK))
            {
                specUserAction = new ClickSpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.DOUBLE_CLICK))
            {
                specUserAction = new DoubleClickSpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.RIGHT_CLICK))
            {
                specUserAction = new RightClickSpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.WAIT_EXIST) ||
                     actionEpx.StartsWith(AbstractSpecUserAction.WAIT_NOT_EXIST))
            {
                specUserAction = new WaitExistSpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.EXIST) ||
                     actionEpx.StartsWith(AbstractSpecUserAction.NOT_EXIST))
            {
                specUserAction = new CheckExistSpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.DELAY))
            {
                specUserAction = new DelaySpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.GET))
            {
                specUserAction = new GetSpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.CAPTURE))
            {
                specUserAction = new CaptureSpecUserAction();
            }
            else if (actionEpx.StartsWith(AbstractSpecUserAction.DROP))
            {
                specUserAction = new DropSpecUserAction();
            }
            //else if (actionEpx.StartsWith(AbstractSpecUserAction.COMPARE_IMAGE))
            //{
            //    specUserAction = new ImageComparativeSpecUserAction();
            //    specUserAction.Expression = actionEpx;
            //}
            else if (actionEpx.StartsWith(AbstractSpecUserAction.ATTRIBUTE_CONTAIN) ||
                     actionEpx.StartsWith(AbstractSpecUserAction.ATTRIBUTE_NOT_CONTAIN))
            {
                specUserAction = new ContainSpecUserAction();
            }

            else if (color.Equals(AbstractSpecUserAction.VALIDATION_COLOR) ||
                     color.Equals(AbstractSpecUserAction.ENVIRONMENT_COLOR))
            {
                specUserAction = new ValidationSpecUserAction();
            }
            else if (color.Equals(AbstractSpecUserAction.PROCEDURES_COLOR) ||
                     color.Equals(AbstractSpecUserAction.PRE_CONDITION_COLOR))
            {
                if (attribute != null && !attribute.Equals("") &&
                    (Regex.IsMatch(attribute, "^\\w+$") ||
                     Regex.IsMatch(attribute, ".*\\..*")))
                {
                    specUserAction = new SetSpecUserAction();
                }
                else if (attribute == null || attribute.Equals("") ||
                         Regex.IsMatch(attribute, "Cell\\s*\\((\\d+?),\\s*(\\d+?)\\)") ||
                         Regex.IsMatch(attribute, "Row\\s*\\((\\d+?)\\)"))
                {
                    specUserAction = new PressSpecUserAction();
                }
            }

            // add new case to handle here
            else
            {
                myLog.Warn("Incorrect expression: " + actionEpx);
            }
            if (specUserAction != null)
            {
                specUserAction.Expression = actionEpx;
            }
            return(specUserAction);
        }
 private void SetAttributes(SpecScenario scenario, AbstractSpecUserAction specUserAction, SpecNode specNode,
                            IScreen screen, string pathToApp, List <Color> colors, ScriptGenerationParams _params, int se, MyLog myLog)
 {
     // importance: must create on the same thread with UI thread
     try
     {
         Application.Current.Dispatcher.Invoke((Action) delegate
         {
             specUserAction.BgColor = new System.Windows.Media.SolidColorBrush(
                 System.Windows.Media.Color.FromArgb(
                     255, colors[se].R, colors[se].G, colors[se].B));
         });
     }
     catch (Exception)
     {
         specUserAction.BgColor = new System.Windows.Media.SolidColorBrush(
             System.Windows.Media.Color.FromArgb(
                 255, colors[se].R, colors[se].G, colors[se].B));
     }
     _params.Color             = colors[se];
     _params.Id                = scenario.Id;
     _params.ListUIElements    = screen.AllUIElements;
     _params.MyLog             = myLog;
     _params.ScreenName        = screen.Name;
     _params.SpecNode          = specNode;
     _params.PathToApp         = pathToApp;
     specUserAction.Params     = _params;
     specUserAction.NodeAffect = specNode;
     if (scenario.UserActions == null)
     {
         scenario.UserActions = new List <IUserAction>();
     }
     scenario.UserActions.Add(specUserAction);
 }
        public override INode Clone()
        {
            SpecNode re = new SpecNode(UIElement, attribute, expression);

            return(re);
        }