private void ProcessActions(ConvertedCodeLine CCL) { string CodeLine = CCL.CodeLine; string value = ""; string SetValueinObject = ""; string varName = ""; string xpath = ""; string type = ""; if (CodeLine.Contains("WebEdit")) { if (CodeLine.Contains("WebEditTxtChange")) { type = "Edit Box"; SetValueinObject = GetStringBetween(CodeLine, ".WebEdit(\"", "\")"); varName = CodeLine.Substring(CodeLine.IndexOf("GlobalDictionary")).Replace("GlobalDictionary", "").Trim(); varName = varName.Replace("(", "").Replace(")", ""); value = "{Var Name=" + varName + "}"; //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } // Add Action to biz flow ActGenElement act = new ActGenElement(); act.Value = value.Replace("\"", "").Replace("\"", ""); act.GenElementAction = ActGenElement.eGenElementAction.SetValue; act.LocateBy = eLocateBy.ByXPath; act.LocateValue = xpath; act.Description = "Set value in " + SetValueinObject + " " + type; mBusinessFlow.AddAct(act); CCL.Converted = "New Action - ActGenElement.SetValue : LocateValue=" + act.LocateValue + ", Value=" + act.Value; CCL.Status = ConvertedCodeLine.eStatus.ConvertedToScript; } // Extract the WebEdit/WebCheckBox else if (CodeLine.Contains(".Set") || CodeLine.Contains(".set")) { if (CodeLine.Contains("WebEdit")) { type = "Edit Box"; SetValueinObject = GetStringBetween(CodeLine, ".WebEdit(\"", "\")"); //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } else if (CodeLine.Contains("WebCheckBox")) { type = "Check Box"; SetValueinObject = GetStringBetween(CodeLine, ".WebCheckBox(\"", "\")"); //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } // for Values to Set if (CodeLine.Contains("Set \"")) // For hard coded values { value = GetStringBetween(CodeLine, "Set \"", CodeLine[CodeLine.Length - 1].ToString()); } else if (CodeLine.Contains("GlobalDictionary")) { varName = CodeLine.Substring(CodeLine.IndexOf("GlobalDictionary")).Replace("GlobalDictionary", "").Trim(); varName = varName.Replace("(", "").Replace(")", ""); value = "{Var Name=" + varName + "}"; } else if (CodeLine.Contains("Globaldictionary")) { varName = CodeLine.Substring(CodeLine.IndexOf("Globaldictionary")).Replace("Globaldictionary", "").Trim(); varName = varName.Replace("(", "").Replace(")", ""); value = "{Var Name=" + varName + "}"; } else if (!CodeLine.Contains("GlobalDictionary") && !CodeLine.Contains("Globaldictionary")) // for variables declared using Dim { varName = CodeLine.Substring(CodeLine.IndexOf("Set")).Replace("Set", "").Trim(); value = "{Var Name=" + varName + "}"; VariableString v = new VariableString(); v.Description = GingerDicser.GetTermResValue(eTermResKey.Variable) + " added by UFT Script"; v.Name = varName; v.Value = value; mBusinessFlow.AddVariable(v); } // Add Action to biz flow ActGenElement act = new ActGenElement(); act.Value = value.Replace("\"", "").Replace("\"", ""); act.GenElementAction = ActGenElement.eGenElementAction.SetValue; act.LocateBy = eLocateBy.ByXPath; act.LocateValue = xpath; act.Description = "Set value in " + SetValueinObject + " " + type; mBusinessFlow.AddAct(act); CCL.Converted = "New Action - ActGenElement.SetValue : LocateValue=" + act.LocateValue + ", Value=" + act.Value; CCL.Status = ConvertedCodeLine.eStatus.ConvertedToScript; } // Extract the WebButton/Link/Image/WebELemnt else if (CodeLine.Contains(".Click") || CodeLine.Contains(".click")) { if (CodeLine.Contains("WebButton")) { type = "Button"; SetValueinObject = GetStringBetween(CodeLine, ".WebButton(\"", "\")"); //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } else if (CodeLine.Contains("Link")) { type = "Link"; SetValueinObject = GetStringBetween(CodeLine, ".Link(\"", "\")"); //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } else if (CodeLine.Contains("WebElement")) { type = "Web Element"; SetValueinObject = GetStringBetween(CodeLine, ".WebElement(\"", "\")"); //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } else if (CodeLine.Contains("Image")) { type = "Image"; SetValueinObject = GetStringBetween(CodeLine, ".Image(\"", "\")"); //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } // Add Action to biz flow ActGenElement act = new ActGenElement(); act.Value = ""; act.LocateBy = eLocateBy.ByXPath; act.LocateValue = xpath; act.GenElementAction = ActGenElement.eGenElementAction.Click; act.Description = "Click on " + SetValueinObject + " " + type; mBusinessFlow.AddAct(act); CCL.Converted = "New Action - ActGenElement.Click : LocateValue=" + act.LocateValue; // +", Value=" + act.Value; CCL.Status = ConvertedCodeLine.eStatus.ConvertedToScript; } // Extract the WeBlist/WebRadiogroup else if (CodeLine.Contains(".Select") || CodeLine.Contains(".select")) { if (CodeLine.Contains("WebList")) { type = "List"; SetValueinObject = GetStringBetween(CodeLine, ".WebList(\"", "\")"); //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } else if (CodeLine.Contains("WebRadiogroup")) { type = "Radio Group"; SetValueinObject = GetStringBetween(CodeLine, ".WebRadiogroup(\"", "\")"); //Calling function to indentify Locate By and Locate Value xpath = ProcessLocateBy_Value(SetValueinObject); } //For Values to Set if (CodeLine.Contains("Select \"")) // For hard coded values { value = GetStringBetween(CodeLine, "Select \"", CodeLine[CodeLine.Length - 1].ToString()); } else if (CodeLine.Contains("GlobalDictionary")) { varName = CodeLine.Substring(CodeLine.IndexOf("GlobalDictionary")).Replace("GlobalDictionary", "").Trim(); varName = varName.Replace("(", "").Replace(")", ""); value = "{Var Name=" + varName + "}"; } else if (CodeLine.Contains("Globaldictionary")) { varName = CodeLine.Substring(CodeLine.IndexOf("Globaldictionary")).Replace("Globaldictionary", "").Trim(); varName = varName.Replace("(", "").Replace(")", ""); value = "{Var Name=" + varName + "}"; } else { varName = CodeLine.Substring(CodeLine.IndexOf("Select ")).Replace("Select ", "").Trim(); value = "{Var Name=" + varName + "}"; VariableString v = new VariableString(); v.Description = GingerDicser.GetTermResValue(eTermResKey.Variable) + " added by UFT Script"; v.Name = varName; v.Value = value; mBusinessFlow.AddVariable(v); } // Add Action to biz flow ActGenElement act = new ActGenElement(); act.Value = value; act.LocateBy = eLocateBy.ByXPath; act.LocateValue = xpath; act.GenElementAction = ActGenElement.eGenElementAction.SetValue; act.Description = "Select value from " + SetValueinObject + " " + type; mBusinessFlow.AddAct(act); CCL.Converted = "New Action - ActGenElement.SetValue : LocateValue=" + act.LocateValue + ", Value=" + act.Value; CCL.Status = ConvertedCodeLine.eStatus.ConvertedToScript; } // Extract the URL to Navigate to else if (CodeLine.Contains("Navigate")) { // Extract the URL string URL = GetStringBetween(CodeLine, ".Navigate(\"", "\")"); // Add Action to biz flow ActGotoURL act = new ActGotoURL(); act.Value = URL; act.Description = "Navigate to URL"; mBusinessFlow.AddAct(act); CCL.Converted = "New Action - ActGotoURL : " + URL; CCL.Status = ConvertedCodeLine.eStatus.ConvertedToScript; } // Extract the URL launced using SystemUtil.Run else if (CodeLine.Contains("SystemUtil.Run") && CodeLine.Contains("iexplore.exe")) { // Extract the URL string URL = GetStringBetween(CodeLine, "iexplore.exe\",\"", "\""); // Add Action to biz flow ActGotoURL act = new ActGotoURL(); act.Value = URL; act.Description = "Navigate to URL"; mBusinessFlow.AddAct(act); CCL.Converted = "New Action - ActGotoURL : " + URL; CCL.Status = ConvertedCodeLine.eStatus.ConvertedToScript; } else if (CodeLine.Contains("fDBCheck") || CodeLine.Contains("fDBActivities")) //ASAP function { // Temp until we read the SQL from common.xls ActDBValidation act = new ActDBValidation(); act.Description = "DB Action-Configure Manually"; mBusinessFlow.AddAct(act); CCL.Converted = "New Action - DB Action "; CCL.Status = ConvertedCodeLine.eStatus.ConvertedToScript; } }
public override void RunAction(Act act) { //TODO: add func to Act + Enum for switch string actClass = act.GetType().ToString(); mUIAutomationHelper.mLoadTimeOut = mActionTimeout; mUIAutomationHelper.taskFinished = false; //TODO: avoid hard coded string... actClass = actClass.Replace("GingerCore.Actions.", ""); actClass = actClass.Replace("Windows.", ""); if (actClass != "ActSwitchWindow" || (actClass == "ActWindow" && ((ActWindow)act).WindowActionType != ActWindow.eWindowActionType.Switch)) { CheckRetrySwitchWindowIsNeeded(); } if (act.Timeout != null) { mUIAutomationHelper.mLoadTimeOut = act.Timeout; } try { switch (actClass) { case "ActWindow": ActWindow actWindow = (ActWindow)act; HandleWindowAction(actWindow); break; //TODO: ActSwitchWindow is the correct approach for switch window. And we should guide the users accordingly. case "ActSwitchWindow": mUIAutomationHelper.SmartSwitchWindow((ActSwitchWindow)act); break; case "ActWindowsControl": HandleWindowsControlAction((ActWindowsControl)act); break; case "ActGenElement": ActGenElement AGE = (ActGenElement)act; HandleWindowsGenericWidgetControlAction(AGE); break; case "ActMenuItem": ActMenuItem actMenuItem = (ActMenuItem)act; HandleMenuControlAction(actMenuItem); break; case "ActSmartSync": mUIAutomationHelper.SmartSyncHandler((ActSmartSync)act); break; case "ActScreenShot": try { //TODO: When capturing all windows, we do showwindow. for few applications show window is causing applicaiton to minimize //Disabling the capturing all windows for Windows driver until we fix show window issue Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); act.AddScreenShot(bmp); //if not running well. need to add return same as PBDrive } catch (Exception ex) { act.Error = "Error: Action failed to be performed, Details: " + ex.Message; } break; case "Common.ActUIElement": HandleUIElementAction(act); break; case "ActBrowserElement": ActBrowserElement actWBE = (ActBrowserElement)act; HandleWindowsBrowserElementAction(actWBE); break; case "ActTableElement": ActTableElement actTable = (ActTableElement)act; HandleWindowsWidgetTableControlAction(actTable); break; default: throw new Exception("Action unknown/Not Impl in Driver - " + this.GetType().ToString()); } GC.Collect(); GC.WaitForPendingFinalizers(); } catch (System.Runtime.InteropServices.COMException e) { Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e); CheckAndRetryRunAction(act, e); return; } catch (ElementNotAvailableException e) { Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e); CheckAndRetryRunAction(act, e); return; } catch (ArgumentException e) { Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e); CheckAndRetryRunAction(act, e); return; } catch (Exception e) { Reporter.ToLog(eLogLevel.WARN, "Exception at Run action", e); act.Error = e.Message; } }
private static void GetMultipleBFActGenElementActions() { mListBF = new ObservableList <BusinessFlow>(); BusinessFlow webBF = new BusinessFlow() { Name = "TestBFWebConversion", Active = true }; BusinessFlow winBF = new BusinessFlow() { Name = "TestBFWinConversion", Active = true }; BusinessFlow pbBF = new BusinessFlow() { Name = "TestBFPBConversion", Active = true }; Activity webActivity = new Activity(); webActivity.Active = true; webActivity.SelectedForConversion = true; webActivity.TargetApplication = "Web-App"; ActGenElement gen1 = new ActGenElement(); gen1.Active = true; gen1.Description = "Set Value : first_name input"; gen1.LocateBy = Amdocs.Ginger.Common.UIElement.eLocateBy.ByRelXPath; gen1.LocateValue = "//input[@name='first_name']"; gen1.GenElementAction = ActGenElement.eGenElementAction.SendKeys; webActivity.Acts.Add(gen1); webBF.AddActivity(webActivity); mListBF.Add(webBF); Activity winActivity = new Activity(); winActivity.Active = true; winActivity.SelectedForConversion = true; winActivity.TargetApplication = "Web-App"; ActGenElement gen2 = new ActGenElement(); gen2.Active = true; gen2.Description = "Set Value : last_name input"; gen2.LocateBy = Amdocs.Ginger.Common.UIElement.eLocateBy.ByRelXPath; gen2.LocateValue = "//input[@name='last_name']"; gen2.GenElementAction = ActGenElement.eGenElementAction.SendKeys; winActivity.Acts.Add(gen2); winBF.AddActivity(winActivity); mListBF.Add(winBF); Activity pbActivity = new Activity(); pbActivity.Active = true; pbActivity.SelectedForConversion = true; pbActivity.TargetApplication = "Web-App"; ActGenElement gen3 = new ActGenElement(); gen3.Active = true; gen3.Description = "Set Value : email input"; gen3.LocateBy = Amdocs.Ginger.Common.UIElement.eLocateBy.ByRelXPath; gen3.LocateValue = "//input[@name='email']"; gen3.GenElementAction = ActGenElement.eGenElementAction.SendKeys; pbActivity.Acts.Add(gen3); pbBF.AddActivity(pbActivity); mListBF.Add(pbBF); }
private void HandleWindowsGenericWidgetControlAction(ActGenElement actWinC) { IHTMLElement element = mUIAutomationHelper.GetHTMLHelper().GetActElement(actWinC); if (element == null) { actWinC.Error = "Element not Found - " + actWinC.LocateBy + " " + actWinC.LocateValueCalculated; return; } string value = string.Empty; bool result = false; string ValDrv = actWinC.ValueForDriver; try { switch (actWinC.GenElementAction) { case ActGenElement.eGenElementAction.SetValue: result = mUIAutomationHelper.GetHTMLHelper().SetValue(element, ValDrv); if (result) { actWinC.ExInfo = ValDrv + " set"; } else { actWinC.Error = "Unable to set value to " + ValDrv; } break; case ActGenElement.eGenElementAction.FireSpecialEvent: value = mUIAutomationHelper.GetHTMLHelper().FireSpecialEvent(element, ValDrv); if (value.StartsWith("Error")) { actWinC.Error = "Unable to fire special event. " + value; } else { actWinC.ExInfo = "Fire special event " + value; } break; case ActGenElement.eGenElementAction.SendKeys: result = mUIAutomationHelper.GetHTMLHelper().SendKeys(element, ValDrv); if (result) { actWinC.ExInfo = ValDrv + " Keys Sent"; } else { actWinC.Error = "Unable to Send Keys " + ValDrv; } break; case ActGenElement.eGenElementAction.GetValue: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, "value"); if (string.IsNullOrEmpty(value)) { actWinC.Error = "Unable to Get value of " + ValDrv; } else { actWinC.AddOrUpdateReturnParamActual("Actual", value.ToString()); actWinC.ExInfo = value.ToString(); } break; case ActGenElement.eGenElementAction.ClickAt: result = mUIAutomationHelper.GetHTMLHelper().ClickAt(element, ValDrv); if (result) { actWinC.ExInfo = "Element Clicked"; } else { actWinC.Error = "Element Unable to Clicked"; } break; case ActGenElement.eGenElementAction.Click: case ActGenElement.eGenElementAction.AsyncClick: result = mUIAutomationHelper.GetHTMLHelper().Click(element); if (result) { actWinC.ExInfo = "Element Clicked"; } else { actWinC.Error = "Element Unable to Clicked"; } break; case ActGenElement.eGenElementAction.RightClick: result = mUIAutomationHelper.GetHTMLHelper().RightClick(element, ValDrv); if (result) { actWinC.ExInfo = "Element Right Click Done"; } else { actWinC.Error = "Element Unable to Right Click"; } break; case ActGenElement.eGenElementAction.Enabled: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, "disabled"); value = value.ToString().ToLower().Equals("false") ? "true" : "false"; actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); break; case ActGenElement.eGenElementAction.Hover: result = mUIAutomationHelper.GetHTMLHelper().MouseHover(element, ValDrv); if (result) { actWinC.ExInfo = "Element Hover Done"; } else { actWinC.Error = "Unable to Hover the Element"; } break; case ActGenElement.eGenElementAction.ScrollToElement: result = mUIAutomationHelper.GetHTMLHelper().scrolltoElement(element); if (result) { actWinC.ExInfo = "Scroll to Element Done"; } else { actWinC.Error = "Unable to Scroll to Element"; } break; case ActGenElement.eGenElementAction.Visible: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, "type"); value = value.Equals("hidden") ? "false" : "true"; actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); break; case ActGenElement.eGenElementAction.SelectFromDropDown: value = mUIAutomationHelper.GetHTMLHelper().SelectFromDropDown(element, ValDrv); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to select value-" + ValDrv + " from DropDown"; } break; case ActGenElement.eGenElementAction.SelectFromDropDownByIndex: result = mUIAutomationHelper.GetHTMLHelper().SetValue(element, ValDrv); if (result) { actWinC.ExInfo = ValDrv + " set"; } else { actWinC.Error = "Unable to Set Value " + ValDrv; } break; case ActGenElement.eGenElementAction.GetInnerText: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, "innerText"); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to get Inner Text"; } break; case ActGenElement.eGenElementAction.GetStyle: value = mUIAutomationHelper.GetHTMLHelper().GetStyle(element); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to get Element Style"; } break; case ActGenElement.eGenElementAction.GetElementAttributeValue: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, ValDrv); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to get custom attribute"; } break; case ActGenElement.eGenElementAction.GetCustomAttribute: value = mUIAutomationHelper.GetHTMLHelper().GetNodeAttributeValue(element, ValDrv); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to get custom attribute"; } break; case ActGenElement.eGenElementAction.SwitchFrame: value = mUIAutomationHelper.GetHTMLHelper().SwitchFrame(actWinC.LocateBy, actWinC.LocateValueCalculated); if (value.Equals("true")) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = "Switched to frame"; } else { actWinC.Error = "Unable Switch frame"; } break; case ActGenElement.eGenElementAction.HighLightElement: value = mUIAutomationHelper.GetHTMLHelper().HighLightElement(element); if (value.Equals("true")) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = "Element Highlighted"; } else { actWinC.Error = "Unable To Highlight Element"; } break; default: actWinC.Error = "Unknown Action - " + actWinC.GenElementAction; break; } } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
public override void RunAction(Act act) { //TODO: add func to Act + Enum for switch string actClass = act.GetType().ToString(); mUIAutomationHelper.mLoadTimeOut = mActionTimeout; mUIAutomationHelper.taskFinished = false; //TODO: avoid hard coded string... actClass = actClass.Replace("GingerCore.Actions.", ""); if (actClass != "ActUIASwitchWindow" && actClass != "ActSwitchWindow") { CheckRetrySwitchWindowIsNeeded(); } if (act.Timeout != null) { mUIAutomationHelper.mLoadTimeOut = act.Timeout; } try { Reporter.ToLog(eLogLevel.DEBUG, "Start Executing action of type '" + actClass + "' Description is" + act.Description); switch (actClass) { case "ActPBControl": ActPBControl actPBC = (ActPBControl)act; HandlePBControlAction(actPBC); break; case "ActGenElement": ActGenElement AGE = (ActGenElement)act; HandlePBGenericWidgetControlAction(AGE); break; case "ActBrowserElement": ActBrowserElement actBE = (ActBrowserElement)act; HandlePBBrowserElementAction(actBE); break; //TODO: ActSwitchWindow is the correct approach for switch window. And we should guide the users accordingly. //Down the line we need to clean up ActUIASwitchWindow. This is old way, but we keep it to support old actions case "ActUIASwitchWindow": mUIAutomationHelper.SwitchWindow((ActUIASwitchWindow)act); break; case "ActSwitchWindow": mUIAutomationHelper.SmartSwitchWindow((ActSwitchWindow)act); break; case "ActMenuItem": ActMenuItem actMenuItem = (ActMenuItem)act; HandleMenuControlAction(actMenuItem); break; case "ActWindow": ActWindow actWindow = (ActWindow)act; HandleWindowControlAction(actWindow); break; //case "ActUIAButton": // ActUIAButton b = (ActUIAButton)act; // UIA.ClickButton(b); // break; //case "ActUIATextBox": // ActUIATextBox ATB = (ActUIATextBox)act; // if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.SetValue) // { // UIA.SetTextBoxValue(ATB); // return; // } // if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.GetValue) UIA.GetTextBoxValue(ATB); // //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.GetValue) UIA.GetTextBoxValue(ATB); // //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.IsDisabled) UIA.IsTextBoxDisabled(ATB); // //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.GetFont) UIA.GetTextBoxFont(ATB); // //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.IsPrepopulated) UIA.IsTextBoxPrepopulated(ATB); // //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.IsRequired) UIA.IsTextBoxRequired(ATB); // //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.IsDisplayed) UIA.IsTextBoxDisplayed(ATB); // //if (ATB.UIATextBoxAction == ActUIATextBox.eUIATextBoxAction.GetInputLength) UIA.GetTextBoxInputLength(ATB); // break; //case "ActUIALabel": // if (((ActUIALabel)act).LabelAction == ActUIALabel.eLabelAction.GetForeColor) UIA.LabelGetColor((ActUIALabel)act); // break; //TODO: What Jave is doing here? is it needed? case "Java.ActTableElement": ActTableElement actTable = (ActTableElement)act; mUIAutomationHelper.HandleGridControlAction(actTable); break; case "ActTableElement": ActTableElement actTable1 = (ActTableElement)act; mUIAutomationHelper.HandleGridControlAction(actTable1); break; case "ActSmartSync": mUIAutomationHelper.SmartSyncHandler((ActSmartSync)act); break; //case "ActUIAClickOnPoint": // ActUIAClickOnPoint ACP = (ActUIAClickOnPoint)act; // if (ACP.ActUIAClickOnPointAction == ActUIAClickOnPoint.eUIAClickOnPointAction.ClickXY) UIA.ClickOnPoint(ACP); // break; case "ActScreenShot": try { //TODO: Implement Multi window capture if (act.WindowsToCapture == Act.eWindowsToCapture.AllAvailableWindows) { List <AppWindow> list = mUIAutomationHelper.GetListOfDriverAppWindows(); List <Bitmap> bList; foreach (AppWindow aw in list) { Bitmap bmp = mUIAutomationHelper.GetAppWindowAsBitmap(aw); act.AddScreenShot(bmp); bList = mUIAutomationHelper.GetAppDialogAsBitmap(aw); foreach (Bitmap tempbmp in bList) { act.AddScreenShot(tempbmp); } bList.Clear(); } } else { Bitmap bmp = mUIAutomationHelper.GetCurrentWindowBitmap(); act.AddScreenShot(bmp); } return; } catch (Exception ex) { act.Error = "Error: Action failed to be performed, Details: " + ex.Message; } break; //case "ActUIAImage": // if (((ActUIAImage)act).ImageAction == ActUIAImage.eImageAction.IsVisible) UIA.ImageIsVisible((ActUIAImage)act); // break; //case "ActPBControl": // ActPBControl APBC = (ActPBControl)act; // RunControlAction(APBC); // break; //case "ActMenuItem": // ActMenuItem ami = (ActMenuItem)act; // MenuItem(ami); // break; case "Common.ActUIElement": //ActUIElement actUIPBC = (ActUIElement)act; HandleUIElementAction(act); break; default: throw new Exception("Action unknown/Not Impl in Driver - " + this.GetType().ToString()); } } catch (System.Runtime.InteropServices.COMException e) { Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e); CheckAndRetryRunAction(act, e); return; } catch (ElementNotAvailableException e) { Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e); CheckAndRetryRunAction(act, e); return; } catch (ArgumentException e) { Reporter.ToLog(eLogLevel.ERROR, "Exception at Run action:" + act.GetType() + " Description:" + act.Description + " Error details:", e); CheckAndRetryRunAction(act, e); return; } catch (Exception e) { Reporter.ToLog(eLogLevel.WARN, "Exception at Run action", e); act.Error = e.Message; } }
public void Hover_Test() { // TODO: ActGenElement act = new ActGenElement(); act.LocateBy = eLocateBy.ByName; act.GenElementAction = ActGenElement.eGenElementAction.Hover; act.LocateValueCalculated = "stateForStandard"; act.AddNewReturnParams = true; act.Active = true; mBF.CurrentActivity.Acts.Add(act); mBF.CurrentActivity.Acts.CurrentItem = act; mGR.RunAction(act, false); ActPBControl action = new ActPBControl(); string actual = ""; action = new ActPBControl(); action.LocateBy = eLocateBy.ByName; action.ControlAction = ActPBControl.eControlAction.IsExist; action.LocateValueCalculated = "Script Error"; action.AddNewReturnParams = true; action.Timeout = 10; action.Active = true; mBF.CurrentActivity.Acts.Add(action); mBF.CurrentActivity.Acts.CurrentItem = action; //Act mGR.RunAction(action, false); Assert.AreEqual(action.Status, eRunStatus.Passed, "Action Status"); actual = action.GetReturnParam("Actual"); if (actual.Equals("True")) { Assert.AreEqual(action.Status, eRunStatus.Passed, "Action Status"); while (!String.IsNullOrEmpty(actual) && actual.Equals("True")) { ActPBControl PbAct = new ActPBControl(); PbAct.LocateBy = eLocateBy.ByXPath; PbAct.ControlAction = ActPBControl.eControlAction.Click; PbAct.LocateValueCalculated = @"/Script Error/[LocalizedControlType:title bar]/Close"; PbAct.Active = true; PbAct.AddNewReturnParams = true; mBF.CurrentActivity.Acts.Add(PbAct); mBF.CurrentActivity.Acts.CurrentItem = PbAct; mGR.RunAction(PbAct, false); action = new ActPBControl(); action.LocateBy = eLocateBy.ByName; action.ControlAction = ActPBControl.eControlAction.IsExist; action.LocateValueCalculated = "Script Error"; action.AddNewReturnParams = true; action.Timeout = 10; action.Active = true; mBF.CurrentActivity.Acts.Add(action); mBF.CurrentActivity.Acts.CurrentItem = action; //Act mGR.RunAction(action, false); actual = PbAct.GetReturnParam("Actual"); } } else { Assert.AreEqual(action.Status, eRunStatus.Failed, "Action Status"); } ActGenElement actGen = new ActGenElement(); actGen.LocateBy = eLocateBy.ByName; actGen.GenElementAction = ActGenElement.eGenElementAction.Click; actGen.LocateValueCalculated = "lastName"; actGen.Active = true; mBF.CurrentActivity.Acts.Add(actGen); mBF.CurrentActivity.Acts.CurrentItem = actGen; mGR.RunAction(actGen, false); }
public void RightClick_Test() { ActGenElement act = new ActGenElement(); //act.LocateBy = eLocateBy.ByName; //act.GenElementAction = ActGenElement.eGenElementAction.Hover; //act.LocateValueCalculated = "lastName"; //act.Active = true; //mBF.CurrentActivity.Acts.Add(act); //mBF.CurrentActivity.Acts.CurrentItem = act; //mGR.RunAction(act, false); act = new ActGenElement(); act.LocateBy = eLocateBy.ByName; act.GenElementAction = ActGenElement.eGenElementAction.SetValue; act.LocateValueCalculated = "lastName"; act.Value = "CoreTeam"; act.Active = true; mBF.CurrentActivity.Acts.Add(act); mBF.CurrentActivity.Acts.CurrentItem = act; mGR.RunAction(act, false); act = new ActGenElement(); act.LocateBy = eLocateBy.ByName; act.GenElementAction = ActGenElement.eGenElementAction.SetValue; act.LocateValueCalculated = "lastName"; act.Value = "*****@*****.**"; act.Active = true; mBF.CurrentActivity.Acts.Add(act); mBF.CurrentActivity.Acts.CurrentItem = act; mGR.RunAction(act, false); act = new ActGenElement(); act.LocateBy = eLocateBy.ByName; act.GenElementAction = ActGenElement.eGenElementAction.RightClick; act.LocateValueCalculated = "lastName"; act.Active = true; mBF.CurrentActivity.Acts.Add(act); mBF.CurrentActivity.Acts.CurrentItem = act; mGR.RunAction(act, false); act = new ActGenElement(); act.LocateBy = eLocateBy.ByXPath; act.GenElementAction = ActGenElement.eGenElementAction.SendKeys; act.LocateValueCalculated = "/html[1]/body[1]/div[1]/table[1]/tbody[1]/tr[2]/td[2]/table[1]/tbody[1]/tr[2]/td[1]/table[1]/tbody[1]/tr[1]/td[3]/div[1]/form[1]/table[1]/tbody[1]/tr[3]/td[1]/table[1]/tbody[1]/tr[2]/td[1]/table[1]/tbody[1]/tr[2]/td[2]/table[1]/tbody[1]/tr[1]/td[1]/table[1]/tbody[1]/tr[3]/td[3]/input[1]"; act.Value = "u"; act.Wait = 2; act.Active = true; mBF.CurrentActivity.Acts.Add(act); mBF.CurrentActivity.Acts.CurrentItem = act; mGR.RunAction(act, false); act = new ActGenElement(); act.LocateBy = eLocateBy.ByName; act.GenElementAction = ActGenElement.eGenElementAction.GetValue; act.LocateValueCalculated = "lastName"; act.AddNewReturnParams = true; act.Active = true; mBF.CurrentActivity.Acts.Add(act); mBF.CurrentActivity.Acts.CurrentItem = act; mGR.RunAction(act, false); Assert.AreEqual(act.Status, eRunStatus.Passed, "Action Status"); string actual = act.GetReturnParam("Actual"); Assert.AreEqual(actual, "CoreTeam", "True"); Assert.AreEqual(act.Error, null, "Act.Error"); }
//Handle all Generic Actions public void GenElementHandler(ActGenElement act) { IWebElement e; switch (act.GenElementAction) { //Click and ClickAt case ActGenElement.eGenElementAction.ClickAt: case ActGenElement.eGenElementAction.Click: e = LocateElement(act); if (e == null) { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValue; return; } else { e.Click(); } break; //Set Value case ActGenElement.eGenElementAction.SetValue: e = LocateElement(act); if (e != null) { if (e.TagName == "select") { SelectElement combobox = new SelectElement(e); string val = act.ValueForDriver; combobox.SelectByText(val); act.ExInfo += "Selected Value - " + val; return; } if (e.TagName == "input" && e.GetAttribute("type") == "checkbox") { ((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].setAttribute('checked',arguments[1])", e, act.ValueForDriver); return; } //Special case for FF if (Driver.GetType() == typeof(FirefoxDriver) && e.TagName == "input" && e.GetAttribute("type") == "text") { e.Clear(); e.SendKeys(GetKeyName(act.ValueForDriver)); } else { ((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].setAttribute('value',arguments[1])", e, act.ValueForDriver); } } else { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValueCalculated; return; } break; //KeyType - similar to Keyboard Input case ActGenElement.eGenElementAction.KeyType: e = LocateElement(act); if (e != null) { e.Clear(); e.SendKeys(GetKeyName(act.ValueForDriver)); } else { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValueCalculated; return; } break; //Keyboard Input - similar to KeyType case ActGenElement.eGenElementAction.KeyboardInput: e = LocateElement(act); if (e != null) { e.SendKeys(GetKeyName(act.ValueForDriver)); } else { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValueCalculated; return; } break; //Check this case ActGenElement.eGenElementAction.GetValue: e = LocateElement(act); if (e != null) { act.AddOrUpdateReturnParamActual("Actual", e.GetAttribute("text")); if (act.GetReturnParam("Actual") == null) { act.AddOrUpdateReturnParamActual("Actual", e.Text); } } else { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValue; return; } break; //GoToURL - implemented also as GoToURL action and not in GenElementHandler action case ActGenElement.eGenElementAction.GotoURL: string sURL = act.ValueForDriver.ToLower(); if (sURL.StartsWith("www")) { sURL = "http://" + act.ValueForDriver; } else { sURL = act.ValueForDriver; } Driver.Navigate().GoToUrl(sURL); break; //Wait Action case ActGenElement.eGenElementAction.Wait: WaitAction(act); break; //Delete all Cookies case ActGenElement.eGenElementAction.DeleteAllCookies: //TODO: FIXME: This action should not be part of GenElement Driver.Manage().Cookies.DeleteAllCookies(); break; //Back Click case ActGenElement.eGenElementAction.Back: //TODO: FIXME: This action should not be part of GenElement PressBackBtn(); break; case ActGenElement.eGenElementAction.CloseBrowser: Dictionary <String, Object> pars = new Dictionary <String, Object>(); Driver.ExecuteScript("mobile:monitor:stop", pars); break; } }