示例#1
0
        public virtual void doActions(List <WebAction> actions)
        {
            completedEventHandler         = new WebBrowserDocumentCompletedEventHandler(this.pageLoaded);
            WebBrowser.DocumentCompleted += completedEventHandler;
            Queue <WebAction> activeActions = new Queue <WebAction>(actions);

            while (0 < activeActions.Count)
            {
                activeAction = activeActions.Dequeue();
                if (activeAction.canDoAction(this))
                {
                    if (activeAction.shouldWaitAction(this))
                    {
                        trigger.Reset();
                        WaitHandle.WaitAny(waitHandles);
                    }
                    activeAction.doAction(this);
                    if (activeAction.isWaitForEvent())
                    {
                        trigger.Reset();
                        WaitHandle.WaitAny(waitHandles);
                    }
                }
            }
            completedActions();
        }
        public ActionResult Index()
        {
            var model = new WebAction();

            ViewBag.Items = dbc.WebActions.ToList();
            return(View(model));
        }
示例#3
0
        protected override async Task Boost(WebAction action, string trackPath)
        {
            switch (action)
            {
            case WebAction.Play:
                await this.Play(trackPath);

                break;

            case WebAction.Follow:
                await this.Follow(trackPath);

                break;

            case WebAction.Like:
                await this.Like(trackPath);

                break;

            case WebAction.Share:
                await this.Share(trackPath);

                break;
            }
        }
示例#4
0
        multiple_webactions_define_the_request_pipeline()
        {
            var newRequestWithContext = Defaults.Context.With(path: "/hello");

            WebActionFeature <string> addContent = (content) =>
                                                   (ctx) => ctx.With(content: content);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var requestPipeline = Pipeline(
                (context) =>
                context
                | addContent("hello")
                | ok
                );

            var afterContext = requestPipeline(newRequestWithContext);


            Assert.Equal("hello", afterContext.Response.Content);
            Assert.Equal(200, afterContext.Response.StatusCode);
        }
示例#5
0
        apply_pipeline_for_a_matched_route()
        {
            WebActionFeature <string> addContent = (some) =>
                                                   (ctx) => ctx.With(content: some);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var requestPipeline = Pipeline(
                (context) =>
                context
                | addContent("hello")
                | ok
                );

            Route route = new Route(
                template: "/hello",
                pipeline: requestPipeline
                );

            string content       = string.Empty;
            int    status        = 0;
            var    beforeContext = Defaults.Context.With(path: "/hello");

            if (route.Matches(path: "/hello"))
            {
                (content, status) = route.ApplyPipeline(beforeContext);
            }


            Assert.Equal("hello", content);
            Assert.Equal(200, status);
        }
示例#6
0
 public MenuItemBinding(WebAction action, ActionDispatcher dispatcher, MenuItem item)
 {
     _actionItem       = action;
     _actionDispatcher = dispatcher;
     _actionDispatcher.Register(action.Identifier, this);
     item.Click += OnItemClick;
     Item        = item;
 }
示例#7
0
        engine_stores_project_routes(string path1, string path2, int countExpected)
        {
            var       engine = new Router();
            WebAction ok     = c => c.With(statusCode: 200);

            engine.AddRoute(new Route(path1, ok));
            engine.AddRoute(new Route(path2, ok));

            Assert.Equal(countExpected, engine.Routes.Count());
        }
示例#8
0
 public void Dispose()
 {
     if (_actionDispatcher != null)
     {
         Item.Click -= OnItemClick;
         ReleaseDispatcher();
         _actionItem       = null;
         Item              = null;
         _actionDispatcher = null;
     }
 }
示例#9
0
 public Route(string template, WebAction pipeline)
 {
     Template = template;
     Pipeline = pipeline;
     Filters  = new List <Filter> {
     };
     if (!string.IsNullOrEmpty(template))
     {
         Filters.Add(PathFilter(template));
     }
 }
 public ActionResult Insert(WebAction entity)
 {
     try
     {
         dbc.WebActions.Add(entity);
         dbc.SaveChanges();
         TempData["Message"] = "Thêm mới thành công!";
     }
     catch
     {
         TempData["Message"] = "Thêm mới thất bại!";
     }
     return(RedirectToAction("Index"));
 }
