private IWebElement LocateElement(GingerAction gingerAction, eElementType elementType, eLocateBy locateBy, string locateValue) { try { IWebElement e = null; switch (locateBy) { case eLocateBy.Id: e = mDriver.FindElement(By.Id(locateValue)); return(e); case eLocateBy.Name: e = mDriver.FindElement(By.Name(locateValue)); return(e); case eLocateBy.Text: e = mDriver.FindElement(By.CssSelector("text=" + locateValue)); return(e); case eLocateBy.XPath: e = mDriver.FindElement(By.XPath(locateValue)); return(e); //TODO: all the rest default: gingerAction.AddError("LocateElement", "Locator not implemented - " + locateBy); return(null); } } catch (Exception ex) { gingerAction.AddError("LocateElement", ex.Message); return(null); } }
public void HTTP(GingerAction gingerAction, string url) { if (mDisplay != null) { mDisplay.URL = url; } // mDisplay.WriteLine("Geeting HTTP URL" + url); // example to show error checks if (!url.StartsWith("HTTP", StringComparison.InvariantCultureIgnoreCase)) { gingerAction.AddError("WebServicesDriver.HTTP", "URL must start with HTTP - " + url); return; } using (var client = new HttpClient()) { Stopwatch stopwatch = Stopwatch.StartNew(); var result = client.GetAsync(url).Result; stopwatch.Stop(); gingerAction.Output.Add("Status Code", result.StatusCode.ToString()); gingerAction.Output.Add("Elapsed", stopwatch.ElapsedMilliseconds.ToString()); if (mDisplay != null) { mDisplay.AddLog("Elapsed - " + stopwatch.ElapsedMilliseconds); } } gingerAction.ExInfo = "URL: " + url; }
public void SpeedTest(GingerAction gingerAction, string message, int sleep) { // Do Work gingerAction.Output.Add("key2", "hello 2"); gingerAction.Output.Add("message", message); gingerAction.Output.Add("message len", message.Length.ToString()); /// !!!!!!!!!!!!!! Thread.Sleep(sleep); gingerAction.ExInfo = "ex1"; gingerAction.AddError("aaa", "aaaaa errr"); }
public void ExecuteCommand(object commandVal) { try { CommandElements commandVals = (CommandElements)commandVal; Process process = new Process(); if (commandVals.WorkingFolder != null) { process.StartInfo.WorkingDirectory = commandVals.WorkingFolder; } process.StartInfo.FileName = commandVals.ExecuterFilePath; process.StartInfo.Arguments = commandVals.Arguments; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardError = true; mCommandOutputBuffer = string.Empty; mCommandOutputErrorBuffer = string.Empty; process.OutputDataReceived += (proc, outLine) => { AddCommandOutput(outLine.Data); }; process.ErrorDataReceived += (proc, outLine) => { AddCommandOutputError(outLine.Data); }; process.Exited += Process_Exited; Console.WriteLine("--Staring process"); process.Start(); Stopwatch stopwatch = Stopwatch.StartNew(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); int maxWaitingTime = 1000 * 60 * 60;//1 hour process.WaitForExit(maxWaitingTime); Console.WriteLine("--Process done"); stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds >= maxWaitingTime) { GingerAction.AddError("Command processing timeout has reached!"); } } catch (Exception ex) { GingerAction.AddError("Failed to execute the command, Error is: '{0}'" + ex.Message); Console.Write(ex.Message); } finally { GingerAction.AddExInfo("--Exiting execute command"); } }
public void Execute(GingerAction GA) { GingerGrid gingerGrid = WorkSpace.Instance.LocalGingerGrid; string PID = GA.InputParams["PluginID"].GetValueAsString(); PluginPackage p = (from x in mPluginPackages where x.PluginID == PID select x).SingleOrDefault(); if (p == null) { GA.AddError("Execute", "Plugin id not found: " + PID); return; } //TODO: use nameof after ActPlugin move to common string serviceID = GA.InputParams["PluginActionID"].GetValueAsString(); GingerNodeInfo GNI = (from x in gingerGrid.NodeList where x.Name == p.PluginID select x).FirstOrDefault(); //run script only if service is not up if (GNI == null) { string script = CommandProcessor.CreateLoadPluginScript(p.Folder); // hard coded!!!!!!!!!! script += CommandProcessor.CreateStartServiceScript("ExcelService", p.PluginID, SocketHelper.GetLocalHostIP(), gingerGrid.Port); Task t = new Task(() => { GingerConsoleHelper.Execute(script); }); t.Start(); } int counter = 0; while (GNI == null && counter < 30) { Thread.Sleep(1000); GNI = (from x in gingerGrid.NodeList where x.Name == p.PluginID select x).FirstOrDefault(); counter++; } GingerNodeProxy GNA = new GingerNodeProxy(GNI); GNA.Reserve(); GNA.GingerGrid = gingerGrid; GNA.RunAction(GA); }
public void UIElementAction(GingerAction gingerAction, eElementType elementType, eLocateBy locateBy, string locateValue, eElementAction elementAction, string value = null) { Console.WriteLine("HandleUIElementAction"); //First find the element IWebElement e = LocateElement(gingerAction, elementType, locateBy, locateValue); if (e == null) { Console.WriteLine("Element not found - " + elementType + " - " + locateBy + " " + locateValue); gingerAction.AddError("HandleUIElementAction", "Cannot find element: " + elementType + locateBy + " " + locateValue); return; } PerformUIElementAction(gingerAction, e, elementAction, value); }
private void ParseCommandOutput() { try { //Error if (!string.IsNullOrEmpty(mCommandOutputErrorBuffer.Trim().Trim('\n'))) { GingerAction.AddError(string.Format("Console Errors: \n{0}", mCommandOutputErrorBuffer)); } //Output values Regex rg = new Regex(@"Microsoft.*\n.*All rights reserved."); string stringToProcess = rg.Replace(mCommandOutputBuffer, ""); string[] values = stringToProcess.Split('\n'); foreach (string dataRow in values) { if (dataRow.Length > 0) // Ignore empty lines { string param; string value; int signIndex = -1; if (string.IsNullOrEmpty(mDelimeter)) { signIndex = dataRow.IndexOf("="); } else { signIndex = dataRow.IndexOf(mDelimeter); } if (signIndex > 0) { param = dataRow.Substring(0, signIndex); //the rest is the value value = dataRow.Substring(param.Length + 1); GingerAction.AddOutput(param, value, "Console Output"); } } } } catch (Exception ex) { GingerAction.AddError(string.Format("Failed to parse all command console outputs, Error:'{0}'", ex.Message)); } }
public void Execute() { Console.Write("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Execution Started %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); try { switch (ExecutionMode) { case eExecutionMode.ScriptPath: CommandElements command = new CommandElements(); command = PrepareFreeCommand(); ExecuteCommand(command); ParseCommandOutput(); break; } } catch (Exception ex) { GingerAction.AddError("Error while executing script : " + ex.ToString()); } }
public void ReadExcelCell(ref GingerAction GA, string FileName, string sheetName, string row, string column) { try { if (column.Contains("#") && row.Contains("#")) //row="#3", column="#B" { string col = "a"; string nRow = "3"; string txt1 = GetCellValue(FileName, "Sheet1", col + nRow); GA.Output.Add("Value", txt1); GA.ExInfo = "Read FileName: " + FileName + " row= " + row + " col= " + column; } else //row="First='Moshe'", column="ID" { // List<string> colList = GetCoulmnsName(FileName, sheetName, column); //ReadExcelRowWithCondition(GA, FileName, sheetName, row, colList); } } catch (Exception ex) { GA.AddError("ReadExcelCell", ex.StackTrace); } }
private void PerformUIElementAction(GingerAction gingerAction, IWebElement e, eElementAction elementAction, string value) { switch (elementAction) { case eElementAction.Click: e.Click(); break; case eElementAction.SetValue: //TODO: override in sub driver if needed e.Clear(); e.SendKeys(value); break; case eElementAction.GetValue: gingerAction.Output.Add("Text", e.Text); break; default: gingerAction.AddError("PerformUIElementAction", "Unknown element action - " + elementAction); break; } }
public void RunAction(GingerAction GA) { // Here we decompose the GA and create Payload to transfer it to the agent NewPayLoad PL = new NewPayLoad("RunAction"); PL.AddValue(GA.ID); List <NewPayLoad> Params = new List <NewPayLoad>(); foreach (ActionParam AP in GA.InputParams.Values) { // TODO: use const NewPayLoad p = new NewPayLoad("P"); // To save network trafic we send just one letter p.AddValue(AP.Name); p.AddValue(AP.Value.ToString()); p.ClosePackage(); Params.Add(p); } PL.AddListPayLoad(Params); PL.ClosePackage(); // TODO: use function which goes to local grid or remote grid NewPayLoad RC = SendRequestPayLoad(PL); // After we send it we parse the driver response if (RC.Name == "ActionResult") { // We read the ExInfo, Err and output params GA.ExInfo = RC.GetValueString(); string Error = RC.GetValueString(); if (!string.IsNullOrEmpty(Error)) { GA.AddError("Driver", RC.GetValueString()); // We need to get Error even if Payload is OK - since it might be in } List <NewPayLoad> OutpuValues = RC.GetListPayLoad(); foreach (NewPayLoad OPL in OutpuValues) { //TODO: change to use PL AddValueByObjectType // it is param name, type and value string PName = OPL.GetValueString(); string mOutputValueType = OPL.GetValueEnum(); switch (mOutputValueType) { case nameof(OutputValueType.String): string v = OPL.GetValueString(); GA.Output.Values.Add(new ActionOutputValue() { Param = PName, ValueString = v }); break; case nameof(OutputValueType.ByteArray): byte[] b = OPL.GetBytes(); GA.Output.Values.Add(new ActionOutputValue() { Param = PName, ValueByteArray = b }); break; default: throw new Exception("Unknown param type: " + mOutputValueType); } } } else { // The RC is not OK when we faced some unexpected exception //TODO: string Err = RC.GetValueString(); GA.AddError("RunAction", Err); } }