示例#1
0
        public override ScriptsExpression HandleAndGenScripts(IScriptGenerationParams scriptGenerationParams, ScriptType scriptType = ScriptType.Normal)
        {
            string re = GetComment(scriptGenerationParams) + NEW_LINE;

            if (scriptGenerationParams is ValidationUCScriptGenerationParams param)
            {
                string newFunctionContent = "";
                if (param.SpecNode.Attribute == null ||
                    param.SpecNode.Attribute == "")
                {
                    param.SpecNode.Attribute = TEXT;
                }
                foreach (string exp in param.ListExps)
                {
                    if (newFunctionContent != "")
                    {
                        newFunctionContent += NEW_LINE;
                    }
                    if (scriptType == ScriptType.Normal)
                    {
                        newFunctionContent += ValidationSpecUserAction.GetRawScripts(param, exp).Expression;
                    }
                    else if (scriptType == ScriptType.Ranorex)
                    {
                        newFunctionContent += ValidationSpecUserAction.GetRawRanorexScripts(param as IRanorexScriptGenerationParams, exp).Expression;
                    }
                }
                string newClassName = param.ClassName;
                string newFuncName  = param.FunctionName;
                re += newClassName + "." + newFuncName + "();";
                var pair = CheckFunctionExisted(param.ClassExpressions, newClassName, newFuncName, 0, true);
                // if not existed
                if (!pair.Item1)
                {
                    FunctionExpression func = new FunctionExpression(newFuncName);
                    func.setContent(newFunctionContent);
                    UserCodeScriptsExpression re1 = new UserCodeScriptsExpression(re);
                    re1.MapClassAndFuncsAddition = new Dictionary <string, List <FunctionExpression> >
                    {
                        { newClassName, new List <FunctionExpression>()
                          {
                              func
                          } }
                    };
                    return(re1);
                }
                return(new ScriptsExpression(re));
            }
            else
            {
                re += ValidationSpecUserAction.GetRawScripts(scriptGenerationParams, this.Expression).Expression;
                return(new ScriptsExpression(re));
            }
        }
        //public abstract ScriptsExpression GenScripts(ScriptGenerationParams scriptGenerationParams);

        public string GetWhileWaitScripts(WaitValidateScriptGenerationParams param)
        {
            string re = TEMPLATE
                        .Replace("#idx1", param.WaitIndex + "")
                        .Replace("#r1", this.Expression)
                        .Replace("#r2", param.ListUserActions.Count + "");
            string r3 = "";

            for (int fi = 0; fi < param.ListUserActions.Count; fi++)
            {
                var userAction = param.ListUserActions[fi];
                if (r3 != "")
                {
                    r3 += NEW_LINE;
                }
                r3 += TEMPLATE_2
                      .Replace("#idx1", param.WaitIndex + "")
                      .Replace("#idx2", fi + "");
                //.Replace("#r1", userAction.GenRawScripts(userAction.Params).Expression);
                if (userAction is ValidationSpecUserAction || userAction is ContainSpecUserAction ||
                    userAction is CheckExistSpecUserAction)
                {
                    r3 = r3.Replace("#r1", userAction.GenRawScripts(userAction.Params).Expression);
                }
                else if (userAction is SetSpecUserAction || userAction is PressSpecUserAction)
                {
                    if (userAction.Params.SpecNode.Attribute == null ||
                        userAction.Params.SpecNode.Attribute == "")
                    {
                        userAction.Params.SpecNode.Attribute = TEXT;
                    }
                    r3 = r3.Replace("#r1",
                                    ValidationSpecUserAction.GetRawScripts(userAction.Params, userAction.Expression).Expression);
                }
            }
            re = re.Replace("#r3", r3);
            return(re);
        }
        /// <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);
        }