public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter expectedFilePathParameter = testAction.GetParameter("ExpectedFile", false, new[] { ActionMode.Input }); IParameter actualFilePathParameter = testAction.GetParameter("ActualFile", false, new[] { ActionMode.Input }); string expectedFilePath = Environment.ExpandEnvironmentVariables(expectedFilePathParameter.GetAsInputValue().Value); string actualFilePath = Environment.ExpandEnvironmentVariables(actualFilePathParameter.GetAsInputValue().Value); string result = String.Empty; try { result = FileComparer.Compare(expectedFilePath, actualFilePath); } catch (FileNotFoundException exc) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, exc.Message); return; } if (result == String.Empty) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "The contents of the files are identical."); } else { testAction.SetResult(SpecialExecutionTaskResultState.Failed, result); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPfile = testAction.GetParameter("File", false, new[] { ActionMode.Input }); IParameter IPinverse = testAction.GetParameter("Exists", false, new[] { ActionMode.Input }); string file = IPfile.GetAsInputValue().Value; string inverseString = IPinverse.GetAsInputValue().Value; bool fileExists; // if this is true, the file should exists. Default value should be true bool result; bool success = Boolean.TryParse(inverseString, out fileExists); if (!success) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "Inverse has to be an boolean"); return; } if (FileOrDirectoryExists(file)) { result = fileExists; //if the file is found, the value of fileExists will be returned. } else { result = !fileExists; //if the file is not found, the inverse of fileExists will be returned. } if (result) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Correct"); return; } testAction.SetResult(SpecialExecutionTaskResultState.Failed, "Incorrect"); }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPconnString = testAction.GetParameter("ConnectionString", false, new[] { ActionMode.Input }); IParameter IPquery = testAction.GetParameter("Query", false, new[] { ActionMode.Input }); IParameter IPresult = testAction.GetParameter("Result", true, new[] { ActionMode.Verify, ActionMode.Buffer }); string connString = IPconnString.GetAsInputValue().Value; string query = IPquery.GetAsInputValue().Value; if (File.Exists(query)) { query = File.ReadAllText(query); } Datalink dl = new Datalink(connString); if (!dl.IsValidSqlConnectionString()) { throw new InvalidOperationException("Connectionstring is not valid or the database cannot be reached"); } string result = dl.Execute(query); if (IPresult != null) { IInputValue expectedResult = IPresult.Value as IInputValue; if (IPresult.ActionMode == ActionMode.Buffer) { Buffers.Instance.SetBuffer(expectedResult.Value, result); testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.", expectedResult.Value, result)); return; } if (expectedResult.Value == result) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Actual rows match expected number of rows."); } else { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Expected result: {0}. Actual result {1}. Incorrect", expectedResult.Value, result.ToString())); } } else { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Query executed"); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { //The 2nd parameter of GetParameterAsInputValue Method defines if the argument is optional or not //and if we don't provide the second parameter by default it is false(Means argument is mandetory) IInputValue browserName = testAction.GetParameterAsInputValue("BrowserName", false); bool result = EraseTemporaryFiles(browserName.Value); if (result) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Cache for {0} is cleared.", browserName.Value)); } else { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Unable to clear cache for {0}.", browserName.Value)); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPconnString = testAction.GetParameter("ConnectionString", false, new[] { ActionMode.Input }); IParameter IPquery = testAction.GetParameter("Query", false, new[] { ActionMode.Input }); IParameter IPresult = testAction.GetParameter("Result", true, new[] { ActionMode.Verify, ActionMode.Buffer }); string connString = IPconnString.GetAsInputValue().Value; string query = IPquery.GetAsInputValue().Value; if (File.Exists(query)) { query = File.ReadAllText(query); } Datalink dl = new Datalink(connString); if (!dl.IsValidSqlConnectionString()) { throw new InvalidOperationException("Connectionstring is not valid or the database cannot be reached"); } string result = dl.Execute(query); if (IPresult != null ) { IInputValue expectedResult = IPresult.Value as IInputValue; if (IPresult.ActionMode == ActionMode.Buffer) { Buffers.Instance.SetBuffer(expectedResult.Value, result); testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.",expectedResult.Value, result)); return; } if (expectedResult.Value == result) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Actual rows match expected number of rows."); } else { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Expected result: {0}. Actual result {1}. Incorrect", expectedResult.Value, result.ToString())); } } else { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Query executed"); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPprocess = testAction.GetParameter("Process", false, new[] { ActionMode.Input }); IParameter IPwaittimesecs = testAction.GetParameter("WaitTimeSecs", false, new[] { ActionMode.Input }); string process = IPprocess.GetAsInputValue().Value; string waittimesecsString = IPwaittimesecs.GetAsInputValue().Value; short waittimesecs = 0; bool success = Int16.TryParse(waittimesecsString, out waittimesecs); if (!success) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "WaitTimeSecs has to be an integer"); return; } if (waittimesecs == 0) { waittimesecs = DEFAULTWAITTIME; } Process[] pname = Process.GetProcessesByName(process); if (pname.Length == 0) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Proces {0} already ended or not started", process)); return; } short counter = 0; while (counter < waittimesecs) { counter++; Thread.Sleep(1000); pname = Process.GetProcessesByName(process); if (pname.Length == 0) { break; } } testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Proces {0} has ended after {1} seconds", process, counter)); }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPprocess = testAction.GetParameter("Process", false, new[] { ActionMode.Input }); IParameter IPwaittimesecs = testAction.GetParameter("WaitTimeSecs", false, new[] { ActionMode.Input }); string process = IPprocess.GetAsInputValue().Value; string waittimesecsString = IPwaittimesecs.GetAsInputValue().Value; short waittimesecs = 0; bool success = Int16.TryParse(waittimesecsString, out waittimesecs); if (!success) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "WaitTimeSecs has to be an integer"); return; } if (waittimesecs == 0) waittimesecs = DEFAULTWAITTIME; Process[] pname = Process.GetProcessesByName(process); if (pname.Length == 0) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Proces {0} already ended or not started", process)); return; } short counter = 0; while (counter < waittimesecs) { counter++; Thread.Sleep(1000); pname = Process.GetProcessesByName(process); if (pname.Length == 0) break; } testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Proces {0} has ended after {1} seconds", process, counter)); }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { if (!Collections.Instance.CollectionExists(BufferCollectionPath)) { throw new InvalidOperationException("No Buffer-Collection is available in the settings!"); } foreach ( KeyValuePair <string, string> buffer in Collections.Instance.GetCollectionEntries(BufferCollectionPath)) { if (!string.IsNullOrEmpty(buffer.Value)) { if ((!buffer.Key.StartsWith("LOCAL_")) && (!buffer.Key.StartsWith("ENV")) && (!buffer.Key.StartsWith("TOOLS_"))) { Buffers.Instance.SetBuffer(buffer.Key, string.Empty, false); } } } testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Successfully cleared all Buffers!"); }
private static void StartProgramWithoutWaitingForExit( ISpecialExecutionTaskTestAction testAction, ProcessStartInfo processStartInfo, string expandedPath, string processArguments, IParameter pathParameter) { try { Process.Start(processStartInfo); testAction.SetResult( SpecialExecutionTaskResultState.Ok, "Started: " + expandedPath + " with arguments: " + processArguments); } catch (Win32Exception e) { testAction.SetResultForParameter( pathParameter, SpecialExecutionTaskResultState.Failed, CreateMessageForStartError(expandedPath, processArguments, e), e.StackTrace, ""); } }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String bankIdent = testAction.GetParameterAsInputValue("bankIdent", false).Value; if (string.IsNullOrEmpty(bankIdent)) { throw new ArgumentException(string.Format("Es muss eine Bank identifikation angegeben sein.")); } String accountNumber = testAction.GetParameterAsInputValue("accountNumber", false).Value; if (string.IsNullOrEmpty(accountNumber)) { throw new ArgumentException(string.Format("Es muss eine Kontonummer angegeben sein.")); } String buffer = testAction.GetParameterAsInputValue("buffer", false).Value; if (string.IsNullOrEmpty(buffer)) { throw new ArgumentException(string.Format("Es muss ein Puffer angegeben werden in welche die IBAN gespeichert werden soll.")); } // onyl support DE so far ECountry countryCode = ECountry.DE; // DE46 | 5054 0028 | 0420 0861 00 _manager = ContainerBootstrapper.Resolve <IIbanManager>(countryCode.ToString()); iban = _manager.GenerateIban(countryCode, bankIdent, accountNumber); Buffers.Instance.SetBuffer(buffer, iban.IBAN.IBAN, false); testAction.SetResult(SpecialExecutionTaskResultState.Ok, "IBAN generated and saved to buffer."); throw new NotImplementedException(); }
private void StartProgramWithWaitForExit( ISpecialExecutionTaskTestAction testAction, IParameter exitParameter, ProcessStartInfo processStartInfo, IParameter pathParameter, string expandedPath, string processArguments) { if (exitParameter.GetAsInputValue().Verify("True", exitParameter.Operator) is FailedActionResult) { throw new InvalidOperationException( "Please use 'True' as value for " + exitParameter.Name + ". If you don't want to wait for exit of the application, please delete the node. The items below won't work without waiting for exit."); } IParameter stdoutParameter = exitParameter.GetChildParameter(StandardOutputFile, true); IParameter exitCodeParameter = exitParameter.GetChildParameter( ProcessExitCode, true, new[] { ActionMode.Buffer, ActionMode.Verify }); IInputValue timeoutForExitValue = exitParameter.GetChildParameterAsInputValue(TimeoutForExit, true); int timeoutForExit; if (timeoutForExitValue != null) { if (!int.TryParse(timeoutForExitValue.Value, out timeoutForExit)) { throw new InvalidOperationException( "Please use a valid integer value for the Parameter 'TimeoutForExit'"); } timeoutForExit = timeoutForExit * 1000; } else { timeoutForExit = int.MaxValue; } string output; try { int exitCode; bool wasTimeout; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); output = StartProcessWithWaitForExit( processStartInfo, stdoutParameter != null, timeoutForExit, out exitCode, out wasTimeout); stopwatch.Stop(); testAction.SetResult( SpecialExecutionTaskResultState.Ok, string.Format("Started '{0}' with arguments '{1}'", expandedPath, processArguments)); if (wasTimeout) { testAction.SetResultForParameter( pathParameter, SpecialExecutionTaskResultState.Failed, string.Format( "Timeout occured, process didn't stop within the timeout of {0} seconds!", timeoutForExit / 1000)); } else { testAction.SetResultForParameter( pathParameter, SpecialExecutionTaskResultState.Ok, string.Format( "Process stopped after '{0}' minutes.", Math.Round(stopwatch.Elapsed.TotalMinutes))); if (exitCodeParameter != null) { HandleActualValue(testAction, exitCodeParameter, exitCode); } } } catch (Win32Exception e) { testAction.SetResultForParameter( pathParameter, SpecialExecutionTaskResultState.Failed, CreateMessageForStartError(expandedPath, processArguments, e), e.StackTrace, ""); return; } if (stdoutParameter != null && output != null) { String filePath = Environment.ExpandEnvironmentVariables(stdoutParameter.GetAsInputValue().Value); File.WriteAllText(filePath, output); testAction.SetResultForParameter( stdoutParameter, new PassedActionResult( "The Standard-Output was saved inside the given file. See 'Details'-column for the path.", filePath, String.Empty)); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { const string BEGINWHERE = " where 1=1 "; const string BEGINSELECT = " select "; const string BEGINORDER = " order by "; const string ORDERDIRECTION = " desc "; var connStringParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault( xParam => xParam.Name == "ConnectionString"); string connString = connStringParam.UnparsedValue; var tableNameParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "TableName"); string tableName = tableNameParam.UnparsedValue; var orderAttribParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "OrderAttribute"); string orderAttrib = orderAttribParam.UnparsedValue; string queryWhere = BEGINWHERE; string queryBegin = BEGINSELECT; string query = string.Empty; string queryOrder = string.Format("{0} {1} {2}", BEGINORDER, orderAttrib, ORDERDIRECTION); int count = 0; var constraints = testAction.Parameters.FindAll(p => p.ActionMode == ActionMode.Constraint); if (constraints.Count > 0) { foreach (var parameter in constraints) { IInputValue value = parameter.Value as IInputValue; queryWhere += string.Format(" and {0} = '{1}' ", parameter.Name, value.Value); } } var buffersVerifies = testAction.Parameters.FindAll(p => p.ActionMode == ActionMode.Verify || p.ActionMode == ActionMode.Buffer); if (buffersVerifies.Count == 0 ) { // No use in continuing if there is nothing to verify or buffer return; } queryBegin += String.Join(",", buffersVerifies.Select(p => p.Name).ToArray()); // Generate db query query = string.Format("{0} FROM {1} {2} {3}", queryBegin, tableName, queryWhere, queryOrder); // Connect to the database Datalink dl = new Datalink(); dl.ConnectionString = connString; if (!dl.IsValidSqlConnectionString()) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Cannot connect to the SQL database with the following connection string: {0}", connString)); return; } DataRow dr = dl.GetRowFromDb(query); // If there is not a result from the database, set the testresult to failed if (dr == null) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "No records found in with selected searchcriteria" ); return; } foreach (IParameter parameter in buffersVerifies.Where(p => p.ActionMode == ActionMode.Verify)) { IInputValue value = parameter.Value as IInputValue; if (value.Value == dr[parameter.Name].ToString()) { testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("{0}: Expected value {1} matches actual value {2}.", parameter.Name, value.Value, dr[parameter.Name].ToString())); } else { count++; testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Failed, string.Format("Error {0}: Expected value {1} does not match actual value {2}.", parameter.Name, value.Value, dr[parameter.Name].ToString())); } } foreach (IParameter parameter in buffersVerifies.Where(p => p.ActionMode == ActionMode.Buffer)) { IInputValue buffer = parameter.Value as IInputValue; Buffers.Instance.SetBuffer(buffer.Value, dr[parameter.Name].ToString()); testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.", buffer.Value, dr[parameter.Name].ToString())); } if (count == 0) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "All values match."); } else { int numberOfVerifies = buffersVerifies.Count(p => p.ActionMode == ActionMode.Verify); testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("{0} out of {1} values match.", numberOfVerifies - count, numberOfVerifies)); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { const string BEGINWHERE = " where 1=1 "; const string BEGINSELECT = " select "; const string BEGINORDER = " order by "; const string ORDERDIRECTION = " desc "; var connStringParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "ConnectionString"); string connString = connStringParam.UnparsedValue; var tableNameParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "TableName"); string tableName = tableNameParam.UnparsedValue; var orderAttribParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "OrderAttribute"); string orderAttrib = orderAttribParam.UnparsedValue; string queryWhere = BEGINWHERE; string queryBegin = BEGINSELECT; string query = string.Empty; string queryOrder = string.Format("{0} {1} {2}", BEGINORDER, orderAttrib, ORDERDIRECTION); int count = 0; var constraints = testAction.Parameters.FindAll(p => p.ActionMode == ActionMode.Constraint); if (constraints.Count > 0) { foreach (var parameter in constraints) { IInputValue value = parameter.Value as IInputValue; queryWhere += string.Format(" and {0} = '{1}' ", parameter.Name, value.Value); } } var buffersVerifies = testAction.Parameters.FindAll(p => p.ActionMode == ActionMode.Verify || p.ActionMode == ActionMode.Buffer); if (buffersVerifies.Count == 0) { // No use in continuing if there is nothing to verify or buffer return; } queryBegin += String.Join(",", buffersVerifies.Select(p => p.Name).ToArray()); // Generate db query query = string.Format("{0} FROM {1} {2} {3}", queryBegin, tableName, queryWhere, queryOrder); // Connect to the database Datalink dl = new Datalink(); dl.ConnectionString = connString; if (!dl.IsValidSqlConnectionString()) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Cannot connect to the SQL database with the following connection string: {0}", connString)); return; } DataRow dr = dl.GetRowFromDb(query); // If there is not a result from the database, set the testresult to failed if (dr == null) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "No records found in with selected searchcriteria"); return; } foreach (IParameter parameter in buffersVerifies.Where(p => p.ActionMode == ActionMode.Verify)) { IInputValue value = parameter.Value as IInputValue; if (value.Value == dr[parameter.Name].ToString()) { testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("{0}: Expected value {1} matches actual value {2}.", parameter.Name, value.Value, dr[parameter.Name].ToString())); } else { count++; testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Failed, string.Format("Error {0}: Expected value {1} does not match actual value {2}.", parameter.Name, value.Value, dr[parameter.Name].ToString())); } } foreach (IParameter parameter in buffersVerifies.Where(p => p.ActionMode == ActionMode.Buffer)) { IInputValue buffer = parameter.Value as IInputValue; Buffers.Instance.SetBuffer(buffer.Value, dr[parameter.Name].ToString()); testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.", buffer.Value, dr[parameter.Name].ToString())); } if (count == 0) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "All values match."); } else { int numberOfVerifies = buffersVerifies.Count(p => p.ActionMode == ActionMode.Verify); testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("{0} out of {1} values match.", numberOfVerifies - count, numberOfVerifies)); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { String paraCommand = testAction.GetParameterAsInputValue("Command", false).Value; if (string.IsNullOrEmpty(paraCommand)) { throw new ArgumentException(string.Format("Es muss ein Command angegeben sein.")); } String paraTarget = testAction.GetParameterAsInputValue("Target", false).Value; // Wenn Target null, dann leer uebergeben. if (string.IsNullOrEmpty(paraTarget)) { paraTarget = ""; } String paraValue = testAction.GetParameterAsInputValue("Value", false).Value; // Wenn Value null, dann leer uebergeben. if (string.IsNullOrEmpty(paraValue)) { paraValue = ""; } // Rest Service konfigurierbar machen? var client = new RestClient("http://127.0.0.1:84"); var request = new RestRequest("tn5250/execute", Method.POST); request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", "application/json"); request.AddHeader("Accept", "application/json"); request.AddBody(new { command = paraCommand, target = paraTarget, value = paraValue }); IRestResponse response = client.Execute(request); var content = response.Content; // Deserialisieren RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer(); var JSONObj = deserial.Deserialize <Dictionary <string, string> >(response); string rowCode = JSONObj["code"]; string rowMsg = ""; if (JSONObj.ContainsKey("message")) { rowMsg = JSONObj["message"]; } // storedKey und storedValue beruecksichtigen if (JSONObj.ContainsKey("storedValue")) { string storedValue = JSONObj["storedValue"]; string storedKey = JSONObj["storedKey"]; Buffers.Instance.SetBuffer(storedKey, storedValue, false); } if (rowCode == "0") { // return new PassedActionResult("Got response: " + content); testAction.SetResult(SpecialExecutionTaskResultState.Ok, "The execution of the command was successfully processed."); } else { // Im Falle eines Fehlers und damit eines Abbruchs muessen wir die Telnet Session aufraeumen? // var requestClean = new RestRequest("selenese/close", Method.POST); // requestClean.RequestFormat = DataFormat.Json; // requestClean.AddHeader("Content-Type", "application/json"); // requestClean.AddHeader("Accept", "application/json"); // requestClean.AddBody(new { // command = "close", // target = "this", // value = "null" // }); // IRestResponse responseClean = client.Execute(requestClean); // return new VerifyFailedActionResult("expected", "real"); testAction.SetResult( SpecialExecutionTaskResultState.Failed, rowMsg); } }