示例#11
0
        routes_default_filter_is_only_path_template(string requestPath, bool isMatchExpected)
        {
            var newContext = Defaults.Context.With(path: requestPath);

            WebAction ok = c => c.With(statusCode: 200);


            var route = new Route("/a", ok);

            Check.That(route.Filters).HasSize(1);
            Filter routeFilter = route.Filters.FirstOrDefault();

            Assert.Equal(isMatchExpected, routeFilter((newContext, true)).isMatch);
        }
 public ActionResult Update(WebAction entity)
 {
     try
     {
         dbc.Entry(entity).State = System.Data.EntityState.Modified;
         dbc.SaveChanges();
         TempData["Message"] = "Cập nhật thành công!";
     }
     catch
     {
         TempData["Message"] = "Cập nhật thất bại!";
     }
     return(RedirectToAction("Edit", new { entity.Id }));
 }
示例#13
0
        public async Task <IEnumerable <WebAction> > GetWebActions(string fileId)
        {
            var actions = new List <WebAction>();

            var request = _driveService.Files.Get(fileId);

            var data = await request.ExecuteAsync();

            request.Fields = "id, name, mimeType, webViewLink";

            var webViewAction = new WebAction("View on Web", data.WebViewLink);

            actions.Add(webViewAction);

            return(actions);
        }
示例#14
0
        public ActionResult Update(WebAction model)
        {
            try
            {
                sdb.Entry(model).State = EntityState.Modified;
                sdb.SaveChanges();
                ModelState.AddModelError("", "Updated");
            }
            catch
            {
                ModelState.AddModelError("", "Error");
            }

            ViewBag.WebActions = sdb.WebActions;
            return View("Index", model);
        }
示例#15
0
        public ActionResult Insert(WebAction model)
        {
            try
            {
                sdb.WebActions.Add(model);
                sdb.SaveChanges();
                ModelState.AddModelError("", "Inserted");
            }
            catch
            {
                ModelState.AddModelError("", "Error");
            }

            ViewBag.WebActions = sdb.WebActions;
            return(View("Index", model));
        }
示例#16
0
        public ActionResult Update(WebAction model)
        {
            try
            {
                sdb.Entry(model).State = EntityState.Modified;
                sdb.SaveChanges();
                ModelState.AddModelError("", "Updated");
            }
            catch
            {
                ModelState.AddModelError("", "Error");
            }

            ViewBag.WebActions = sdb.WebActions;
            return(View("Index", model));
        }
示例#17
0
        public ActionResult Insert(WebAction model)
        {
            try
            {
                sdb.WebActions.Add(model);
                sdb.SaveChanges();
                ModelState.AddModelError("", "Inserted");
            }
            catch
            {
                ModelState.AddModelError("", "Error");
            }

            ViewBag.WebActions = sdb.WebActions;
            return View("Index", model);
        }
示例#18
0
        WebAction_is_context_transform()
        {
            var req           = Request(RequestType.UNKNOWN, "/hello");
            var response      = Response("xxx", 0);
            var beforeContext = Context(req, response);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var afterContext = ok(beforeContext);


            Assert.Equal(200, afterContext.Response.StatusCode);
            Assert.Equal("xxx", afterContext.Response.Content);
        }
示例#19
0
        public async Task Boost(string trackPath, IList <WebAction> actions)
        {
            if (this._webDriver != null)
            {
                SeleniumUtils.NavigateTo(this._webDriver, trackPath);
            }

            Task[] boosts = new Task[actions.Count];

            for (int i = 0; i < actions.Count; i++)
            {
                WebAction action = actions[i];
                boosts[i] = this.Boost(action, trackPath);
            }

            await Task.WhenAll(boosts);
        }
示例#20
0
        protected override void  UpdateEntity(Entity entity)
        {
            WebAction webAction = (WebAction)entity;

            webAction.ToolTip   = Action.Tooltip;
            webAction.Label     = Action.Label;
            webAction.Enabled   = Action.Enabled;
            webAction.Visible   = Action.Visible;
            webAction.Available = Action.Available;

            if (Action.IconSet == null)
            {
                return;
            }

            webAction.IconSet = CreateWebIconSet(Action);
        }
