private static string GetCalculatedValue(Context context, string stringToCalculate) { IValueExpression mVE = new GingerCore.ValueExpression(context.Environment, context.BusinessFlow, new ObservableList <GingerCore.DataSource.DataSourceBase>(), false, "", false); mVE.Value = stringToCalculate; return(mVE.ValueCalculated); }
static NewPayLoad GeneratePlatformActionPayload(IActPluginExecution ACT, Agent agent) { PlatformAction platformAction = ACT.GetAsPlatformAction(); if (ACT is ActUIElement actUi) { if (actUi.ElementLocateBy == eLocateBy.POMElement) { AddPOMLocators(ref platformAction, ref actUi, agent.ProjEnvironment, agent.BusinessFlow); } } // TODO: calculate VE ??!! NewPayLoad payload = new NewPayLoad("RunPlatformAction"); payload.AddJSONValue <PlatformAction>(platformAction); payload.ClosePackage(); // TODO: Process Valuefordriver!!!! return(payload); void AddPOMLocators(ref PlatformAction PlatformAction, ref ActUIElement UIElementAction, ProjEnvironment projEnvironment, BusinessFlow businessFlow) { Dictionary <string, string> Locators = new Dictionary <string, string>(); List <string> Frames = new List <string>(); string[] pOMandElementGUIDs = UIElementAction.ElementLocateValue.ToString().Split('_'); Guid selectedPOMGUID = new Guid(pOMandElementGUIDs[0]); ApplicationPOMModel currentPOM = amdocs.ginger.GingerCoreNET.WorkSpace.Instance.SolutionRepository.GetRepositoryItemByGuid <ApplicationPOMModel>(selectedPOMGUID); if (currentPOM == null) { UIElementAction.ExInfo = string.Format("Failed to find the mapped element Page Objects Model with GUID '{0}'", selectedPOMGUID.ToString()); return; } Guid selectedPOMElementGUID = new Guid(pOMandElementGUIDs[1]); ElementInfo selectedPOMElement = (ElementInfo)currentPOM.MappedUIElements.Where(z => z.Guid == selectedPOMElementGUID).FirstOrDefault(); if (selectedPOMElement == null) { UIElementAction.ExInfo = string.Format("Failed to find the mapped element with GUID '{0}' inside the Page Objects Model", selectedPOMElement.ToString()); return; } else { List <NewPayLoad> switchframpayload = new List <NewPayLoad>(); if (selectedPOMElement.Path != null) { string[] spliter = new string[] { "," }; string[] iframesPathes = selectedPOMElement.Path.Split(spliter, StringSplitOptions.RemoveEmptyEntries); foreach (string iframePath in iframesPathes) { Frames.Add(iframePath); } } PlatformAction.InputParams.Add("Frames", Frames); //adding all locators from POM foreach (ElementLocator locator in selectedPOMElement.Locators.Where(x => x.Active == true).ToList()) { string locateValue; if (locator.IsAutoLearned) { locateValue = locator.LocateValue; } else { ElementLocator evaluatedLocator = locator.CreateInstance() as ElementLocator; GingerCore.ValueExpression VE = new GingerCore.ValueExpression(projEnvironment, businessFlow); locateValue = VE.Calculate(evaluatedLocator.LocateValue); } Locators.Add(locator.LocateBy.ToString(), locateValue); } if (PlatformAction.InputParams.ContainsKey("Locators")) { PlatformAction.InputParams["Locators"] = Locators; } else { PlatformAction.InputParams.Add("Locators", Locators); } } } }
private void SetDriverConfiguration() { Boolean bValue; if (DriverConfiguration == null) { return; } if (ProjEnvironment == null) { ProjEnvironment = new Environments.ProjEnvironment();//to avoid value expertion exception } if (BusinessFlow == null) { BusinessFlow = new GingerCore.BusinessFlow();//to avoid value expertion exception } foreach (DriverConfigParam DCP in DriverConfiguration) { //process Value expression in case used ValueExpression VE = new ValueExpression(ProjEnvironment, BusinessFlow, DSList); VE.Value = DCP.Value; string value = VE.ValueCalculated; //TODO: check if Convert.To is better option //TODO: hanlde other feilds type PropertyInfo tp = Driver.GetType().GetProperty(DCP.Parameter); if (tp != null) { string tpName = tp.PropertyType.Name; switch (tpName) { case "String": Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, value); break; case "Boolean": try { bValue = Convert.ToBoolean(value); } catch (Exception) { bValue = true; } Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, bValue); break; case "Int32": int i = int.Parse(value); Driver.GetType().GetProperty(DCP.Parameter).SetValue(Driver, i); break; case "eType": //TODO: Handle enums later... throw new Exception("Driver Config - Enum not supported yet"); default: Reporter.ToUser(eUserMsgKeys.SetDriverConfigTypeNotHandled, DCP.GetType().ToString()); break; } } else { // TODO: show message to user to remove param - old } } Driver.AdvanceDriverConfigurations = this.AdvanceAgentConfigurations; }