コード例 #1
0
        private string HandleCompoent(JObject scriptInfo)
        {
            string methodNanme = "";

            string tradeCode     = scriptInfo.GetValue("tradeCode").ToString();
            string pageCode      = scriptInfo.GetValue("pageCode").ToString();
            string compoentId    = scriptInfo.GetValue("compoentId").ToString();
            string compoentValue = scriptInfo.GetValue("compoentValue").ToString();
            string action        = scriptInfo.GetValue("action").ToString();
            string compoentType  = scriptInfo.GetValue("compoentType").ToString();

            BrowserUntils browserUntils = BrowserUntils.GetBrowser(tradeCode, pageCode);

            methodNanme = compoentType + action;

            string className = "ABCAgreeAutoTestPluging4.Controller.Trade.ScriptExecute";

            Type type = Type.GetType(className);

            object obj = System.Activator.CreateInstance(type);                                        //方法或构造函数的对象

            object[] parameters = new object[] { pageCode, compoentId, compoentValue, browserUntils }; //调用的方法或构造函数的参数列表

            //获取方法信息
            MethodInfo method = type.GetMethod(methodNanme, new Type[] { typeof(string), typeof(string), typeof(string), typeof(BrowserUntils) });

            return(method.Invoke(obj, parameters).ToString());
        }
コード例 #2
0
        /// <summary>
        /// 弹窗提示信息正则匹配
        /// </summary>
        /// <param name="tradeMessage"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public bool CheckDialogRegexResult(JObject tradeMessage, string expression, BrowserUntils browserUntils)
        {
            currentValue = browserUntils.ExecuteScript("获取弹出框信息的js语句");

            Regex regex = new Regex(expression.Substring(1, expression.Length - 1));

            return(regex.IsMatch(currentValue));
        }
コード例 #3
0
        public void AText(string pageCode, string itemCode, string itemValue, BrowserUntils browserUntils)
        {
            browserUntils.ExecuteScript("window.focusEvent('" + pageCode + "','" + itemCode + "');");

            System.Threading.Thread.Sleep(1000);//执行操作之后延时时间

            //可以触发vue文本框的校验
            browserUntils.ExecuteScript("window.findVueByName('" + pageCode + "')." + "$refs." + itemCode + ".$emit('input','" + itemValue + "')");

            browserUntils.ExecuteScript("window.blurEvent('" + pageCode + "','" + itemCode + "');");
        }
コード例 #4
0
 public void Span(string pageCode, string itemCode, string itemValue, BrowserUntils browserUntils)
 {
     if (int.TryParse(itemValue, out int value))
     {
         browserUntils.ExecuteScript("window.findVueByName('" + pageCode + "').$refs." + itemCode + "[" + (value - 1) + "].click();");
     }
     else
     {
         browserUntils.ExecuteScript("function foo(){var list = window.findVueByName('" + pageCode + "').$refs." + itemCode + ";" +
                                     "for (var i = 0; i < list.length; i++){if (list[i].innerText == '" + itemValue + "'){list[i].click();} } } foo();");
     }
 }
コード例 #5
0
        /// <summary>
        /// 操作组件信息
        /// </summary>
        /// <param name="tradeMessage"></param>
        /// <returns></returns>
        public JObject HandleCompoent(JObject tradeMessage)
        {
            string itemCode = tradeMessage.GetValue("itemCode").ToString();

            string pageCode = tradeMessage.GetValue("pageCode").ToString();

            string relation = tradeMessage.GetValue("relation").ToString();

            string executeTime = "";

            bool result = true;

            logger.Info("开始操作组件");

            browserUntils = BrowserUntils.GetBrowser(transCode, pageCode);

            logger.Info("获取浏览器对象");

            if (CheckPage(transCode, pageCode) && CheckCompoent(transCode, pageCode, itemCode))
            {
                if (tradeMessage.GetValue("isscreen").ToString().Equals("Y"))
                {
                    //截图
                    ScreenShot.Shot(browserUntils.browser);
                }
                if (relation != "")
                {
                    //执行表达式相关操作
                    HandleRelationExpression(relation);
                }
                if (tradeMessage.Property("resultMap") != null && tradeMessage.GetValue("resultMap").ToString() != "")
                {
                    //处理预期结果
                    ExpectedResult expectedResult = new ExpectedResult(browserUntils);

                    result = expectedResult.CheckExpectedResult(tradeMessage);
                }

                DateTime startTime = DateTime.Now;
                ExecuteCompoent(tradeMessage);
                DateTime endTime = DateTime.Now;
                executeTime = (endTime - startTime).Milliseconds.ToString();//操作组件的时间

                tradeMessage.Add("direction", executeTime);
                tradeMessage.Add("checkResult", result);
            }
            else
            {
                Property.executeResult = false;
            }
            return(tradeMessage);
        }