示例#21
0
        private static MenuItem BuildActionMenuItem(WebActionNode subNode, ActionDispatcher dispatcher)
        {
            WebAction actionNode = subNode as WebAction;

            MenuItem item = new MenuItem
            {
                IsEnabled  = actionNode.Enabled,
                IsChecked  = (actionNode is WebClickAction) && (actionNode as WebClickAction).Checked,
                Visibility = actionNode.DesiredVisiblility
            };

            var binding = new MenuItemBinding(actionNode, dispatcher, item);

            binding.SetLabel(actionNode.Label);
            binding.SetIcon();

            item.Tag = binding;

            return(item);
        }
示例#22
0
        public void router_should_return_route_or_not_found(string path, int expectedStatusCode)
        {
            var       testContext = Defaults.Context.With(path: path, type: GET);
            var       router      = new Router();
            WebAction ok          = c => c.With(statusCode: 200);

            router.AddRoute(new Route("/b", ok));
            router.AddRoute(new Route("/c", ok));

            // Route routeNotFound = Route.Empty | NOT_FOUND;

            var route = router.FindRoute(testContext);

            string content = null;
            int    status  = -1;

            (content, status) = route.ApplyPipeline(testContext);

            Assert.Equal(expectedStatusCode, status);
        }
示例#23
0
        featured_webaction_is_a_composition_returning_webaction()
        {
            var req           = Request(RequestType.UNKNOWN, "/hello");
            var response      = Response("xxx", 0);
            var beforeContext = Context(req, response);

            WebActionFeature <string> addContent = (content) =>
                                                   (ctx) => ctx.With(content: content);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var afterContext1 = addContent("oh oh oh")(beforeContext);
            var afterContext  = ok(afterContext1);

            Assert.Equal(200, afterContext.Response.StatusCode);
            Assert.Equal("oh oh oh", afterContext.Response.Content);
        }
示例#24
0
        public void Path_is_a_route_function_with_default_filter_path_and_can_continue_with_webactions()
        {
            var newContext = Defaults.Context.With(path: "/a");

            WebAction ok = c => c.With(statusCode: 200).With(content: "hello");

            Route route = Path("/a") | ok;

            string content = null;
            int    status  = -1;

            if (route.Matches(path: "/a"))
            {
                (content, status) = route.ApplyPipeline(newContext);
            }


            Assert.Equal("hello", content);
            Assert.Equal(200, status);
        }
示例#25
0
 private void Run()
 {
     try
     {
         WebAction.Execute(Context);
         if (WebAction.Type == Models.Behaviours.Action.ActionType.Check)
         {
             CheckAction checkWebAction     = (CheckAction)WebAction;
             Behaviour   behaviourToExecute = checkWebAction.CheckResult ? checkWebAction.BehaviourWhenTrue : checkWebAction.BehaviourWhenFalse;
             if (behaviourToExecute != null)
             {
                 studio.ExecuteBehaviour(behaviourToExecute, Context);
             }
         }
     }
     catch (Exception ex)
     {
         Dialog.CancelAllTasks($"Error while executing action: {ex.Message}");
     }
 }
示例#26
0
        define_route_with_template_and_pipeline()
        {
            WebActionFeature <string> addContent = (content) =>
                                                   (ctx) => ctx.With(content: content);

            WebAction ok = (ctx) => Context(
                request: ctx.Request,
                response: Response(ctx.Response.Content, 200)
                );

            var requestPipeline = Pipeline(
                (context) =>
                context
                | addContent("hello")
                | ok
                );

            Route route = new Route(
                template: "/hello",
                pipeline: requestPipeline
                );
        }
示例#27
0
 public virtual void doNextAction()
 {
     if (0 < activeActions.Count)
     {
         activeAction = activeActions.Dequeue();
         if (activeAction.canDoAction(this))
         {
             if (activeAction.shouldWaitAction(this))
             {
                 //Wait
             }
             else
             {
                 doAction();
             }
         }
     }
     else
     {
         completedActions();
     }
 }
