private CommandElements PrepareFreeCommand() { CommandElements command = new CommandElements(); if (JavaProjectType == eJavaProjectType.Regular) { if (string.IsNullOrEmpty(JavaWorkingFolder) == false) { command.WorkingFolder = JavaWorkingFolder; } command.ExecuterFilePath = string.Format("\"{0}\"", JavaExeFullPath); } else//maven { command.WorkingFolder = MavenProjectFolderPath; command.ExecuterFilePath = string.Format("\"{0}\"", MavenCmdFullPath); } if (OverwriteOriginalTestngXml == false && TestngXmlParametersToOverwrite != null && TestngXmlParametersToOverwrite.Count > 0) { //need to update the path of the xml in the command arguments to point the customized one string xmlName = Path.GetFileName(mOriginalTestngXmlPath); int fileNameIndx = FreeCommandArguments.IndexOf(xmlName); if (fileNameIndx > 0) { int rightIndx = fileNameIndx + xmlName.Length; if (rightIndx < FreeCommandArguments.Length && FreeCommandArguments[rightIndx] == '\"') { rightIndx++; } int leftIndx = fileNameIndx; while (leftIndx > 0 && FreeCommandArguments[leftIndx - 1] != '=') { leftIndx--; } if (leftIndx <= 0)//'=' not found so probably used the TestNG command like "org.testng.TestNG src/test/resources/fit/testng.xml" { leftIndx = fileNameIndx; while (leftIndx > 0 && FreeCommandArguments.Substring(leftIndx - 8, 8).ToUpper() != ".TESTNG ") { leftIndx--; } } if (rightIndx > leftIndx && rightIndx > 0 && leftIndx > 0) { string fullXmlPathArgument = FreeCommandArguments.Substring(leftIndx, rightIndx - leftIndx); FreeCommandArguments = FreeCommandArguments.Replace(fullXmlPathArgument, string.Format("\"{0}\"", TestngXmlPath)); } else { General.AddErrorToConsoleAndAction(GingerAction, string.Format("Failed to replace the original TestNG XML path '{0}' with the customized one '{1}' in the command arguments", mOriginalTestngXmlPath, TestngXmlPath)); } } else { General.AddErrorToConsoleAndAction(GingerAction, string.Format("Failed to replace the original TestNG XML path '{0}' with the customized one '{1}' in the command arguments", mOriginalTestngXmlPath, TestngXmlPath)); } } command.Arguments = string.Format(" {0}", FreeCommandArguments); return(command); }
public bool ValidateAndPrepareConfigs() { //validate general inputes if (Directory.Exists(TempWorkingFolder) == false) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to create temp working folder at: '{0}'", TempWorkingFolder)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("Temp working folder path: '{0}'", TempWorkingFolder)); } if (ExecuterType == eExecuterType.Java) { if (Path.GetFileName(JavaExeFullPath).ToLower().Contains("java") == false || File.Exists(JavaExeFullPath) == false) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find Java Executor file at: '{0}'", JavaExeFullPath)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("Path of Java Executor file: '{0}'", JavaExeFullPath)); } } else//Maven Executer { if (Path.GetFileName(MavenCmdFullPath).ToLower().Contains("mvn") == false || File.Exists(MavenCmdFullPath) == false) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find MVN Executor file at: '{0}'", MavenCmdFullPath)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("Path of MVN Executor file: '{0}'", MavenCmdFullPath)); } } switch (ExecutionMode) { case eExecutionMode.XML: case eExecutionMode.DynamicXML: if (JavaProjectType == eJavaProjectType.Regular) { if (Directory.Exists(JavaProjectResourcesPath.Trim().TrimEnd('*')) == false) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the TestNG resources folder at: '{0}'", JavaProjectResourcesPath)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("TestNG resources path: '{0}'", JavaProjectResourcesPath)); } if (Directory.Exists(JavaProjectBinPath) == false) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the TestNG testing project Bin folder at: '{0}'", JavaProjectBinPath)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("TestNG testing project Bin folder path: '{0}'", JavaProjectBinPath)); } } else //Maven Project { if (Directory.Exists(MavenProjectFolderPath) == false) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the Maven Java project folder at: '{0}'", MavenProjectFolderPath)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("Maven Java project path: '{0}'", MavenProjectFolderPath)); } } if (ExecutionMode == eExecutionMode.DynamicXML) { if (XmlTestsToExecute != null && XmlTestsToExecute.Count > 0) { string testsListStr = "Tests to execute: "; foreach (TestNGTest test in XmlTestsToExecute) { test.Name = test.Name.Trim(); if (!TestNgSuiteXMLObj.IsTestExistInXML(test.Name)) { General.AddErrorToConsoleAndAction(GingerAction, string.Format("The Test '{0}' do not exist in the TestNG Suite XML", test.Name)); return(false); } else { testsListStr += string.Format("'{0}', ", test.Name); } } testsListStr.TrimEnd(','); General.AddInfoToConsoleAndAction(GingerAction, testsListStr); } if (TestGroupsToInclude != null && TestGroupsToInclude.Count > 0) { string groupsToIncludeListStr = "Tests Groups to include: "; foreach (TestNGTestGroup group in TestGroupsToInclude) { groupsToIncludeListStr += string.Format("'{0}', ", group.Name); } groupsToIncludeListStr.TrimEnd(','); General.AddInfoToConsoleAndAction(GingerAction, groupsToIncludeListStr); } if (TestGroupsToExclude != null && TestGroupsToExclude.Count > 0) { string groupsToExcludeListStr = "Tests Groups to exclude: "; foreach (TestNGTestGroup group in TestGroupsToExclude) { groupsToExcludeListStr += string.Format("'{0}', ", group.Name); } groupsToExcludeListStr.TrimEnd(','); General.AddInfoToConsoleAndAction(GingerAction, groupsToExcludeListStr); } } break; case eExecutionMode.FreeCommand: if (JavaProjectType == eJavaProjectType.Regular) { if (!string.IsNullOrEmpty(JavaWorkingFolder)) { if (Directory.Exists(JavaWorkingFolder) == false) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the Java Working folder at: '{0}'", JavaWorkingFolder)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("Java Working folder path: '{0}'", JavaWorkingFolder)); } } } if (string.IsNullOrEmpty(FreeCommandArguments.Trim())) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Provided Free Command Arguments are not valid: '{0}'", FreeCommandArguments)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("Free Command Arguments: '{0}'", FreeCommandArguments)); } if (CommandParametersToOverride != null && CommandParametersToOverride.Count > 0) { string paramsListStr = "Command Parameters to override: "; foreach (CommandParameter param in CommandParametersToOverride) { param.Name = param.Name.Trim(); if (!FreeCommandArguments.Contains(param.Name)) { General.AddErrorToConsoleAndAction(GingerAction, string.Format("The Command Parameter '{0}' do not exist in the Command Arguments", param.Name)); return(false); } else { paramsListStr += string.Format("'{0}'='{1}', ", param.Name, param.Value); } } paramsListStr.TrimEnd(','); General.AddInfoToConsoleAndAction(GingerAction, paramsListStr); } break; } if (ExecutionMode != eExecutionMode.FreeCommand || (ExecutionMode == eExecutionMode.FreeCommand && string.IsNullOrEmpty(TestngXmlPath) == false)) { TestNgSuiteXMLObj = new TestNGSuiteXML(TestngXmlPath); if (TestNgSuiteXMLObj.LoadError != null) { General.AddErrorToConsoleAndAction(GingerAction, TestNgSuiteXMLObj.LoadError); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("TestNG XML path: '{0}'", TestNgSuiteXMLObj.XmlFilePath)); } } if (TestNgSuiteXMLObj != null && TestngXmlParametersToOverwrite != null && TestngXmlParametersToOverwrite.Count > 0) { string paramsListStr = "Parameters to override: "; foreach (TestNGTestParameter param in TestngXmlParametersToOverwrite) { if (param == null || string.IsNullOrEmpty(param.Name)) { continue; } else { param.Name = param.Name.Trim(); } if (!string.IsNullOrEmpty(param.ParentNodeName)) { param.ParentNodeName = param.ParentNodeName.Trim(); } if (!TestNgSuiteXMLObj.IsParameterExistInXML(param.Name, param.ParentNodeName)) { if (string.IsNullOrEmpty(param.ParentNodeName)) { General.AddErrorToConsoleAndAction(GingerAction, string.Format("The Parameter '{0}' do not exist in the TestNG Suite XML", param.Name)); } else { General.AddErrorToConsoleAndAction(GingerAction, string.Format("The Parameter '{0}\\{1}' do not exist in the TestNG Suite XML", param.ParentNodeName, param.Name)); } return(false); } else { if (string.IsNullOrEmpty(param.ParentNodeName)) { paramsListStr += string.Format("'{0}'='{1}', ", param.Name, param.Value); } else { paramsListStr += string.Format("'{0}\\{1}'='{2}', ", param.ParentNodeName, param.Name, param.Value); } } } paramsListStr.TrimEnd(','); General.AddInfoToConsoleAndAction(GingerAction, paramsListStr); } if (ParseTestngResultsXml == true) { if (Directory.Exists(TestngResultsXmlFolderPath) == false) { General.AddErrorToConsoleAndAction(GingerAction, String.Format("Failed to find the TestNG output report root folder at: '{0}'", TestngResultsXmlFolderPath)); return(false); } else { General.AddInfoToConsoleAndAction(GingerAction, String.Format("TestNG output report root folder path: '{0}'", TestngResultsXmlFolderPath)); } } return(true); }