private void TableActions(IGingerWebElement element) { if (element is ITable Element) { switch (ElementAction) { case eElementAction.Click: Element.Click(); break; case eElementAction.GetValue: AOVs.Add(new NodeActionOutputValue() { Param = "Actual", Value = Element.GetValue() }); break; case eElementAction.SetValue: Element.SetValue(Value); break; } } }
private void LabelActions(IGingerWebElement element) { if (element is ILabel Label) { switch (ElementAction) { case eElementAction.GetFont: AOVs.Add(new NodeActionOutputValue() { Param = "Actual", Value = Label.GetFont() }); break; case eElementAction.GetText: AOVs.Add(new NodeActionOutputValue() { Param = "Actual", Value = Label.GetText() }); break; case eElementAction.GetValue: AOVs.Add(new NodeActionOutputValue() { Param = "Actual", Value = Label.Getvalue() }); break; } } }
private IGingerWebElement LocateElement(eElementType ElementType, string ElementLocateBy, string LocateByValue) { IGingerWebElement Element = null; switch (ElementLocateBy) { case "ByID": Element = PlatformService.LocateWebElement.LocateElementByID(ElementType, LocateByValue); break; case "ByCSSSelector": case "ByCSS": Element = PlatformService.LocateWebElement.LocateElementByCss(ElementType, LocateByValue); break; case "ByLinkText": Element = PlatformService.LocateWebElement.LocateElementByLinkTest(ElementType, LocateByValue); break; case "ByXPath": Element = PlatformService.LocateWebElement.LocateElementByXPath(ElementType, LocateByValue); break; } return(Element); }
private void ClickActions(IClick Element, eElementAction ClickElementAction) { switch (ClickElementAction) { case eElementAction.Click: Element.Click(); break; case eElementAction.JavaScriptClick: Element.JavascriptClick(); break; case eElementAction.MouseClick: Element.MouseClick(); break; case eElementAction.Select: Element.DoubleClick(); break; case eElementAction.ClickAndValidate: string ValidationType = (string)InputParams["ValidationType"]; string mClickType = (string)InputParams["ClickType"]; eElementAction ClickType = (eElementAction)Enum.Parse(typeof(eElementAction), mClickType); ClickActions(Element, ClickType); IGingerWebElement ValidationElement = GetValidationElement(); if ("IsVisible".Equals(ValidationType)) { if (ValidationElement.IsVisible()) { ExecutionInfo = "Validation element is Visible"; } else { Error = "Validation Element is not visble"; } } else if ("IsEnabled".Equals(ValidationType)) { if (ValidationElement.IsEnabled()) { ExecutionInfo = "Validation element is Enabled"; } else { Error = "Validation Element is not Enabled"; } } break; } }
IGingerWebElement GetValidationElement() { string ValidationElementLocateBy = (string)InputParams["ValidationElementLocateBy"]; string ValidationElementLocatorValue = (string)InputParams["ValidationElementLocatorValue"]; string mValidationElement = (string)InputParams["ValidationElement"]; eElementType validationElementType = (eElementType)Enum.Parse(typeof(eElementType), mValidationElement); IGingerWebElement ValidationElement = LocateElement(ref validationElementType, ValidationElementLocateBy, ValidationElementLocatorValue); return(ValidationElement); }
IGingerWebElement GetValidationElement() { string ValidationElementLocateBy = (string)InputParams["ValidationElementLocateBy"]; string ValidationElementLocatorValue = (string)InputParams["ValidationElementLocatorValue"]; string mValidationElement = (string)InputParams["ValidationElement"]; eElementType validationElementType = (eElementType)Enum.Parse(typeof(eElementType), mValidationElement); IGingerWebElement ValidationElement = WebPlatformActionHandler.LocateElement(ref validationElementType, ValidationElementLocateBy, ValidationElementLocatorValue, mPlatformService); return(ValidationElement); }
public void GetElem() { //Arrange IGingerWebElement GWE = Service.LocateWebElement.LocateElementByID(eElementType.WebElement, "GingerPhone"); //Assert Assert.AreNotEqual(null, GWE.Element); }
private void CanvasAction(IGingerWebElement element) { if (element is ICanvas E) { switch (ElementAction) { case eElementAction.DrawObject: E.DrawObject(); break; } } }
private void RadioButtonActions(IGingerWebElement element) { if (element is IClick ClickElement) { ClickActions(ClickElement, ElementAction); } else if (element is IGetValue GetElementValue) { } else { Error = "Not Supported Action"; } }
public void ExecuteAction(ref NodePlatformAction platformAction) { try { mPlatformAction = platformAction; InputParams = platformAction.InputParams; // convert the JArray to list of locators JObject Locators = (JObject)InputParams["Locators"]; eElementType ElementType = (eElementType)Enum.Parse(typeof(eElementType), (string)InputParams["ElementType"]); IGingerWebElement uiElement = null; foreach (JProperty locator in Locators.Children()) { uiElement = LocateElement(ref ElementType, locator.Name, locator.Value.ToString()); if (uiElement != null) { platformAction.exInfo += "UI Element Located using: " + locator.Name + "=" + locator.Value; break; } } if (uiElement == null) { platformAction.error += "Element not found"; return; } ElementAction = (eElementAction)Enum.Parse(typeof(eElementAction), (string)platformAction.InputParams["ElementAction"]); RunActionOnUIElement(uiElement, ElementType); //TODO: remove // update output values - TODO: do it directlyon platformAction !!! foreach (NodeActionOutputValue nodeActionOutputValue in AOVs) { platformAction.Output.Add(nodeActionOutputValue.Param, (string)nodeActionOutputValue.Value); // TODO: add path !!! } } catch (Exception Ex) { Error = Ex.Message; ExecutionInfo = Ex.StackTrace; // DO not put stacktrace !!!! } }
public void DragAndDrop(string DragDropType, IGingerWebElement targetElement) { switch (DragDropType) { case "DragDropSelenium": OpenQA.Selenium.Interactions.Actions action = new OpenQA.Selenium.Interactions.Actions(Driver); OpenQA.Selenium.Interactions.IAction dragdrop = action.ClickAndHold(this.WebElement).MoveToElement(targetElement.Element as IWebElement).Release(targetElement.Element as IWebElement).Build(); dragdrop.Perform(); break; case "DragDropJS": string script = Resources.Html5DragAndDrop; IJavaScriptExecutor executor = (IJavaScriptExecutor)Driver; executor.ExecuteScript(script, this.WebElement, targetElement); break; } }
private void ListActions(IGingerWebElement element) { if (element is IWebList Element) { string ValueToSelect; ValueToSelect = (string)InputParams["ValueToSelect"]; switch (ElementAction) { case eElementAction.ClearValue: Element.ClearValue(); break; case eElementAction.GetValidValues: Element.GetValidValue(); break; case eElementAction.IsValuePopulated: AOVs.Add(new NodeActionOutputValue() { Param = "Actual", Value = Element.IsValuePopulated() }); break; case eElementAction.GetValue: AOVs.Add(new NodeActionOutputValue() { Param = "Actual", Value = Element.GetValue() }); break; case eElementAction.Select: Element.Select(ValueToSelect); break; case eElementAction.SelectByIndex: Element.SelectByIndex(0); break; case eElementAction.SelectByText: Element.SelectByText(Value); break; } } }
private void HyperLinkActions(IGingerWebElement element, eElementAction mElementAction) { if (element is IHyperLink Hyperlink) { if (element is IClick ClickElement) { ClickActions(ClickElement, ElementAction); } else { switch (mElementAction) { case eElementAction.GetValue: AOVs.Add(new NodeActionOutputValue() { Param = "Actual", Value = Hyperlink.GetValue() }); break; } } } }
internal static IGingerWebElement LocateElement(ref eElementType ElementType, string ElementLocateBy, string LocateByValue, IWebPlatform mPlatformService) { IGingerWebElement Element = null; try { switch (ElementLocateBy) { case "ByID": Element = mPlatformService.LocateWebElement.LocateElementByID(ElementType, LocateByValue); break; case "ByCSSSelector": case "ByCSS": Element = mPlatformService.LocateWebElement.LocateElementByCss(ElementType, LocateByValue); break; case "ByLinkText": Element = mPlatformService.LocateWebElement.LocateElementByLinkTest(ElementType, LocateByValue); break; case "ByName": Element = mPlatformService.LocateWebElement.LocateElementByName(ElementType, LocateByValue); break; case "ByRelXPath": case "ByXPath": Element = mPlatformService.LocateWebElement.LocateElementByXPath(ElementType, LocateByValue); break; } if (Element != null && (ElementType == eElementType.WebElement || ElementType == eElementType.Unknown)) { if (Element is IButton) { ElementType = eElementType.Button; } else if (Element is ICanvas) { ElementType = eElementType.Canvas; } else if (Element is ICheckBox) { ElementType = eElementType.CheckBox; } else if (Element is IComboBox) { ElementType = eElementType.ComboBox; } else if (Element is IDiv) { ElementType = eElementType.Div; } else if (Element is IHyperLink) { ElementType = eElementType.HyperLink; } else if (Element is IImage) { ElementType = eElementType.Image; } else if (Element is ILabel) { ElementType = eElementType.Label; } else if (Element is IWebList) { ElementType = eElementType.List; } else if (Element is IRadioButton) { ElementType = eElementType.RadioButton; } else if (Element is ISpan) { ElementType = eElementType.Span; } else if (Element is ITable) { ElementType = eElementType.Table; } else if (Element is ITextBox) { ElementType = eElementType.TextBox; } } } catch { } return(Element); }
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; } }
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); } }
/// <summary> /// Perform Common action on GngerWebelement return true if iction is perfomed /// </summary> /// <param name="Element"></param> /// <returns></returns> private bool PerformCommonActions(IGingerWebElement Element) { bool performed = true; switch (ElementAction) { case eElementAction.DragDrop: IGingerWebElement TargetElement = null; Element.DragAndDrop("", TargetElement); break; case eElementAction.GetAttrValue: Element.GetAttribute(""); break; case eElementAction.GetHeight: AOVs.Add(new NodeActionOutputValue() { Param = "Height", Value = Element.GetHeight() }); break; case eElementAction.GetItemCount: throw new NotImplementedException("Get Item count is not implementd"); case eElementAction.GetSize: Size s = Element.GetSize(); AOVs.Add(new NodeActionOutputValue() { Param = "Height", Value = s.Height }); AOVs.Add(new NodeActionOutputValue() { Param = "Width", Value = s.Width }); break; case eElementAction.GetStyle: AOVs.Add(new NodeActionOutputValue() { Param = "Style", Value = Element.GetStyle() }); break; case eElementAction.GetWidth: AOVs.Add(new NodeActionOutputValue() { Param = "Width", Value = Element.GetWidth() }); break; case eElementAction.Hover: Element.Hover(); break; case eElementAction.IsEnabled: AOVs.Add(new NodeActionOutputValue() { Param = "Enabled", Value = Element.IsEnabled() }); break; case eElementAction.IsVisible: AOVs.Add(new NodeActionOutputValue() { Param = "Visible", Value = Element.IsVisible() }); break; case eElementAction.MouseRightClick: Element.RightClick(); break; case eElementAction.RunJavaScript: Element.RunJavascript(""); break; case eElementAction.SetFocus: Element.SetFocus(); break; default: performed = false; break; } return(performed); }
private void DivActions(IGingerWebElement element) { throw new NotImplementedException(); }
public void DragAndDrop(string DragDropType, IGingerWebElement targetElement) { Assert.Fail(); }
public void SwitchToFrame(IGingerWebElement WebElement) { throw new NotImplementedException(); }
private IGingerWebElement wrapper(eElementType elementType, IWebElement element) { IGingerWebElement Element = null; switch (elementType) { case eElementType.Button: // return the generic base element Element = new Button(); break; case eElementType.Canvas: // TODO: think if we want to check TagName to verify element type Element = new Canvas(); break; case eElementType.CheckBox: Element = new CheckBox(); break; case eElementType.ComboBox: Element = new ComboBox(); break; case eElementType.Div: Element = new GingerWebElement(); break; case eElementType.Image: Element = new GingerWebElement(); break; case eElementType.Label: Element = new Label(); break; case eElementType.List: Element = new List(); break; case eElementType.RadioButton: Element = new RadioButton(); break; case eElementType.Span: Element = new Span(); break; case eElementType.Table: Element = new Table(); break; case eElementType.TextBox: Element = new TextBox(); break; case eElementType.WebElement: case eElementType.Unknown: eElementType MyElemetType = GetElementType(element); if (MyElemetType == eElementType.Unknown) { Element = new GingerWebElement(); Element.Element = element; } else { Element = wrapper(MyElemetType, element); } break; case eElementType.HyperLink: Element = new HyperLink(); break; } Element.Element = element; if (Element is GingerWebElement GE) { GE.Driver = mDriver; } return(Element); }
public void ExecuteAction(ref NodePlatformAction platformAction) { try { mPlatformAction = platformAction; InputParams = platformAction.InputParams; // convert the JArray to list of locators JObject Locators = (JObject)InputParams["Locators"]; eElementType ElementType = (eElementType)Enum.Parse(typeof(eElementType), (string)InputParams["ElementType"]); IGingerWebElement uiElement = null; JArray Frames = null; if (InputParams.ContainsKey("Frames")) { Frames = (JArray)InputParams["Frames"]; if (Frames != null && Frames.Children().Count() > 0) { mPlatformService.BrowserActions.SwitchToDefaultContent(); foreach (JToken jf in Frames.Children()) { IGingerWebElement GWA = mPlatformService.LocateWebElement.LocateElementByXPath(eElementType.WebElement, jf.ToString()); mPlatformService.BrowserActions.SwitchToFrame(GWA); } } } foreach (JProperty locator in Locators.Children()) { uiElement = WebPlatformActionHandler.LocateElement(ref ElementType, locator.Name, locator.Value.ToString(), mPlatformService); if (uiElement != null) { platformAction.exInfo += "UI Element Located using: " + locator.Name + "=" + locator.Value; break; } } if (uiElement == null) { platformAction.error += "Element not found"; return; } ElementAction = (eElementAction)Enum.Parse(typeof(eElementAction), (string)platformAction.InputParams["ElementAction"]); RunActionOnUIElement(uiElement, ElementType); //TODO: remove // update output values - TODO: do it directlyon platformAction !!! foreach (NodeActionOutputValue nodeActionOutputValue in AOVs) { platformAction.Output.Add(nodeActionOutputValue.Param, (string)nodeActionOutputValue.Value); // TODO: add path !!! } } catch (Exception Ex) { Error = Ex.Message; ExecutionInfo = Ex.StackTrace; // DO not put stacktrace !!!! } }
private void RunActionOnUIElement(IGingerWebElement uiElement, eElementType ElementType) { // Try if it is common action first bool ActionPerformed = PerformCommonActions(uiElement); if (!ActionPerformed) { switch (ElementType) { case eElementType.Button: ButtonActions((IButton)uiElement); break; case eElementType.Canvas: CanvasAction(uiElement); break; case eElementType.CheckBox: CheckBoxActions(uiElement); break; case eElementType.ComboBox: ComboBoxActions(uiElement); break; case eElementType.Div: DivActions(uiElement); break; case eElementType.Image: ImageActions(uiElement); break; case eElementType.Label: LabelActions(uiElement); break; case eElementType.List: ListActions(uiElement); break; case eElementType.RadioButton: RadioButtonActions(uiElement); break; case eElementType.Span: SpanActions(uiElement); break; case eElementType.Table: TableActions(uiElement); break; case eElementType.TextBox: TextBoxActions((ITextBox)uiElement); break; case eElementType.HyperLink: HyperLinkActions(uiElement, ElementAction); break; } } }
public void SwitchToFrame(IGingerWebElement WebElement) { Driver.SwitchTo().Frame(WebElement.Element as IWebElement); }