示例#28
0
        public void Path_is_a_route_function_with_filter_path()
        {
            var testContext = Defaults.Context.With(path: "/a", type: GET);

            WebAction ok = c => c.With(statusCode: 200).With(content: "hello");

            Route route = Path("/a")
                          | Verbs(GET, POST)
                          | ok;

            string content = null;
            int    status  = -1;

            if (route.Matches(testContext))
            {
                (content, status) = route.ApplyPipeline(testContext);
            }


            Assert.Equal("hello", content);
            Assert.Equal(200, status);
        }
示例#29
0
        /// <summary>
        /// 短信发送
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public string SendMessage(string phone, string smessage)
        {
            Random _random   = new Random();
            string _tradeno  = DateTime.Now.ToString("yyyyMMddHHmmssfff") + _random.Next(100, 1000);
            string _username = ConfigurationManager.AppSettings.Get("username");
            string _password = ConfigurationManager.AppSettings.Get("password");
            string _key      = ConfigurationManager.AppSettings.Get("key");
            string _url      = ConfigurationManager.AppSettings.Get("PostUrl");
            string _content  = smessage;
            string _phone    = phone;
            string json      = JsonConvert.SerializeObject(new
            {
                userPassword = _password,
                tradeNo      = _tradeno,
                phones       = _phone,
                etnumber     = "",
                userName     = _username,
                content      = _content,
            });
            string _sign = AES.Encrypt(json, _key, _key);

            _password = MD5Helper.Encrypt(_password);
            string parm_json = JsonConvert.SerializeObject(new
            {
                tradeNo      = _tradeno,
                userName     = _username,
                userPassword = _password,
                phones       = _phone,
                content      = _content,
                etnumber     = "",
                sign         = _sign
            });
            WebAction _web      = new WebAction();
            string    returnStr = HttpHelper.Post(_url, parm_json);

            return(GetResult(returnStr.Split(',')[1].Split(':')[1].Replace('"', ' ').Trim()));
        }
示例#30
0
        public virtual void doNextAction()
        {
            if (0 < activeActions.Count)
            {
                activeAction = activeActions.Dequeue();
                if (activeAction.canDoAction(this))
                {
                    if (activeAction.shouldWaitAction(this))
                    {
                        //Wait
                    }
                    else
                    {
                        doAction();
                    }
                }
            } else
            {
                completedActions();
            }

        }
示例#31
0
 public virtual void doActions(List<WebAction> actions)
 {
     completedEventHandler = new WebBrowserDocumentCompletedEventHandler(this.pageLoaded);
     WebBrowser.DocumentCompleted += completedEventHandler;
     Queue<WebAction> activeActions = new Queue<WebAction>(actions);
     while (0 < activeActions.Count)
     {
         activeAction = activeActions.Dequeue();
         if (activeAction.canDoAction(this))
         {
             if (activeAction.shouldWaitAction(this))
             {
                 trigger.Reset();
                 WaitHandle.WaitAny(waitHandles);
             }
             activeAction.doAction(this);
             if (activeAction.isWaitForEvent())
             {
                 trigger.Reset();
                 WaitHandle.WaitAny(waitHandles);
             }
         }
     }
     completedActions();
 }
