Exemplo n.º 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);
        }