コード例 #6
0
        /// <summary>
        /// 弹窗提示信息判断
        /// </summary>
        /// <param name="tradeMessage"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public bool CheckDialogResult(JObject tradeMessage, string expression, BrowserUntils browserUntils)
        {
            currentValue = browserUntils.ExecuteScript("获取弹出框信息的js语句");

            if (expression.IndexOf("val") != -1)
            {
                expression = expression.Replace("val", currentValue);

                return(bool.Parse(datatable.Compute(expression, "").ToString()));
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
        public string HandleConpoentByScriptt(JObject scriptInfo)
        {
            string result = "";

            //停止
            if (scriptInfo.Property("stopPlugin") != null && scriptInfo.GetValue("stopPlugin").ToString() != "")
            {
                Property.PerformaceMark = false;

                return(StopPlugin());
            }
            //打开交易
            if (scriptInfo.Property("openTrade") != null && scriptInfo.GetValue("openTrade").ToString() != "")
            {
                return(OpenTrade(scriptInfo.GetValue("openTrade").ToString()).ToString());
            }
            //关闭交易
            if (scriptInfo.Property("closeTrade") != null && scriptInfo.GetValue("closeTrade").ToString() != "")
            {
                return(CloseTrade(scriptInfo.GetValue("closeTrade").ToString()));
            }
            //截图
            if (scriptInfo.Property("isScreenShot") != null && scriptInfo.GetValue("isScreenShot").ToString() != "")
            {
                browserUntils = BrowserUntils.GetBrowser(scriptInfo.GetValue("transCode").ToString(), scriptInfo.GetValue("pageCode").ToString());

                //截图
                ScreenShot.Shot(browserUntils.browser);

                return(browserUntils.ExecuteScript("截图的js语句"));
            }

            DateTime startTime = DateTime.Now;

            result = HandleCompoent(scriptInfo);
            DateTime endTime     = DateTime.Now;
            string   executeTime = (endTime - startTime).Milliseconds.ToString();//操作组件的时间

            scriptInfo.Add("direction", executeTime);
            scriptInfo.Add("checkResult", result);

            Property.scriptMessage.Add(scriptInfo);//将脚本中信息存储起来


            return(result);
        }
コード例 #8
0
        /// <summary>
        /// 检查组件返回的结果
        /// </summary>
        /// <param name="tradeMessage"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public bool CheckCompoentResult(JObject tradeMessage, string expression, BrowserUntils browserUntils)
        {
            Match match = null;

            string checkExpression = "";

            string pageCode = tradeMessage.GetValue("tradeCode").ToString();

            if (expression.Contains("or") || expression.Contains("and"))
            {
                match = Regex.Match(expression, @"\{(.*)\}.*\{(.*)\}");
            }
            else
            {
                match = Regex.Match(expression, @"\{(.*)\}");
            }
            for (int i = 1; i < match.Groups.Count; i++)
            {
                string compoentInfo = match.Groups[i].Value;

                string[] compoentList = compoentInfo.Split('.');

                //判断是否在同一个页面,获取需要的检查的组件当前的值
                if (compoentList[1].Equals(pageCode))
                {
                    string currentValue = browserUntils.ExecuteScript(" window.findVueByName('" + pageCode + "').$refs." + compoentList[2] + ".$options.propsData.value");

                    checkExpression = expression.Replace("{" + compoentInfo + "}", currentValue);
                }
                else
                {
                    string currentValue = Property.relationValue.GetValue(compoentInfo.Replace(".", "")).ToString();

                    checkExpression = expression.Replace("{" + currentValue + "}", currentValue);
                }
            }

            logger.Info("需要检查的表达式的值为:" + checkExpression);

            return(bool.Parse(datatable.Compute(checkExpression, "").ToString()));
        }
コード例 #9
0
        public void ARadioButton(string pageCode, string itemCode, string itemValue, BrowserUntils browserUntils)
        {
            browserUntils.ExecuteScript("window.findVueByName('" + pageCode + "').$refs." + itemCode + ".$children" + "[" + (Convert.ToInt32(itemValue) - 1) + "].$el.firstChild.click();");

            ScreenShot.Shot(browserUntils.browser);
        }
コード例 #10
0
        public void AButton(string pageCode, string itemCode, string itemValue, BrowserUntils browserUntils)
        {
            browserUntils.ExecuteScript("window.findVueByName('" + pageCode + "').$refs." + itemCode + ".$el.firstChild.click();");

            ScreenShot.Shot(browserUntils.browser);
        }
コード例 #11
0
        public void ATextAreaSetValue(string pageCode, string itemCode, string itemValue, BrowserUntils browserUntils)
        {
            //可以触发vue文本框的校验
            browserUntils.ExecuteScript("window.findVueByName('" + pageCode + "')." + "$refs." + itemCode + ".$emit('input','" + itemValue + "')");

            ScreenShot.Shot(browserUntils.browser);
        }
コード例 #12
0
        public bool CheckPage(string tansCode, string pageCode)
        {
            BrowserUntils.GetBrowser(tansCode, pageCode).ExecuteScript("");

            throw new NotImplementedException();
        }
コード例 #13
0
 private string GetRelationValue(string tradeCode, string pageCode, string compoentId)
 {
     return(BrowserUntils.GetBrowser(tradeCode, pageCode).ExecuteScript("function foo(){return window.findVueByName('" + pageCode + "').$refs." + compoentId + ".value};foo();"));
 }
コード例 #14
0
 public ExpectedResult(BrowserUntils browserUntils)
 {
     this.browserUntils = browserUntils;
 }
コード例 #15
0
 /// <summary>
 /// 检查表格结果
 /// </summary>
 /// <param name="tradeMessage"></param>
 /// <param name="expression"></param>
 /// <returns></returns>
 public bool CheckTableResult(JObject tradeMessage, string expression, BrowserUntils browserUntils)
 {
     throw new NotImplementedException();
 }
コード例 #16
0
 public void ATab(string pageCode, string itemCode, string itemValue, BrowserUntils browserUntils)
 {
     browserUntils.ExecuteScript("window.findVueByName('" + pageCode + "').$refs." + itemCode + ".setActiveItemByIndex(" + itemValue + ")");
 }
コード例 #17
0
        public void AListBoxClick(string pageCode, string itemCode, string itemValue, BrowserUntils browserUntils)
        {
            browserUntils.ExecuteScript("window.findVueByName('" + pageCode + "').$refs." + itemCode + ".setActiveItemByIndex(" + itemValue + ")");

            ScreenShot.Shot(browserUntils.browser);
        }