示例#32
0
        /// <summary>
        /// 私有方法,执行一个单独的步骤,并返回对应的
        /// </summary>
        /// <param name="testStep"></param>
        /// <returns></returns>
        private bool SingleStepExec(TestStep testStep)
        {
            WebAction webAction = testStep.WebAction;
            //开始判断操作
            bool sigresult = false;

            try
            {
                MacroAction macroAction = webAction.Action as MacroAction;


                switch (webAction.ActionXElement.Name.LocalName)
                {
                case WebActionConst.LaunchBrowser:
                    sigresult = new LaunchEDA(testStep).Launch;
                    break;

                case WebActionConst.AlertAccept:
                    sigresult = new AlertEDA(testStep).Accept;

                    break;

                case WebActionConst.AlertDismiss:
                    sigresult = new AlertEDA(testStep).Dismiss;

                    break;

                case WebActionConst.AlertSendKeys:
                    sigresult = new AlertEDA(testStep).SendKeys;

                    break;

                case WebActionConst.BrowserBack:
                    sigresult = new BrowserEDA(testStep).Back;

                    break;

                case WebActionConst.BrowserClose:
                    sigresult = new BrowserEDA(testStep).Close;

                    break;

                case WebActionConst.BrowserCloseTab:
                    sigresult = new BrowserEDA(testStep).CloseTab;


                    break;

                case WebActionConst.BrowserExecuteScript:
                    sigresult = new BrowserEDA(testStep).ExecuteScript;

                    break;

                case WebActionConst.BrowserForward:
                    sigresult = new BrowserEDA(testStep).Forward;

                    break;

                case WebActionConst.BrowserGoToUrl:
                    sigresult = new BrowserEDA(testStep).GoToUrl;

                    break;

                case WebActionConst.BrowserRefresh:
                    sigresult = new BrowserEDA(testStep).Refresh;

                    break;

                case WebActionConst.BrowserStop:
                    sigresult = new BrowserEDA(testStep).Stop;

                    break;

                case WebActionConst.BrowserSwitchFrame:
                    sigresult = new BrowserEDA(testStep).SwitchFrame;

                    break;

                case WebActionConst.BrowserSwitchToTab:
                    sigresult = new BrowserEDA(testStep).SwitchToTab;

                    break;

                case WebActionConst.BrowserTakeSnapshot:
                    sigresult = new BrowserEDA(testStep).TakeSnapshot;

                    break;

                case WebActionConst.MouseMove:
                    sigresult = new MouseEDA(testStep).Move;

                    break;

                case WebActionConst.MouseClick:
                    sigresult = new MouseEDA(testStep).Click;

                    break;

                case WebActionConst.RoWebElementClear:
                    sigresult = new RoWebElementEDA(testStep).Clear;

                    break;

                case WebActionConst.RoWebElementClick:
                    sigresult = new RoWebElementEDA(testStep).Click;

                    break;

                case WebActionConst.RoWebElementFocus:
                    sigresult = new RoWebElementEDA(testStep).Focus;

                    break;

                case WebActionConst.RoWebElementSelect:
                    sigresult = new RoWebElementEDA(testStep).Select;

                    break;

                case WebActionConst.RoWebElementSendKeys:

                    sigresult = new RoWebElementEDA(testStep).SendKeys;

                    break;

                case WebActionConst.ScrollDown:
                    sigresult = new ScrollEDA(testStep).Down;

                    break;

                case WebActionConst.ScrollUp:
                    sigresult = new ScrollEDA(testStep).Up;

                    break;

                case WebActionConst.Sleep:
                    sigresult = new SleepEDA(testStep).Sleep;

                    break;

                case WebActionConst.UpdateSelect:
                    sigresult = new UpdateEDA(testStep).UpdateSelect;

                    break;

                case WebActionConst.WaitUntilPageIsLoaded:
                    sigresult = new WaitUntilEDA(testStep).PageIsLoaded;

                    break;

                case WebActionConst.WaitUntilAreEqual:
                    sigresult = new WaitUntilEDA(testStep).AreEqual;
                    break;

                case WebActionConst.WaitUntilAreNotEqual:
                    sigresult = new WaitUntilEDA(testStep).AreNotEqual;
                    break;

                case WebActionConst.WaitUntilIsFalse:
                    sigresult = new WaitUntilEDA(testStep).IsFalse;
                    break;

                case WebActionConst.WaitUntilIsTrue:
                    sigresult = new WaitUntilEDA(testStep).IsTrue;
                    break;

                case WebActionConst.WaitUntilStringContains:
                    sigresult = new WaitUntilEDA(testStep).StringContains;
                    break;

                case WebActionConst.WaitUntilStringLength:
                    sigresult = new WaitUntilEDA(testStep).StringLength;
                    break;

                case WebActionConst.MacroReference:
                    /*
                     * TODO Macro是高于各类webaction但低于TestSteps的优先级别,具有teststeps的操作逻辑
                     * TODO 因此需要在本方法中就直接处理Macro,
                     */
                    Queue <TestStep> macros = new MacroReferenceEDA(macroAction).Macro;
                    ComArgs.RoLog.WriteLog(LogStatus.LDeb, $"当前宏操作{macroAction?.MacroId}提取步骤数量为:{macros.Count}");
                    List <bool> reList = new List <bool>();
                    //此处有一个幽灵Bug,当macros被反馈后,如果使用队列的正常方法,字典中的值会直接被清空!!!
                    foreach (TestStep oneTestStep in macros)
                    {
                        bool res = SingleStepExec(oneTestStep);     //递归方法
                        reList.Add(res);
                    }

                    if (!reList.Contains(false))
                    {
                        sigresult = true;
                    }

                    break;
                }

                return(sigresult);
            }
            catch (Exception e)
            {
                //添加输出
                ComArgs.RoLog.WriteLog(LogStatus.LExpt, "私有方法SingleStepExec发生异常", e.ToString());
                return(false);
            }
            finally
            {
                ComArgs.ResultType.NowNums = ComArgs.ResultType.NowNums + 1;

                if (sigresult)
                {
                    ComArgs.ResultType.SuccNums = ComArgs.ResultType.SuccNums + 1;
                }
                else
                {
                    ComArgs.ResultType.FailNums = ComArgs.ResultType.FailNums + 1;
                }

                ComArgs.ResultType.Cover = (((double)ComArgs.ResultType.SuccNums / ComArgs.ResultType.NowNums) * 100).ToString("F");  //默认为保留两位
                _guiViewEvent.OnUiViewResult(ComArgs.ResultType);
            }
        }
