/// <summary> /// constructor /// </summary> /// <param name="runner">parent runner</param> /// <param name="timeout">the global timout</param> public ApiTestRunner(IAssetRunner runner, TimeSpan timeout) { _stopwatch = Stopwatch.StartNew(); _timeout = timeout; _stCanRun = TrySetSTRunner(); _runner = runner; }
/// <summary> /// used by the run fuction to run the tests /// </summary> /// <param name="runner"></param> /// <param name="resultsFile"></param> private void RunTests(IAssetRunner runner, string resultsFile) { try { if (_ciRun) { _xmlBuilder = new JunitXmlBuilder(); _xmlBuilder.XmlName = resultsFile; } TestSuiteRunResults results = runner.Run(); if (results == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } _xmlBuilder.CreateXmlFromRunResults(results); //if there is an error if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; } //this is the total run summary ConsoleWriter.ActiveTestRun = null; string runStatus = (Launcher.ExitCode == ExitCodeEnum.Passed || Launcher.ExitCode == ExitCodeEnum.Unstable) ? "Job succeeded" : "Job failed"; int numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed); int numSuccess = results.TestRuns.Count(t => t.TestState == TestState.Passed); int numErrors = results.TestRuns.Count(t => t.TestState == TestState.Error); ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors)); if (!runner.RunWasCancelled) { results.TestRuns.ForEach(tr => ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath)); ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0) { ConsoleWriter.WriteLine("Job Errors summary:"); ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line)); } } //ConsoleWriter.WriteLine("Returning " + runStatus + "."); } finally { try { runner.Dispose(); } catch (Exception ex) { ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message)); }; } }
/// <summary> /// constructor /// </summary> /// <param name="runner">parent runner</param> /// <param name="timeout">the global timout</param> public ApiTestRunner(IAssetRunner runner, TimeSpan timeout) { _stopwatch = Stopwatch.StartNew(); _timeout = timeout; _stCanRun = TrySetSTRunner(); _runner = runner; }
/// <summary> /// constructor /// </summary> /// <param name="runNotifier"></param> /// <param name="useUftLicense"></param> /// <param name="timeLeftUntilTimeout"></param> public GuiTestRunner(IAssetRunner runNotifier, bool useUftLicense, TimeSpan timeLeftUntilTimeout) { _timeLeftUntilTimeout = timeLeftUntilTimeout; _stopwatch = Stopwatch.StartNew(); _runNotifier = runNotifier; _useUFTLicense = useUftLicense; }
/// <summary> /// constructor /// </summary> /// <param name="runNotifier"></param> /// <param name="useUftLicense"></param> /// <param name="timeLeftUntilTimeout"></param> public GuiTestRunner(IAssetRunner runNotifier, bool useUftLicense, TimeSpan timeLeftUntilTimeout, McConnectionInfo mcConnectionInfo, string mobileInfo) { _timeLeftUntilTimeout = timeLeftUntilTimeout; _stopwatch = Stopwatch.StartNew(); _runNotifier = runNotifier; _useUFTLicense = useUftLicense; _mcConnection = mcConnectionInfo; _mobileInfo = mobileInfo; }
public ParallelTestRunner(IAssetRunner runner, TimeSpan timeout, McConnectionInfo mcConnectionInfo, string mobileInfo, Dictionary <string, List <string> > environments) { _runner = runner; _timeout = timeout; _mcConnectionInfo = mcConnectionInfo; _mobileInfo = mobileInfo; _environments = environments; _canRun = TrySetupParallelRunner(); }
public PerformanceTestRunner(IAssetRunner runner, TimeSpan timeout, int pollingInterval, TimeSpan perScenarioTimeOut, List <string> ignoreErrorStrings) { this._runner = runner; this._timeout = timeout; this._pollingInterval = pollingInterval; this._perScenarioTimeOutMinutes = perScenarioTimeOut; this._ignoreErrorStrings = ignoreErrorStrings; this._scenarioEnded = false; _engine = null; this._errors = null; this._errorsCount = 0; }
public PerformanceTestRunner(IAssetRunner runner, TimeSpan timeout, int pollingInterval, TimeSpan perScenarioTimeOut, List<string> ignoreErrorStrings) { this._runner = runner; this._timeout = timeout; this._pollingInterval = pollingInterval; this._perScenarioTimeOut = perScenarioTimeOut; this._ignoreErrorStrings = ignoreErrorStrings; this._scenarioEnded = false; _engine = null; this._errors = null; this._errorsCount = 0; }
public PerformanceTestRunner(IAssetRunner runner, TimeSpan timeout, int pollingInterval, TimeSpan perScenarioTimeOut, List <string> ignoreErrorStrings, bool displayController, string analysisTemplate) { this._runner = runner; this._timeout = timeout; this._pollingInterval = pollingInterval; this._perScenarioTimeOutMinutes = perScenarioTimeOut; this._ignoreErrorStrings = ignoreErrorStrings; this._displayController = displayController; this._analysisTemplate = analysisTemplate; this._scenarioEnded = false; _engine = null; this._errors = null; this._errorsCount = 0; }
/// <summary> /// analyzes and runs the tests given in the param file. /// </summary> public void Run() { _ciRun = true; if (_runtype == TestStorageType.Unknown) { Enum.TryParse <TestStorageType>(_ciParams["runType"], true, out _runtype); } if (_runtype == TestStorageType.Unknown) { WriteToConsole(Resources.LauncherNoRuntype); return; } if (!_ciParams.ContainsKey("resultsFilename")) { WriteToConsole(Resources.LauncherNoResFilenameFound); return; } string resultsFilename = _ciParams["resultsFilename"]; if (_ciParams.ContainsKey("uniqueTimeStamp")) { UniqueTimeStamp = _ciParams["uniqueTimeStamp"]; } else { UniqueTimeStamp = resultsFilename.ToLower().Replace("results", "").Replace(".xml", ""); } //create the runner according to type IAssetRunner runner = CreateRunner(_runtype, _ciParams); //runner instantiation failed (no tests to run or other problem) if (runner == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } //run the tests! RunTests(runner, resultsFilename); //Console.WriteLine("Press any key to exit..."); //Console.ReadKey(); ConsoleQuickEdit.Enable(); if (Launcher.ExitCode != ExitCodeEnum.Passed) { Environment.Exit((int)Launcher.ExitCode); } }
/// <summary> /// used by the run fuction to run the tests /// </summary> /// <param name="runner"></param> /// <param name="resultsFile"></param> private void RunTests(IAssetRunner runner, string resultsFile) { try { if (_ciRun) { _xmlBuilder = new JunitXmlBuilder(); _xmlBuilder.XmlName = resultsFile; } TestSuiteRunResults results = runner.Run(); if (results == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } _xmlBuilder.CreateXmlFromRunResults(results); //if there is an error if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; } int numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed); int numSuccess = results.TestRuns.Count(t => t.TestState == TestState.Passed); int numErrors = results.TestRuns.Count(t => t.TestState == TestState.Error); //TODO: Temporery fix to remove since jenkins doesnt retrive resutls from jobs that marked as failed and unstable marks jobs with only failed tests if ((numErrors <= 0) && (numFailures > 0)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Unstable; } foreach (var testRun in results.TestRuns) { if (testRun.FatalErrors > 0 && !testRun.TestPath.Equals("")) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; break; } } //this is the total run summary ConsoleWriter.ActiveTestRun = null; string runStatus = ""; switch (Launcher.ExitCode) { case ExitCodeEnum.Passed: runStatus = "Job succeeded"; break; case ExitCodeEnum.Unstable: runStatus = "Job unstable (Passed with failed tests)"; break; case ExitCodeEnum.Aborted: runStatus = "Job failed due to being Aborted"; break; case ExitCodeEnum.Failed: runStatus = "Job failed"; break; default: runStatus = "Error: Job status is Undefined"; break; } ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors)); if (!runner.RunWasCancelled) { results.TestRuns.ForEach(tr => ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath)); ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0) { ConsoleWriter.WriteLine("Job Errors summary:"); ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line)); } } //ConsoleWriter.WriteLine("Returning " + runStatus + "."); } finally { try { runner.Dispose(); } catch (Exception ex) { ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message)); }; } }
/// <summary> /// creates the correct runner according to the given type /// </summary> /// <param name="runType"></param> /// <param name="ciParams"></param> IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciParams) { IAssetRunner runner = null; switch (runType) { case TestStorageType.Alm: //check that all required parameters exist foreach (string param1 in requiredParamsForQcRun) { if (!_ciParams.ContainsKey(param1)) { ConsoleWriter.WriteLine(string.Format(Resources.LauncherParamRequired, param1)); return(null); } } //parse params that need parsing double dblQcTimeout = int.MaxValue; if (!double.TryParse(_ciParams["almTimeout"], out dblQcTimeout)) { ConsoleWriter.WriteLine(Resources.LauncherTimeoutNotNumeric); dblQcTimeout = int.MaxValue; } ConsoleWriter.WriteLine(string.Format(Resources.LuancherDisplayTimout, dblQcTimeout)); QcRunMode enmQcRunMode = QcRunMode.RUN_LOCAL; if (!Enum.TryParse <QcRunMode>(_ciParams["almRunMode"], true, out enmQcRunMode)) { ConsoleWriter.WriteLine(Resources.LauncherIncorrectRunmode); enmQcRunMode = QcRunMode.RUN_LOCAL; } ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayRunmode, enmQcRunMode.ToString())); //go over testsets in the parameters, and collect them List <string> sets = GetParamsWithPrefix("TestSet"); if (sets.Count == 0) { ConsoleWriter.WriteLine(Resources.LauncherNoTests); return(null); } //create an Alm runner runner = new AlmTestSetsRunner(_ciParams["almServerUrl"], _ciParams["almUserName"], Decrypt(_ciParams["almPassword"], secretkey), _ciParams["almDomain"], _ciParams["almProject"], dblQcTimeout, enmQcRunMode, _ciParams["almRunHost"], sets); break; case TestStorageType.FileSystem: //Get displayController var bool displayController = false; if (_ciParams.ContainsKey("displayController")) { if (_ciParams["displayController"] == "1") { displayController = true; } } string analysisTemplate = (_ciParams.ContainsKey("analysisTemplate") ? _ciParams["analysisTemplate"] : ""); Dictionary <string, string> testsKeyValue = GetKeyValuesWithPrefix("Test"); List <TestData> tests = new List <TestData>(); foreach (var item in testsKeyValue) { tests.Add(new TestData(item.Value, item.Key)); } //get the tests //IEnumerable<string> tests = GetParamsWithPrefix("Test"); IEnumerable <string> jenkinsEnvVariablesWithCommas = GetParamsWithPrefix("JenkinsEnv"); Dictionary <string, string> jenkinsEnvVariables = new Dictionary <string, string>(); foreach (string var in jenkinsEnvVariablesWithCommas) { string[] nameVal = var.Split(",;".ToCharArray()); jenkinsEnvVariables.Add(nameVal[0], nameVal[1]); } //parse the timeout into a TimeSpan TimeSpan timeout = TimeSpan.MaxValue; if (_ciParams.ContainsKey("fsTimeout")) { string strTimoutInSeconds = _ciParams["fsTimeout"]; if (strTimoutInSeconds.Trim() != "-1") { int intTimoutInSeconds = 0; int.TryParse(strTimoutInSeconds, out intTimoutInSeconds); timeout = TimeSpan.FromSeconds(intTimoutInSeconds); } } ConsoleWriter.WriteLine("Launcher timeout is " + timeout.ToString(@"dd\:\:hh\:mm\:ss")); //LR specific values: //default values are set by JAVA code, in com.hpe.application.automation.tools.model.RunFromFileSystemModel.java int pollingInterval = 30; if (_ciParams.ContainsKey("controllerPollingInterval")) { pollingInterval = int.Parse(_ciParams["controllerPollingInterval"]); } ConsoleWriter.WriteLine("Controller Polling Interval: " + pollingInterval + " seconds"); TimeSpan perScenarioTimeOutMinutes = TimeSpan.MaxValue; if (_ciParams.ContainsKey("PerScenarioTimeOut")) { string strTimoutInMinutes = _ciParams["PerScenarioTimeOut"]; //ConsoleWriter.WriteLine("reading PerScenarioTimeout: "+ strTimoutInMinutes); if (strTimoutInMinutes.Trim() != "-1") { int intTimoutInMinutes = 0; if (int.TryParse(strTimoutInMinutes, out intTimoutInMinutes)) { perScenarioTimeOutMinutes = TimeSpan.FromMinutes(intTimoutInMinutes); } //ConsoleWriter.WriteLine("PerScenarioTimeout: "+perScenarioTimeOutMinutes+" minutes"); } } ConsoleWriter.WriteLine("PerScenarioTimeout: " + perScenarioTimeOutMinutes.ToString(@"dd\:\:hh\:mm\:ss") + " minutes"); char[] delim = { '\n' }; List <string> ignoreErrorStrings = new List <string>(); if (_ciParams.ContainsKey("ignoreErrorStrings")) { if (_ciParams.ContainsKey("ignoreErrorStrings")) { ignoreErrorStrings.AddRange(Array.ConvertAll(_ciParams["ignoreErrorStrings"].Split(delim, StringSplitOptions.RemoveEmptyEntries), ignoreError => ignoreError.Trim())); } } if (tests == null || tests.Count() == 0) { WriteToConsole(Resources.LauncherNoTestsFound); } List <TestData> validTests = Helper.ValidateFiles(tests); if (tests != null && tests.Count() > 0 && validTests.Count == 0) { ConsoleWriter.WriteLine(Resources.LauncherNoValidTests); return(null); } //If a file path was provided and it doesn't exist stop the analysis launcher if (!analysisTemplate.Equals("") && !Helper.FileExists(analysisTemplate)) { return(null); } //--MC connection info McConnectionInfo mcConnectionInfo = new McConnectionInfo(); if (_ciParams.ContainsKey("MobileHostAddress")) { string mcServerUrl = _ciParams["MobileHostAddress"]; if (!string.IsNullOrEmpty(mcServerUrl)) { //url is something like http://xxx.xxx.xxx.xxx:8080 string[] strArray = mcServerUrl.Split(new Char[] { ':' }); if (strArray.Length == 3) { mcConnectionInfo.MobileHostAddress = strArray[1].Replace("/", ""); mcConnectionInfo.MobileHostPort = strArray[2]; } //mc username if (_ciParams.ContainsKey("MobileUserName")) { string mcUsername = _ciParams["MobileUserName"]; if (!string.IsNullOrEmpty(mcUsername)) { mcConnectionInfo.MobileUserName = mcUsername; } } //mc password if (_ciParams.ContainsKey("MobilePassword")) { string mcPassword = _ciParams["MobilePassword"]; if (!string.IsNullOrEmpty(mcPassword)) { mcConnectionInfo.MobilePassword = Decrypt(mcPassword, secretkey); } } //mc tenantId if (_ciParams.ContainsKey("MobileTenantId")) { string mcTenantId = _ciParams["MobileTenantId"]; if (!string.IsNullOrEmpty(mcTenantId)) { mcConnectionInfo.MobileTenantId = mcTenantId; } } //ssl if (_ciParams.ContainsKey("MobileUseSSL")) { string mcUseSSL = _ciParams["MobileUseSSL"]; if (!string.IsNullOrEmpty(mcUseSSL)) { mcConnectionInfo.MobileUseSSL = int.Parse(mcUseSSL); } } //Proxy enabled flag if (_ciParams.ContainsKey("MobileUseProxy")) { string useProxy = _ciParams["MobileUseProxy"]; if (!string.IsNullOrEmpty(useProxy)) { mcConnectionInfo.MobileUseProxy = int.Parse(useProxy); } } //Proxy type if (_ciParams.ContainsKey("MobileProxyType")) { string proxyType = _ciParams["MobileProxyType"]; if (!string.IsNullOrEmpty(proxyType)) { mcConnectionInfo.MobileProxyType = int.Parse(proxyType); } } //proxy address if (_ciParams.ContainsKey("MobileProxySetting_Address")) { string proxyAddress = _ciParams["MobileProxySetting_Address"]; if (!string.IsNullOrEmpty(proxyAddress)) { // data is something like "16.105.9.23:8080" string[] strArray4ProxyAddr = proxyAddress.Split(new Char[] { ':' }); if (strArray4ProxyAddr.Length == 2) { mcConnectionInfo.MobileProxySetting_Address = strArray4ProxyAddr[0]; mcConnectionInfo.MobileProxySetting_Port = int.Parse(strArray4ProxyAddr[1]); } } } //Proxy authentication if (_ciParams.ContainsKey("MobileProxySetting_Authentication")) { string proxyAuthentication = _ciParams["MobileProxySetting_Authentication"]; if (!string.IsNullOrEmpty(proxyAuthentication)) { mcConnectionInfo.MobileProxySetting_Authentication = int.Parse(proxyAuthentication); } } //Proxy username if (_ciParams.ContainsKey("MobileProxySetting_UserName")) { string proxyUsername = _ciParams["MobileProxySetting_UserName"]; if (!string.IsNullOrEmpty(proxyUsername)) { mcConnectionInfo.MobileProxySetting_UserName = proxyUsername; } } //Proxy password if (_ciParams.ContainsKey("MobileProxySetting_Password")) { string proxyPassword = _ciParams["MobileProxySetting_Password"]; if (!string.IsNullOrEmpty(proxyPassword)) { mcConnectionInfo.MobileProxySetting_Password = Decrypt(proxyPassword, secretkey); } } } } // other mobile info string mobileinfo = ""; if (_ciParams.ContainsKey("mobileinfo")) { mobileinfo = _ciParams["mobileinfo"]; } Dictionary <string, List <String> > parallelRunnerEnvironments = new Dictionary <string, List <string> >(); // retrieve the parallel runner environment for each test if (_ciParams.ContainsKey("parallelRunnerMode")) { foreach (var test in validTests) { string envKey = "Parallel" + test.Id + "Env"; List <string> testEnvironments = GetParamsWithPrefix(envKey); // add the environments for all the valid tests parallelRunnerEnvironments.Add(test.Id, testEnvironments); } } if (_ciParams.ContainsKey("fsUftRunMode")) { string uftRunMode = "Fast"; uftRunMode = _ciParams["fsUftRunMode"]; runner = new FileSystemTestsRunner(validTests, timeout, uftRunMode, pollingInterval, perScenarioTimeOutMinutes, ignoreErrorStrings, jenkinsEnvVariables, mcConnectionInfo, mobileinfo, parallelRunnerEnvironments, displayController, analysisTemplate); } else { runner = new FileSystemTestsRunner(validTests, timeout, pollingInterval, perScenarioTimeOutMinutes, ignoreErrorStrings, jenkinsEnvVariables, mcConnectionInfo, mobileinfo, parallelRunnerEnvironments, displayController, analysisTemplate); } break; default: runner = null; break; } return(runner); }
private void RunTests(IAssetRunner runner, string resultsFile, TestSuiteRunResults results) { try { if (_ciRun) { _xmlBuilder = new JunitXmlBuilder(); _xmlBuilder.XmlName = resultsFile; } if (results == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } _xmlBuilder.CreateXmlFromRunResults(results); if (results.TestRuns.Count == 0) { Console.WriteLine("No tests were run"); Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; Environment.Exit((int)Launcher.ExitCode); } //if there is an error if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; } int numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed); int numSuccess = results.TestRuns.Count(t => t.TestState == TestState.Passed); int numErrors = results.TestRuns.Count(t => t.TestState == TestState.Error); int numWarnings = results.TestRuns.Count(t => t.TestState == TestState.Warning); if ((numErrors <= 0) && (numFailures > 0)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; } if ((numErrors <= 0) && (numFailures > 0) && (numSuccess > 0)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Unstable; } foreach (var testRun in results.TestRuns) { if (testRun.FatalErrors > 0 && !testRun.TestPath.Equals("")) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; break; } } //this is the total run summary ConsoleWriter.ActiveTestRun = null; string runStatus = ""; switch (Launcher.ExitCode) { case ExitCodeEnum.Passed: runStatus = "Job succeeded"; break; case ExitCodeEnum.Unstable: runStatus = "Job unstable (Passed with failed tests)"; break; case ExitCodeEnum.Aborted: runStatus = "Job failed due to being Aborted"; break; case ExitCodeEnum.Failed: runStatus = "Job failed"; break; default: runStatus = "Error: Job status is Undefined"; break; } ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors, numWarnings)); int testIndex = 1; if (!runner.RunWasCancelled) { results.TestRuns.ForEach(tr => { ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath + "[" + testIndex + "]"); testIndex++; }); ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0) { ConsoleWriter.WriteLine("Job Errors summary:"); ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line)); } string onCheckFailedTests = (_ciParams.ContainsKey("onCheckFailedTest") ? _ciParams["onCheckFailedTest"] : ""); _rerunFailedTests = !string.IsNullOrEmpty(onCheckFailedTests) && Convert.ToBoolean(onCheckFailedTests.ToLower()); if (!_rerunFailedTests) { Environment.Exit((int)Launcher.ExitCode); } } } finally { try { runner.Dispose(); } catch (Exception ex) { ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message)); }; } }
/// <summary> /// analyzes and runs the tests given in the param file. /// </summary> public void Run() { _ciRun = true; if (_runtype == TestStorageType.Unknown) { Enum.TryParse <TestStorageType>(_ciParams["runType"], true, out _runtype); } if (_runtype == TestStorageType.Unknown) { WriteToConsole(Resources.LauncherNoRuntype); return; } if (!_ciParams.ContainsKey("resultsFilename")) { WriteToConsole(Resources.LauncherNoResFilenameFound); return; } string resultsFilename = _ciParams["resultsFilename"]; if (_ciParams.ContainsKey("uniqueTimeStamp")) { UniqueTimeStamp = _ciParams["uniqueTimeStamp"]; } else { UniqueTimeStamp = resultsFilename.ToLower().Replace("results", "").Replace(".xml", ""); } bool initialTestRun = true; //run the entire set of test once //create the runner according to type IAssetRunner runner = CreateRunner(_runtype, _ciParams, initialTestRun); //runner instantiation failed (no tests to run or other problem) if (runner == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } RunTests(runner, resultsFilename); if (_runtype.Equals(TestStorageType.Alm)) { bool filterSelected; string filter = (_ciParams.ContainsKey("FilterTests") ? _ciParams["FilterTests"] : ""); if (string.IsNullOrEmpty(filter)) { filterSelected = false; } else { filterSelected = Convert.ToBoolean(filter.ToLower()); } if (filterSelected.Equals(true) && Launcher.ExitCode != ExitCodeEnum.Passed) { //rerun selected tests initialTestRun = false; runner = CreateRunner(_runtype, _ciParams, initialTestRun); //runner instantiation failed (no tests to run or other problem) if (runner == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } RunTests(runner, resultsFilename); } } if (_runtype.Equals(TestStorageType.FileSystem)) { string onCheckFailedTests = (_ciParams.ContainsKey("onCheckFailedTest") ? _ciParams["onCheckFailedTest"] : ""); if (string.IsNullOrEmpty(onCheckFailedTests)) { rerunFailedTests = false; } else { rerunFailedTests = Convert.ToBoolean(onCheckFailedTests.ToLower()); } //the "On failure" option is selected and the run build contains failed tests if (rerunFailedTests.Equals(true) && Launcher.ExitCode != ExitCodeEnum.Passed) { ConsoleWriter.WriteLine("There are failed tests. Rerun the selected tests."); initialTestRun = false; //rerun the selected tests (either the entire set or just the selected ones) //create the runner according to type runner = CreateRunner(_runtype, _ciParams, initialTestRun); //runner instantiation failed (no tests to run or other problem) if (runner == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } RunTests(runner, resultsFilename); } } //Console.WriteLine("Press any key to exit..."); //Console.ReadKey(); ConsoleQuickEdit.Enable(); if (Launcher.ExitCode != ExitCodeEnum.Passed) { Environment.Exit((int)Launcher.ExitCode); } }
/// <summary> /// analyzes and runs the tests given in the param file. /// </summary> public void Run() { _ciRun = true; if (_runType == TestStorageType.Unknown) { Enum.TryParse <TestStorageType>(_ciParams["runType"], true, out _runType); } if (_runType == TestStorageType.Unknown) { WriteToConsole(Resources.LauncherNoRuntype); return; } if (!_ciParams.ContainsKey("resultsFilename")) { WriteToConsole(Resources.LauncherNoResFilenameFound); return; } string resultsFilename = _ciParams["resultsFilename"]; UniqueTimeStamp = _ciParams.ContainsKey("uniqueTimeStamp") ? _ciParams["uniqueTimeStamp"] : resultsFilename.ToLower().Replace("results", "").Replace(".xml", ""); //run the entire set of test once //create the runner according to type IAssetRunner runner = CreateRunner(_runType, _ciParams, true); //runner instantiation failed (no tests to run or other problem) if (runner == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } TestSuiteRunResults results = runner.Run(); RunTests(runner, resultsFilename, results); if (_runType.Equals(TestStorageType.FileSystem)) { string onCheckFailedTests = (_ciParams.ContainsKey("onCheckFailedTest") ? _ciParams["onCheckFailedTest"] : ""); _rerunFailedTests = !string.IsNullOrEmpty(onCheckFailedTests) && Convert.ToBoolean(onCheckFailedTests.ToLower()); //the "On failure" option is selected and the run build contains failed tests if (_rerunFailedTests.Equals(true) && Launcher.ExitCode != ExitCodeEnum.Passed) { ConsoleWriter.WriteLine("There are failed tests. Rerun the selected tests."); //rerun the selected tests (either the entire set or just the selected ones) //create the runner according to type runner = CreateRunner(_runType, _ciParams, false); //runner instantiation failed (no tests to run or other problem) if (runner == null) { Environment.Exit((int)Launcher.ExitCodeEnum.Failed); } TestSuiteRunResults rerunResults = runner.Run(); results.AppendResults(rerunResults); RunTests(runner, resultsFilename, results); } } ConsoleQuickEdit.Enable(); if (Launcher.ExitCode != ExitCodeEnum.Passed) { Environment.Exit((int)Launcher.ExitCode); } }
/// <summary> /// used by the run fuction to run the tests /// </summary> /// <param name="runner"></param> /// <param name="resultsFile"></param> private void RunTests(IAssetRunner runner, string resultsFile) { try { if (_ciRun) { _xmlBuilder = new JunitXmlBuilder(); _xmlBuilder.XmlName = resultsFile; } TestSuiteRunResults results = runner.Run(); if (results == null) Environment.Exit((int)Launcher.ExitCodeEnum.Failed); _xmlBuilder.CreateXmlFromRunResults(results); //if there is an error if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; } //this is the total run summary ConsoleWriter.ActiveTestRun = null; string runStatus = (Launcher.ExitCode == ExitCodeEnum.Passed || Launcher.ExitCode == ExitCodeEnum.Unstable) ? "Job succeeded" : "Job failed"; int numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed); int numSuccess = results.TestRuns.Count(t => t.TestState == TestState.Passed); int numErrors = results.TestRuns.Count(t => t.TestState == TestState.Error); ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors)); if (!runner.RunWasCancelled) { results.TestRuns.ForEach(tr => ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath)); ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0) { ConsoleWriter.WriteLine("Job Errors summary:"); ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line)); } } //ConsoleWriter.WriteLine("Returning " + runStatus + "."); } finally { try { runner.Dispose(); } catch (Exception ex) { ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message)); }; } }
/// <summary> /// creates the correct runner according to the given type /// </summary> /// <param name="runType"></param> /// <param name="ciParams"></param> /// <param name="initialTestRun"></param> private IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciParams, bool initialTestRun) { IAssetRunner runner = null; switch (runType) { case TestStorageType.Alm: //check that all required parameters exist foreach (string param1 in requiredParamsForQcRun) { if (!_ciParams.ContainsKey(param1)) { ConsoleWriter.WriteLine(string.Format(Resources.LauncherParamRequired, param1)); return(null); } } //parse params that need parsing double dblQcTimeout = int.MaxValue; if (!double.TryParse(_ciParams["almTimeout"], out dblQcTimeout)) { ConsoleWriter.WriteLine(Resources.LauncherTimeoutNotNumeric); dblQcTimeout = int.MaxValue; } ConsoleWriter.WriteLine(string.Format(Resources.LuancherDisplayTimout, dblQcTimeout)); QcRunMode enmQcRunMode = QcRunMode.RUN_LOCAL; if (!Enum.TryParse <QcRunMode>(_ciParams["almRunMode"], true, out enmQcRunMode)) { ConsoleWriter.WriteLine(Resources.LauncherIncorrectRunmode); enmQcRunMode = QcRunMode.RUN_LOCAL; } ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayRunmode, enmQcRunMode.ToString())); //go over test sets in the parameters, and collect them List <string> sets = GetParamsWithPrefix("TestSet"); if (sets.Count == 0) { ConsoleWriter.WriteLine(Resources.LauncherNoTests); return(null); } //check if filterTests flag is selected; if yes apply filters on the list bool isFilterSelected; string filter = _ciParams.ContainsKey("FilterTests") ? _ciParams["FilterTests"] : ""; isFilterSelected = !string.IsNullOrEmpty(filter) && Convert.ToBoolean(filter.ToLower()); string filterByName = _ciParams.ContainsKey("FilterByName") ? _ciParams["FilterByName"] : ""; string statuses = _ciParams.ContainsKey("FilterByStatus") ? _ciParams["FilterByStatus"] : ""; List <string> filterByStatuses = new List <string>(); if (statuses != "") { if (statuses.Contains(",")) { filterByStatuses = statuses.Split(',').ToList(); } else { filterByStatuses.Add(statuses); } } bool isSSOEnabled = _ciParams.ContainsKey("SSOEnabled") && Convert.ToBoolean(_ciParams["SSOEnabled"]); //create an Alm runner runner = new AlmTestSetsRunner(_ciParams["almServerUrl"], _ciParams["almUserName"], Decrypt(_ciParams["almPassword"], _secretKey), _ciParams["almDomain"], _ciParams["almProject"], dblQcTimeout, enmQcRunMode, _ciParams["almRunHost"], sets, isFilterSelected, filterByName, filterByStatuses, initialTestRun, TestStorageType.Alm, isSSOEnabled, _ciParams["almClientID"], Decrypt(_ciParams["almApiKey"], _secretKey)); break; case TestStorageType.FileSystem: bool displayController = false; if (_ciParams.ContainsKey("displayController")) { if (_ciParams["displayController"] == "1") { displayController = true; } } string analysisTemplate = (_ciParams.ContainsKey("analysisTemplate") ? _ciParams["analysisTemplate"] : ""); List <TestData> validBuildTests = GetValidTests("Test", Resources.LauncherNoTestsFound, Resources.LauncherNoValidTests); //add build tests and cleanup tests in correct order List <TestData> validTests = new List <TestData>(); if (!_rerunFailedTests) { ConsoleWriter.WriteLine("Run build tests"); //run only the build tests foreach (var item in validBuildTests) { validTests.Add(item); } } else { //add also cleanup tests string fsTestType = (_ciParams.ContainsKey("testType") ? _ciParams["testType"] : ""); List <TestData> validFailedTests = GetValidTests("FailedTest", Resources.LauncherNoFailedTestsFound, Resources.LauncherNoValidFailedTests); List <TestData> validCleanupTests = new List <TestData>(); if (GetValidTests("CleanupTest", Resources.LauncherNoCleanupTestsFound, Resources.LauncherNoValidCleanupTests).Count > 0) { validCleanupTests = GetValidTests("CleanupTest", Resources.LauncherNoCleanupTestsFound, Resources.LauncherNoValidCleanupTests); } List <string> reruns = GetParamsWithPrefix("Reruns"); List <int> numberOfReruns = new List <int>(); foreach (var item in reruns) { numberOfReruns.Add(int.Parse(item)); } bool noRerunsSet = CheckListOfRerunValues(numberOfReruns); if (noRerunsSet) { ConsoleWriter.WriteLine("In order to rerun the tests the number of reruns should be greater than zero."); } else { for (int i = 0; i < numberOfReruns.Count; i++) { var currentRerun = numberOfReruns.ElementAt(i); if (fsTestType.Equals("Of any of the build's tests")) { ConsoleWriter.WriteLine("Rerun the entire test set"); while (currentRerun > 0) { if (validCleanupTests.Count > 0) { validTests.Add(validCleanupTests.ElementAt(i)); } foreach (var item in validFailedTests) { validTests.Add(item); } currentRerun--; } } else { while (currentRerun > 0) { if (validCleanupTests.Count > 0) { validTests.Add(validCleanupTests.ElementAt(i)); } validTests.Add(validFailedTests.ElementAt(i)); currentRerun--; } } } } } //get the tests //IEnumerable<string> tests = GetParamsWithPrefix("Test"); IEnumerable <string> jenkinsEnvVariablesWithCommas = GetParamsWithPrefix("JenkinsEnv"); Dictionary <string, string> jenkinsEnvVariables = new Dictionary <string, string>(); foreach (string var in jenkinsEnvVariablesWithCommas) { string[] nameVal = var.Split(",;".ToCharArray()); jenkinsEnvVariables.Add(nameVal[0], nameVal[1]); } //parse the timeout into a TimeSpan TimeSpan timeout = TimeSpan.MaxValue; if (_ciParams.ContainsKey("fsTimeout")) { string strTimeoutInSeconds = _ciParams["fsTimeout"]; if (strTimeoutInSeconds.Trim() != "-1") { int intTimeoutInSeconds = 0; int.TryParse(strTimeoutInSeconds, out intTimeoutInSeconds); timeout = TimeSpan.FromSeconds(intTimeoutInSeconds); } } ConsoleWriter.WriteLine("Launcher timeout is " + timeout.ToString(@"dd\:\:hh\:mm\:ss")); //LR specific values: //default values are set by JAVA code, in com.hpe.application.automation.tools.model.RunFromFileSystemModel.java int pollingInterval = 30; if (_ciParams.ContainsKey("controllerPollingInterval")) { pollingInterval = int.Parse(_ciParams["controllerPollingInterval"]); } ConsoleWriter.WriteLine("Controller Polling Interval: " + pollingInterval + " seconds"); TimeSpan perScenarioTimeOutMinutes = TimeSpan.MaxValue; if (_ciParams.ContainsKey("PerScenarioTimeOut")) { string strTimeoutInMinutes = _ciParams["PerScenarioTimeOut"]; //ConsoleWriter.WriteLine("reading PerScenarioTimeout: "+ strTimoutInMinutes); if (strTimeoutInMinutes.Trim() != "-1") { int intTimoutInMinutes = 0; if (int.TryParse(strTimeoutInMinutes, out intTimoutInMinutes)) { perScenarioTimeOutMinutes = TimeSpan.FromMinutes(intTimoutInMinutes); } //ConsoleWriter.WriteLine("PerScenarioTimeout: "+perScenarioTimeOutMinutes+" minutes"); } } ConsoleWriter.WriteLine("PerScenarioTimeout: " + perScenarioTimeOutMinutes.ToString(@"dd\:\:hh\:mm\:ss") + " minutes"); char[] delimiter = { '\n' }; List <string> ignoreErrorStrings = new List <string>(); if (_ciParams.ContainsKey("ignoreErrorStrings")) { if (_ciParams.ContainsKey("ignoreErrorStrings")) { ignoreErrorStrings.AddRange(Array.ConvertAll(_ciParams["ignoreErrorStrings"].Split(delimiter, StringSplitOptions.RemoveEmptyEntries), ignoreError => ignoreError.Trim())); } } //If a file path was provided and it doesn't exist stop the analysis launcher if (!analysisTemplate.Equals("") && !Helper.FileExists(analysisTemplate)) { return(null); } //--MC connection info McConnectionInfo mcConnectionInfo = new McConnectionInfo(); if (_ciParams.ContainsKey("MobileHostAddress")) { string mcServerUrl = _ciParams["MobileHostAddress"]; if (!string.IsNullOrEmpty(mcServerUrl)) { //url is something like http://xxx.xxx.xxx.xxx:8080 string[] strArray = mcServerUrl.Split(new Char[] { ':' }); if (strArray.Length == 3) { mcConnectionInfo.MobileHostAddress = strArray[1].Replace("/", ""); mcConnectionInfo.MobileHostPort = strArray[2]; } //mc username if (_ciParams.ContainsKey("MobileUserName")) { string mcUsername = _ciParams["MobileUserName"]; if (!string.IsNullOrEmpty(mcUsername)) { mcConnectionInfo.MobileUserName = mcUsername; } } //mc password if (_ciParams.ContainsKey("MobilePassword")) { string mcPassword = _ciParams["MobilePassword"]; if (!string.IsNullOrEmpty(mcPassword)) { mcConnectionInfo.MobilePassword = Decrypt(mcPassword, _secretKey); } } //mc tenantId if (_ciParams.ContainsKey("MobileTenantId")) { string mcTenantId = _ciParams["MobileTenantId"]; if (!string.IsNullOrEmpty(mcTenantId)) { mcConnectionInfo.MobileTenantId = mcTenantId; } } //ssl if (_ciParams.ContainsKey("MobileUseSSL")) { string mcUseSSL = _ciParams["MobileUseSSL"]; if (!string.IsNullOrEmpty(mcUseSSL)) { mcConnectionInfo.MobileUseSSL = int.Parse(mcUseSSL); } } //Proxy enabled flag if (_ciParams.ContainsKey("MobileUseProxy")) { string useProxy = _ciParams["MobileUseProxy"]; if (!string.IsNullOrEmpty(useProxy)) { mcConnectionInfo.MobileUseProxy = int.Parse(useProxy); } } //Proxy type if (_ciParams.ContainsKey("MobileProxyType")) { string proxyType = _ciParams["MobileProxyType"]; if (!string.IsNullOrEmpty(proxyType)) { mcConnectionInfo.MobileProxyType = int.Parse(proxyType); } } //proxy address if (_ciParams.ContainsKey("MobileProxySetting_Address")) { string proxyAddress = _ciParams["MobileProxySetting_Address"]; if (!string.IsNullOrEmpty(proxyAddress)) { // data is something like "16.105.9.23:8080" string[] strArrayForProxyAddress = proxyAddress.Split(new Char[] { ':' }); if (strArrayForProxyAddress.Length == 2) { mcConnectionInfo.MobileProxySetting_Address = strArrayForProxyAddress[0]; mcConnectionInfo.MobileProxySetting_Port = int.Parse(strArrayForProxyAddress[1]); } } } //Proxy authentication if (_ciParams.ContainsKey("MobileProxySetting_Authentication")) { string proxyAuthentication = _ciParams["MobileProxySetting_Authentication"]; if (!string.IsNullOrEmpty(proxyAuthentication)) { mcConnectionInfo.MobileProxySetting_Authentication = int.Parse(proxyAuthentication); } } //Proxy username if (_ciParams.ContainsKey("MobileProxySetting_UserName")) { string proxyUsername = _ciParams["MobileProxySetting_UserName"]; if (!string.IsNullOrEmpty(proxyUsername)) { mcConnectionInfo.MobileProxySetting_UserName = proxyUsername; } } //Proxy password if (_ciParams.ContainsKey("MobileProxySetting_Password")) { string proxyPassword = _ciParams["MobileProxySetting_Password"]; if (!string.IsNullOrEmpty(proxyPassword)) { mcConnectionInfo.MobileProxySetting_Password = Decrypt(proxyPassword, _secretKey); } } } } // other mobile info string mobileinfo = ""; if (_ciParams.ContainsKey("mobileinfo")) { mobileinfo = _ciParams["mobileinfo"]; } Dictionary <string, List <String> > parallelRunnerEnvironments = new Dictionary <string, List <string> >(); // retrieve the parallel runner environment for each test if (_ciParams.ContainsKey("parallelRunnerMode")) { foreach (var test in validTests) { string envKey = "Parallel" + test.Id + "Env"; List <string> testEnvironments = GetParamsWithPrefix(envKey); // add the environments for all the valid tests parallelRunnerEnvironments.Add(test.Id, testEnvironments); } } // users can provide a custom report path string reportPath = null; if (_ciParams.ContainsKey("fsReportPath")) { reportPath = _ciParams["fsReportPath"]; } SummaryDataLogger summaryDataLogger = GetSummaryDataLogger(); List <ScriptRTSModel> scriptRTSSet = GetScriptRtsSet(); if (_ciParams.ContainsKey("fsUftRunMode")) { string uftRunMode = "Fast"; uftRunMode = _ciParams["fsUftRunMode"]; runner = new FileSystemTestsRunner(validTests, timeout, uftRunMode, pollingInterval, perScenarioTimeOutMinutes, ignoreErrorStrings, jenkinsEnvVariables, mcConnectionInfo, mobileinfo, parallelRunnerEnvironments, displayController, analysisTemplate, summaryDataLogger, scriptRTSSet, reportPath); } else { runner = new FileSystemTestsRunner(validTests, timeout, pollingInterval, perScenarioTimeOutMinutes, ignoreErrorStrings, jenkinsEnvVariables, mcConnectionInfo, mobileinfo, parallelRunnerEnvironments, displayController, analysisTemplate, summaryDataLogger, scriptRTSSet, reportPath); } break; default: runner = null; break; } return(runner); }
/// <summary> /// creates the correct runner according to the given type /// </summary> /// <param name="runType"></param> /// <param name="ciParams"></param> IAssetRunner CreateRunner(TestStorageType runType, JavaProperties ciParams) { IAssetRunner runner = null; switch (runType) { case TestStorageType.Alm: //check that all required parameters exist foreach (string param1 in requiredParamsForQcRun) { if (!_ciParams.ContainsKey(param1)) { ConsoleWriter.WriteLine(string.Format(Resources.LauncherParamRequired, param1)); return(null); } } //parse params that need parsing double dblQcTimeout = int.MaxValue; if (!double.TryParse(_ciParams["almTimeout"], out dblQcTimeout)) { ConsoleWriter.WriteLine(Resources.LauncherTimeoutNotNumeric); dblQcTimeout = int.MaxValue; } ConsoleWriter.WriteLine(string.Format(Resources.LuancherDisplayTimout, dblQcTimeout)); QcRunMode enmQcRunMode = QcRunMode.RUN_LOCAL; if (!Enum.TryParse <QcRunMode>(_ciParams["almRunMode"], true, out enmQcRunMode)) { ConsoleWriter.WriteLine(Resources.LauncherIncorrectRunmode); enmQcRunMode = QcRunMode.RUN_LOCAL; } ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayRunmode, enmQcRunMode.ToString())); //go over testsets in the parameters, and collect them List <string> sets = GetParamsWithPrefix("TestSet"); if (sets.Count == 0) { ConsoleWriter.WriteLine(Resources.LauncherNoTests); return(null); } //create an Alm runner runner = new AlmTestSetsRunner(_ciParams["almServerUrl"], _ciParams["almUserName"], Decrypt(_ciParams["almPassword"], secretkey), _ciParams["almDomain"], _ciParams["almProject"], dblQcTimeout, enmQcRunMode, _ciParams["almRunHost"], sets); break; case TestStorageType.FileSystem: //get the tests IEnumerable <string> tests = GetParamsWithPrefix("Test"); IEnumerable <string> jenkinsEnvVariablesWithCommas = GetParamsWithPrefix("JenkinsEnv"); Dictionary <string, string> jenkinsEnvVariables = new Dictionary <string, string>(); foreach (string var in jenkinsEnvVariablesWithCommas) { string[] nameVal = var.Split(",;".ToCharArray()); jenkinsEnvVariables.Add(nameVal[0], nameVal[1]); } //parse the timeout into a TimeSpan TimeSpan timeout = TimeSpan.MaxValue; if (_ciParams.ContainsKey("fsTimeout")) { string strTimoutInSeconds = _ciParams["fsTimeout"]; if (strTimoutInSeconds.Trim() != "-1") { int intTimoutInSeconds = 0; int.TryParse(strTimoutInSeconds, out intTimoutInSeconds); timeout = TimeSpan.FromSeconds(intTimoutInSeconds); } } //LR specific values: //default values are set by JAVA code, in com.hp.application.automation.tools.model.RunFromFileSystemModel.java int pollingInterval = 30; if (_ciParams.ContainsKey("controllerPollingInterval")) { pollingInterval = int.Parse(_ciParams["controllerPollingInterval"]); } TimeSpan perScenarioTimeOut = TimeSpan.MaxValue; if (_ciParams.ContainsKey("PerScenarioTimeOut")) { string strTimoutInSeconds = _ciParams["PerScenarioTimeOut"]; if (strTimoutInSeconds.Trim() != "-1") { int intTimoutInSeconds = 0; if (int.TryParse(strTimoutInSeconds, out intTimoutInSeconds)) { perScenarioTimeOut = TimeSpan.FromMinutes(intTimoutInSeconds); } } } char[] delim = { '\n' }; List <string> ignoreErrorStrings = new List <string>(); if (_ciParams.ContainsKey("ignoreErrorStrings")) { ignoreErrorStrings.AddRange(_ciParams["ignoreErrorStrings"].Split(delim, StringSplitOptions.RemoveEmptyEntries)); } if (tests == null || tests.Count() == 0) { WriteToConsole(Resources.LauncherNoTestsFound); } List <string> validTests = Helper.ValidateFiles(tests); if (tests != null && tests.Count() > 0 && validTests.Count == 0) { ConsoleWriter.WriteLine(Resources.LauncherNoValidTests); return(null); } runner = new FileSystemTestsRunner(validTests, timeout, pollingInterval, perScenarioTimeOut, ignoreErrorStrings, jenkinsEnvVariables); break; default: runner = null; break; } return(runner); }
/// <summary> /// used by the run fuction to run the tests /// </summary> /// <param name="runner"></param> /// <param name="resultsFile"></param> private void RunTests(IAssetRunner runner, string resultsFile) { try { if (_ciRun) { _xmlBuilder = new JunitXmlBuilder(); _xmlBuilder.XmlName = resultsFile; } TestSuiteRunResults results = runner.Run(); if (results == null) Environment.Exit((int)Launcher.ExitCodeEnum.Failed); _xmlBuilder.CreateXmlFromRunResults(results); //if there is an error if (results.TestRuns.Any(tr => tr.TestState == TestState.Failed || tr.TestState == TestState.Error)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; } int numFailures = results.TestRuns.Count(t => t.TestState == TestState.Failed); int numSuccess = results.TestRuns.Count(t => t.TestState == TestState.Passed); int numErrors = results.TestRuns.Count(t => t.TestState == TestState.Error); //TODO: Temporery fix to remove since jenkins doesnt retrive resutls from jobs that marked as failed and unstable marks jobs with only failed tests if ((numErrors <= 0) && (numFailures > 0)) { Launcher.ExitCode = Launcher.ExitCodeEnum.Unstable; } foreach (var testRun in results.TestRuns) { if (testRun.FatalErrors > 0 && !testRun.TestPath.Equals("")) { Launcher.ExitCode = Launcher.ExitCodeEnum.Failed; break; } } //this is the total run summary ConsoleWriter.ActiveTestRun = null; string runStatus = ""; switch (Launcher.ExitCode) { case ExitCodeEnum.Passed: runStatus = "Job succeeded"; break; case ExitCodeEnum.Unstable: runStatus = "Job unstable (Passed with failed tests)"; break; case ExitCodeEnum.Aborted: runStatus = "Job failed due to being Aborted"; break; case ExitCodeEnum.Failed: runStatus = "Job failed"; break; default: runStatus = "Error: Job status is Undefined"; break; } ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); ConsoleWriter.WriteLine(string.Format(Resources.LauncherDisplayStatistics, runStatus, results.TestRuns.Count, numSuccess, numFailures, numErrors)); if (!runner.RunWasCancelled) { results.TestRuns.ForEach(tr => ConsoleWriter.WriteLine(((tr.HasWarnings) ? "Warning".PadLeft(7) : tr.TestState.ToString().PadRight(7)) + ": " + tr.TestPath)); ConsoleWriter.WriteLine(Resources.LauncherDoubleSeperator); if (ConsoleWriter.ErrorSummaryLines != null && ConsoleWriter.ErrorSummaryLines.Count > 0) { ConsoleWriter.WriteLine("Job Errors summary:"); ConsoleWriter.ErrorSummaryLines.ForEach(line => ConsoleWriter.WriteLine(line)); } } //ConsoleWriter.WriteLine("Returning " + runStatus + "."); } finally { try { runner.Dispose(); } catch (Exception ex) { ConsoleWriter.WriteLine(string.Format(Resources.LauncherRunnerDisposeError, ex.Message)); }; } }