コード例 #1
0
        public void HandleRunAction(IPlatformService service, ref NodePlatformAction platformAction)
        {
            Platformservice = (IWebServicePlatform)service;

            RestClient = Platformservice.RestClient;

            try
            {
                GingerHttpRequestMessage Request = GetRequest(platformAction);

                GingerHttpResponseMessage Response = RestClient.PerformHttpOperation(Request);
                platformAction.Output.Add("Header: Status Code ", Response.StatusCode.ToString());

                foreach (var RespHeader in Response.Headers)
                {
                    platformAction.Output.Add("Header: " + RespHeader.Key, RespHeader.Value);
                }

                platformAction.Output.Add("Request:", Response.RequestBodyString);
                platformAction.Output.Add("Response:", Response.Resposne);
            }

            catch (Exception ex)
            {
                platformAction.addError(ex.Message);
            }
        }
コード例 #2
0
        private void ExecuteSmartSyncAction(IWebPlatform webPlatformService, ref NodePlatformAction platformAction)
        {
            Dictionary <string, object> InputParams = platformAction.InputParams;

            int MaxTimeout = Int32.Parse(InputParams.ContainsKey("WaitTime") ? InputParams["WaitTime"].ToString() : (string.IsNullOrEmpty(InputParams["Value"].ToString()) ? "5" : InputParams["Value"].ToString()));

            string SmartSyncAction = InputParams["SmartSyncAction"] as string;

            string LocateValue = InputParams["LocateValue"] as string;

            string       LocateBy    = InputParams["LocateBy"] as string;
            eElementType ElementType = eElementType.WebElement;

            IGingerWebElement WebElement = null;
            Stopwatch         st         = new Stopwatch();

            switch (SmartSyncAction)
            {
            case "WaitUntilDisplay":
                st.Reset();
                st.Start();
                WebElement = LocateElement(ref ElementType, LocateBy, LocateValue, webPlatformService);

                while (!(WebElement != null && (WebElement.IsVisible() || WebElement.IsEnabled())))
                {
                    Task.Delay(100);
                    WebElement = LocateElement(ref ElementType, LocateBy, LocateValue, webPlatformService);

                    if (st.ElapsedMilliseconds > MaxTimeout * 1000)
                    {
                        platformAction.addError("Smart Sync of WaitUntilDisplay is timeout");
                        break;
                    }
                }
                break;

            case "WaitUntilDisapear":
                st.Reset();
                st.Start();

                WebElement = LocateElement(ref ElementType, LocateBy, LocateValue, webPlatformService);

                if (WebElement == null)
                {
                    return;
                }
                else
                {
                    st.Start();

                    while (WebElement != null && WebElement.IsVisible())
                    {
                        Task.Delay(100);
                        WebElement = LocateElement(ref ElementType, LocateBy, LocateValue, webPlatformService);
                        if (st.ElapsedMilliseconds > MaxTimeout * 1000)
                        {
                            platformAction.addError("Smart Sync of WaitUntilDisapear is timeout");
                            break;
                        }
                    }
                }
                break;

            default:
                platformAction.error = "Smart Sync " + SmartSyncAction + "Action Not found";
                break;
            }
        }
コード例 #3
0
        public void ExecuteAction(ref NodePlatformAction platformAction)
        {
            InputParams = platformAction.InputParams;



            string Value = (string)InputParams["Value"];
            List <NodeActionOutputValue> AOVs = new List <NodeActionOutputValue>();

            try
            {
                // use enum or string/const ???
                eControlAction ElementAction = (eControlAction)Enum.Parse(typeof(eControlAction), InputParams["ControlAction"].ToString());
                switch (ElementAction)
                {
                case eControlAction.GotoURL:
                    string GotoURLType = String.Empty;

                    if (InputParams.ContainsKey("GotoURLType"))
                    {
                        GotoURLType = (string)InputParams["GotoURLType"];
                    }
                    if (string.IsNullOrEmpty(GotoURLType))
                    {
                        GotoURLType = "Current";
                    }

                    BrowserService.Navigate(Value, GotoURLType);



                    platformAction.exInfo += "Navigated to: " + Value;

                    break;

                case eControlAction.GetPageURL:
                    platformAction.Output.Add("PageUrl", BrowserService.GetCurrentUrl());
                    break;

                case eControlAction.Maximize:
                    BrowserService.Maximize();
                    break;

                case eControlAction.Close:
                    BrowserService.CloseCurrentTab();
                    break;

                case eControlAction.CloseAll:
                    BrowserService.CloseWindow();
                    break;

                case eControlAction.Refresh:
                    BrowserService.Refresh();
                    break;

                case eControlAction.NavigateBack:
                    BrowserService.NavigateBack();
                    break;

                case eControlAction.DismissMessageBox:
                    BrowserService.DismissAlert();
                    break;

                case eControlAction.DeleteAllCookies:
                    BrowserService.DeleteAllCookies();
                    break;

                case eControlAction.AcceptMessageBox:

                    BrowserService.AcceptAlert();
                    break;

                case eControlAction.GetWindowTitle:

                    string Title = BrowserService.GetTitle();

                    AOVs.Add(new NodeActionOutputValue()
                    {
                        Param = "Actual", Value = Title
                    });
                    break;

                case eControlAction.GetMessageBoxText:

                    string AlertText = BrowserService.GetAlertText();
                    AOVs.Add(new NodeActionOutputValue()
                    {
                        Param = "Actual", Value = AlertText
                    });
                    break;

                case eControlAction.SetAlertBoxText:


                    string value = (string)InputParams["Value"];
                    BrowserService.SendAlertText(value);
                    break;

                case eControlAction.SwitchFrame:
                    string ElementLocateBy;
                    string Locatevalue;
                    string mElementType = "";
                    Locatevalue = (string)InputParams["LocateValue"];

                    object elb;
                    InputParams.TryGetValue("ElementLocateBy", out elb);

                    ElementLocateBy = elb != null?elb.ToString() : "";

                    if (string.IsNullOrEmpty(ElementLocateBy))
                    {
                        ElementLocateBy = (string)InputParams["LocateBy"];
                    }

                    if (string.IsNullOrEmpty(Locatevalue))
                    {
                        Locatevalue = (string)InputParams["Value"];
                    }


                    eElementType ElementType = eElementType.WebElement;
                    _ = Enum.TryParse <eElementType>(mElementType, out ElementType);
                    IGingerWebElement Element = LocateElement(ElementType, ElementLocateBy, Locatevalue);
                    BrowserService.SwitchToFrame(Element);
                    break;

                case eControlAction.RunJavaScript:
                    string javascript = (string)InputParams["javascript"];
                    object Output     = BrowserService.ExecuteScript(javascript);
                    if (Output != null)
                    {
                        platformAction.Output.Add("Actual", Output.ToString());
                    }
                    break;

                case eControlAction.GetPageSource:

                    string PageSource = BrowserService.GetPageSource();
                    AOVs.Add(new NodeActionOutputValue()
                    {
                        Param = "PageSource", Value = PageSource
                    });

                    break;

                case eControlAction.InjectJS:



                    break;
                }
            }
            catch (Exception ex)
            {
                platformAction.addError(ex.Message);
            }

            finally
            {
                platformAction.Output.OutputValues.AddRange(AOVs);
            }
        }