示例#33
0
 public void Dispose()
 {
     if (_actionDispatcher != null)
     {
         Item.Click -= OnItemClick;
         ReleaseDispatcher();
         _actionItem = null;
         Item = null;
         _actionDispatcher = null;
     }
 }
示例#34
0
 public MenuItemBinding(WebAction action, ActionDispatcher dispatcher, MenuItem item)
 {
     _actionItem = action;
     _actionDispatcher = dispatcher;
     _actionDispatcher.Register(action.Identifier, this);
     item.Click += OnItemClick;
     Item = item;
 }
示例#35
0
        private static MenuItem BuildMenuItem(WebActionNode node, ActionDispatcher dispatcher)
        {
            MenuItem thisMenu = null;

            try
            {
                if (node.Children != null)
                {
                    thisMenu = new MenuItem {
                        Header = node.LocalizedText
                    };

                    foreach (WebActionNode subNode in node.Children)
                    {
                        if (subNode.Children == null || subNode.Children.Count == 0)
                        {
                            MenuItem menuItem = BuildActionMenuItem(subNode, dispatcher);

                            if (menuItem != null)
                            {
                                if (menuItem.IsChecked)
                                {
                                    thisMenu.IsChecked = true;
                                }

                                if (menuItem != null)
                                {
                                    thisMenu.Items.Add(menuItem);
                                }
                            }
                        }
                        else
                        {
                            MenuItem menuItem = BuildMenuItem(subNode, dispatcher);
                            if (menuItem != null)
                            {
                                if (menuItem.IsChecked)
                                {
                                    thisMenu.IsChecked = true;
                                }

                                thisMenu.Items.Add(menuItem);
                            }
                        }
                    }

                    // Don't show the menu if it has no children
                    thisMenu.Visibility = node.DesiredVisiblility;
                }
                else
                {
                    WebAction actionNode = node as WebAction;
                    thisMenu = BuildActionMenuItem(actionNode, dispatcher);
                }

                return(thisMenu);
            }
            catch (Exception ex)
            {
                // When an error happens here we need as much technical details as possible to diagnose the problem
                // Also, it's better to capture the error in English
                var itemName = node.LocalizedText;
                if (node is WebActionNode)
                {
                    itemName = (node as WebActionNode).LocalizedText;
                }
                if (node is WebAction)
                {
                    itemName = (node as WebAction).Label;
                }

                var message = new StringBuilder();
                message.AppendFormat("An expected error has occurred when building menu item labelled: {0}", itemName);
                message.AppendLine();
                message.AppendLine(string.Format("Details: {0}", ex.Message));
                message.AppendLine("Stack:");
                message.AppendLine(ex.StackTrace);

                var newEx = new Exception(message.ToString(), ex);
                throw newEx;
            }
        }
示例#36
0
 protected abstract Task Boost(WebAction action, string trackPath);