/// <summary> /// runs the given test /// </summary> /// <param name="testPath"></param> /// <param name="errorReason"></param> /// <param name="runCancelled">cancellation delegate, holds the function that checks cancellation</param> /// <returns></returns> public TestRunResults RunTest(string testPath, ref string errorReason, RunCancelledDelegate runCancelled) { TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testPath); runDesc.ReportLocation = Helper.CreateTempDir(); runDesc.ErrorDesc = errorReason; runDesc.TestPath = testPath; runDesc.TestState = TestState.Unknown; if (!Helper.IsServiceTestInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.LauncherStNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } _runCancelled = runCancelled; if (!_stCanRun) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; return(runDesc); } string fileName = Path.Combine(_stExecuterPath, STRunnerName); if (!File.Exists(fileName)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; ConsoleWriter.WriteErrLine(Resources.STExecuterNotFound); return(runDesc); } Stopwatch s = Stopwatch.StartNew(); runDesc.TestState = TestState.Running; if (!ExecuteProcess(fileName, String.Format("{0} \"{1}\" {2} \"{3}\" ", STRunnerTestArg, testPath, STRunnerReportArg, runDesc.ReportLocation), ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; runDesc.Runtime = s.Elapsed; return(runDesc); } else { runDesc.ReportLocation = Path.Combine(runDesc.ReportLocation, "Report"); } runDesc.Runtime = s.Elapsed; return(runDesc); }
/// <summary> /// runs the given test /// </summary> /// <param name="testPath"></param> /// <param name="errorReason"></param> /// <param name="runCancelled">cancellation delegate, holds the function that checks cancellation</param> /// <returns></returns> public TestRunResults RunTest(string testPath, ref string errorReason, RunCancelledDelegate runCancelled) { TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testPath); runDesc.ReportLocation = Helper.CreateTempDir(); runDesc.ErrorDesc = errorReason; runDesc.TestPath = testPath; runDesc.TestState = TestState.Unknown; if (!Helper.IsServiceTestInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.LauncherStNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return runDesc; } _runCancelled = runCancelled; if (!_stCanRun) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; return runDesc; } string fileName = Path.Combine(_stExecuterPath, STRunnerName); if (!File.Exists(fileName)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; ConsoleWriter.WriteErrLine(Resources.STExecuterNotFound); return runDesc; } Stopwatch s = Stopwatch.StartNew(); runDesc.TestState = TestState.Running; if (!ExecuteProcess(fileName, String.Format("{0} \"{1}\" {2} \"{3}\" ", STRunnerTestArg, testPath, STRunnerReportArg, runDesc.ReportLocation), ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; runDesc.Runtime = s.Elapsed; return runDesc; } else { runDesc.ReportLocation = Path.Combine(runDesc.ReportLocation, "Report"); } runDesc.Runtime = s.Elapsed; return runDesc; }
/// <summary> /// runs the given test /// </summary> /// <param name="testinf"></param> /// <param name="errorReason"></param> /// <param name="runCancelled">cancellation delegate, holds the function that checks cancellation</param> /// <returns></returns> public TestRunResults RunTest(TestInfo testinf, ref string errorReason, RunCancelledDelegate runCancelled) { TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testinf.TestPath); runDesc.ReportLocation = Helper.CreateTempDir(); runDesc.ErrorDesc = errorReason; runDesc.TestPath = testinf.TestPath; runDesc.TestState = TestState.Unknown; if (!Helper.IsServiceTestInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.LauncherStNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return runDesc; } _runCancelled = runCancelled; if (!_stCanRun) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; return runDesc; } string fileName = Path.Combine(_stExecuterPath, STRunnerName); if (!File.Exists(fileName)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; ConsoleWriter.WriteErrLine(Resources.STExecuterNotFound); return runDesc; } //write the input parameter xml file for the API test string paramFileName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 10); string tempPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestParams"); Directory.CreateDirectory(tempPath); string paramsFilePath = Path.Combine(tempPath, "params" + paramFileName + ".xml"); string paramFileContent = testinf.GenerateAPITestXmlForTest(); string argumentString = ""; if (!string.IsNullOrWhiteSpace(paramFileContent)) { File.WriteAllText(paramsFilePath, paramFileContent); argumentString = String.Format("{0} \"{1}\" {2} \"{3}\" {4} \"{5}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation, STRunnerInputParamsArg, paramsFilePath); } else { argumentString = String.Format("{0} \"{1}\" {2} \"{3}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation); } Stopwatch s = Stopwatch.StartNew(); runDesc.TestState = TestState.Running; if (!ExecuteProcess(fileName, argumentString, ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; } else { runDesc.ReportLocation = Path.Combine(runDesc.ReportLocation, "Report"); if (!File.Exists(Path.Combine(runDesc.ReportLocation, "Results.xml"))) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = "No Results.xml file found"; } } //File.Delete(paramsFilePath); runDesc.Runtime = s.Elapsed; return runDesc; }
/// <summary> /// runs the given test and returns resutls /// </summary> /// <param name="testPath"></param> /// <param name="errorReason"></param> /// <param name="runCanclled"></param> /// <returns></returns> public TestRunResults RunTest(TestInfo testinf, ref string errorReason, RunCancelledDelegate runCanclled) { var testPath = testinf.TestPath; TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testPath); runDesc.ReportLocation = testPath; runDesc.TestPath = testPath; runDesc.TestState = TestState.Unknown; _runCancelled = runCanclled; if (!Helper.IsQtpInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.GeneralQtpNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } string reason = string.Empty; if (!Helper.CanUftProcessStart(out reason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = reason; ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } try { ChangeDCOMSettingToInteractiveUser(); var type = Type.GetTypeFromProgID("Quicktest.Application"); lock (_lockObject) { _qtpApplication = Activator.CreateInstance(type) as Application; Version qtpVersion = Version.Parse(_qtpApplication.Version); if (qtpVersion.Equals(new Version(11, 0))) { runDesc.ReportLocation = Path.Combine(testPath, "Report"); if (Directory.Exists(runDesc.ReportLocation)) { Directory.Delete(runDesc.ReportLocation, true); Directory.CreateDirectory(runDesc.ReportLocation); } } // Check for required Addins LoadNeededAddins(testPath); // set Mc connection and other mobile info into rack if neccesary #region Mc connection and other mobile info // Mc Address, username and password if (!string.IsNullOrEmpty(_mcConnection.MobileHostAddress)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_HOST_ADDRESS, _mcConnection.MobileHostAddress); if (!string.IsNullOrEmpty(_mcConnection.MobileHostPort)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_HOST_PORT, _mcConnection.MobileHostPort); } } if (!string.IsNullOrEmpty(_mcConnection.MobileUserName)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_USER, _mcConnection.MobileUserName); } if (!string.IsNullOrEmpty(_mcConnection.MobilePassword)) { string encriptedMcPassword = WinUserNativeMethods.ProtectBSTRToBase64(_mcConnection.MobilePassword); if (encriptedMcPassword == null) { ConsoleWriter.WriteLine("ProtectBSTRToBase64 fail for mcPassword"); throw new Exception("ProtectBSTRToBase64 fail for mcPassword"); } _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PASSWORD, encriptedMcPassword); } // ssl and proxy info _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_USE_SSL, _mcConnection.MobileUseSSL); if (_mcConnection.MobileUseProxy == 1) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_USE_PROXY, _mcConnection.MobileUseProxy); _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_ADDRESS, _mcConnection.MobileProxySetting_Address); _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_PORT, _mcConnection.MobileProxySetting_Port); _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_AUTHENTICATION, _mcConnection.MobileProxySetting_Authentication); _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_USERNAME, _mcConnection.MobileProxySetting_UserName); string encriptedMcProxyPassword = WinUserNativeMethods.ProtectBSTRToBase64(_mcConnection.MobileProxySetting_Password); if (encriptedMcProxyPassword == null) { ConsoleWriter.WriteLine("ProtectBSTRToBase64 fail for mc proxy Password"); throw new Exception("ProtectBSTRToBase64 fail for mc proxy Password"); } _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_PASSWORD, encriptedMcProxyPassword); } // Mc info (device, app, launch and terminate data) if (!string.IsNullOrEmpty(_mobileInfo)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_INFO, _mobileInfo); } #endregion if (!_qtpApplication.Launched) { if (_runCancelled()) { QTPTestCleanup(); KillQtp(); runDesc.TestState = TestState.Error; return(runDesc); } // Launch application after set Addins _qtpApplication.Launch(); _qtpApplication.Visible = false; } } } catch (Exception e) { errorReason = Resources.QtpNotLaunchedError; runDesc.TestState = TestState.Error; runDesc.ReportLocation = ""; runDesc.ErrorDesc = e.Message; return(runDesc); } if (_qtpApplication.Test != null && _qtpApplication.Test.Modified) { var message = Resources.QtpNotLaunchedError; errorReason = message; runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } _qtpApplication.UseLicenseOfType(_useUFTLicense ? tagUnifiedLicenseType.qtUnifiedFunctionalTesting : tagUnifiedLicenseType.qtNonUnified); if (!HandleInputParameters(testPath, ref errorReason, testinf.GetParameterDictionaryForQTP())) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } GuiTestRunResult guiTestRunResult = ExecuteQTPRun(runDesc); runDesc.ReportLocation = guiTestRunResult.ReportPath; if (!guiTestRunResult.IsSuccess) { runDesc.TestState = TestState.Error; return(runDesc); } if (!HandleOutputArguments(ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } QTPTestCleanup(); return(runDesc); }
private bool runScenario(string scenario, ref string errorReason, RunCancelledDelegate runCancelled) { cleanENV(); ConsoleWriter.WriteLine(string.Format(Resources.LrInitScenario, scenario)); //start controller _engine = new LrEngine(); if (_engine == null) { errorReason = string.Format(Resources.LrFailToOpenController, scenario); return(false); } //try to register the end scenario event: _scenarioEndedEvent = false; try { _engine.Events.ScenarioEvents.OnScenarioEnded += ScenarioEvents_OnScenarioEnded; _scenarioEndedEvent = true; } catch (Exception e) { ConsoleWriter.WriteException(Resources.LrFailToRegisterEndScenarioEvent, e); _scenarioEndedEvent = false; } if (_displayController == true) { _engine.ShowMainWindow(1); } else { _engine.ShowMainWindow(0); } //pointer to the scenario object: LrScenario currentScenario = _engine.Scenario; //try to open the scenario and validate the scenario and connect to load generators if (openScenario(scenario, ref errorReason) && validateScenario(currentScenario, ref errorReason)) { //apply rts to scripts foreach (ScriptRTSModel scriptRTS in _scriptRTSSet) { try { LrScripts currentScripts = currentScenario.Scripts; LrScript currentScript = currentScripts.Item[scriptRTS.GetScriptName()]; string runtimeSettings = "", actionLogic = ""; currentScript.GetScriptRunTimeSettings(ref runtimeSettings, ref actionLogic); RTSHelper rtsHelper = new RTSHelper(runtimeSettings, RTSHelper.COMMAND_ARGUMENTS, scriptRTS.GetKeyValuePairs()); string updatedRuntimeSettings = rtsHelper.GetUpdatedIniFileText(); currentScript.SetScriptRunTimeSettings(updatedRuntimeSettings, actionLogic); } catch (Exception e) { errorReason = string.Format(Resources.LrRTSError, scriptRTS.GetScriptName(), e.Message); return(false); } } //set the result dir: ConsoleWriter.WriteLine("setting scenario result folder to " + Path.Combine(_resultsFolder, LRR_FOLDER)); currentScenario.ResultDir = Path.Combine(_resultsFolder, LRR_FOLDER); ConsoleWriter.WriteLine("scenario result folder: " + currentScenario.ResultDir); //check if canceled or timedOut: if (_runCancelled()) { errorReason = Resources.GeneralTimedOut; return(false); } _scenarioEnded = false; ConsoleWriter.WriteLine(Resources.LrStartScenario); int ret = currentScenario.Start(); if (!currentScenario.ResultDir.Equals(Path.Combine(_resultsFolder, LRR_FOLDER))) { ConsoleWriter.WriteLine("controller failed to write to " + Path.Combine(_resultsFolder, LRR_FOLDER) + " setting result folder to " + currentScenario.ResultDir); _controller_result_dir = new DirectoryInfo(currentScenario.ResultDir).Name; ConsoleWriter.WriteLine("controller reult dir: " + _controller_result_dir); } if (ret != 0) { errorReason = string.Format(Resources.LrStartScenarioFail, scenario, ret); return(false); } //per scenario timeout stopwatch _stopWatch = Stopwatch.StartNew(); //wait for scenario to end: if (!waitForScenario(ref errorReason)) { //something went wrong during scenario execution, error reason set in errorReason string return(false); } else {//scenario has ended Console.WriteLine(string.Format(Resources.LrScenarioEnded, scenario, _stopWatch.Elapsed.Hours, _stopWatch.Elapsed.Minutes, _stopWatch.Elapsed.Seconds)); //collate results collateResults(); } } else { return(false); } return(true); }
public TestRunResults RunTest(TestInfo scenarioInf, ref string errorReason, RunCancelledDelegate runCancelled) { string scenarioPath = scenarioInf.TestPath; //prepare the instance that will contain test results for JUnit TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + scenarioPath); runDesc.TestType = TestType.LoadRunner.ToString(); _resultsFolder = Helper.GetTempDir(); //a directory with this name may already exist. try to delete it. if (Directory.Exists(_resultsFolder)) { try { // Directory.Delete(_resultsFolder, true); DirectoryInfo dir = new DirectoryInfo(_resultsFolder); dir.GetFiles().ToList().ForEach(file => file.Delete()); dir.GetDirectories().ToList().ForEach(subdir => subdir.Delete()); } catch (Exception) { Console.WriteLine(string.Format(Resources.CannotDeleteReportFolder, _resultsFolder)); } } else { try { Directory.CreateDirectory(_resultsFolder); } catch (Exception e) { errorReason = string.Format(Resources.FailedToCreateTempDirError, _resultsFolder); runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } } //create LRR folder: _controller_result_dir = Path.Combine(_resultsFolder, LRR_FOLDER); Directory.CreateDirectory(_controller_result_dir); //init result params runDesc.ErrorDesc = errorReason; runDesc.TestPath = scenarioPath; ConsoleWriter.WriteLine(runDesc.TestPath); runDesc.TestState = TestState.Unknown; if (!Helper.isLoadRunnerInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.LoadRunnerNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } //from here on, we may delegate runCancelled(). _runCancelled = runCancelled; //start scenario stop watch Stopwatch scenarioStopWatch = Stopwatch.StartNew(); //set state to running runDesc.TestState = TestState.Running; //and run the scenario bool res = runScenario(scenarioPath, ref errorReason, runCancelled); if (!res) { //runScenario failed. print the error and set test as failed ConsoleWriter.WriteErrLine(errorReason); runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; runDesc.Runtime = scenarioStopWatch.Elapsed; //and try to close the controller closeController(); return(runDesc); } else { try { ConsoleWriter.WriteLine(Resources.GeneralDoubleSeperator); runDesc.ReportLocation = _resultsFolder; ConsoleWriter.WriteLine(Resources.LrAnalysingResults); //close the controller, so Analysis can be opened ConsoleWriter.WriteLine("closing Controller"); closeController(); ConsoleWriter.WriteLine("Controller closed"); //generate report using Analysis: ConsoleWriter.WriteLine("calling analysis report generator"); generateAnalysisReport(runDesc); ConsoleWriter.WriteLine("analysis report generator finished"); //check for errors: if (File.Exists(Path.Combine(_resultsFolder, "errors.xml"))) { checkForErrors(); } ConsoleWriter.WriteLine(Resources.LRErrorsSummary); //count how many ignorable errors and how many fatal errors occured. int ignore = getErrorsCount(ERRORState.Ignore); int fatal = getErrorsCount(ERRORState.Error); runDesc.FatalErrors = fatal; ConsoleWriter.WriteLine(String.Format(Resources.LrErrorSummeryNum, ignore, fatal)); ConsoleWriter.WriteLine(""); if (_errors != null && _errors.Count > 0) { foreach (ERRORState state in Enum.GetValues(typeof(ERRORState))) { ConsoleWriter.WriteLine(printErrorSummary(state)); } } //if scenario ended with fatal errors, change test state if (fatal > 0) { ConsoleWriter.WriteErrLine(string.Format(Resources.LRTestFailDueToFatalErrors, fatal)); errorReason = buildErrorReasonForErrors(); runDesc.TestState = TestState.Failed; } else if (ignore > 0) { ConsoleWriter.WriteLine(string.Format(Resources.LRTestWarningDueToIgnoredErrors, ignore)); runDesc.HasWarnings = true; runDesc.TestState = TestState.Warning; } else { Console.WriteLine(Resources.LRTestPassed); runDesc.TestState = TestState.Passed; } } catch (Exception e) { ConsoleWriter.WriteException(Resources.LRExceptionInAnalysisRunner, e); runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.LRExceptionInAnalysisRunner; runDesc.Runtime = scenarioStopWatch.Elapsed; } //runDesc.ReportLocation = _resultsFolder; } runDesc.Runtime = scenarioStopWatch.Elapsed; if (!string.IsNullOrEmpty(errorReason)) { runDesc.ErrorDesc = errorReason; } KillController(); return(runDesc); }
/// <summary> /// Runs the provided test on all the environments. /// </summary> /// <param name="testInfo"> The test information. </param> /// <param name="errorReason"> failure reason </param> /// <param name="runCancelled"> delegate to RunCancelled </param> /// <returns> /// The run results for the current test. /// </returns> public TestRunResults RunTest(TestInfo testInfo, ref string errorReason, RunCancelledDelegate runCancelled) { // change the DCOM setting for qtp application Helper.ChangeDCOMSettingToInteractiveUser(); testInfo.ReportPath = testInfo.TestPath + @"\ParallelReport"; // this is to make sure that we do not overwrite the report // when we run the same test multiple times on the same build string resFolder = Helper.GetNextResFolder(testInfo.ReportPath, "Res"); var runResults = new TestRunResults { ReportLocation = testInfo.ReportPath, ErrorDesc = errorReason, TestState = TestState.Unknown, TestPath = testInfo.TestPath, TestType = TestType.ParallelRunner.ToString() }; // set the active test run ConsoleWriter.ActiveTestRun = runResults; if (!_canRun) { ConsoleWriter.WriteLine("Could not find parallel runner executable!"); errorReason = Resources.ParallelRunnerExecutableNotFound; runResults.TestState = TestState.Error; runResults.ErrorDesc = errorReason; return(runResults); } // Try to create the ParalleReport path try { Directory.CreateDirectory(runResults.ReportLocation); }catch (Exception) { errorReason = string.Format(Resources.FailedToCreateTempDirError, runResults.ReportLocation); runResults.TestState = TestState.Error; runResults.ErrorDesc = errorReason; Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runResults); } ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " => Using ParallelRunner to execute test: " + testInfo.TestPath); _runCancelled = runCancelled; // prepare the json file for the process var configFilePath = string.Empty; try { configFilePath = ParallelRunnerEnvironmentUtil.GetConfigFilePath(testInfo, _mcConnectionInfo, _environments); _configFiles.Add(configFilePath); }catch (ParallelRunnerConfigurationException ex) // invalid configuration { errorReason = ex.Message; runResults.ErrorDesc = errorReason; runResults.TestState = TestState.Error; return(runResults); } // Parallel runner argument "-c" for config path and "-o static" so that // the output from ParallelRunner is compatible with Jenkins var arguments = String.Format(ParallelRunnerArguments, configFilePath); // the test can be started now runResults.TestState = TestState.Running; var runTime = new Stopwatch(); runTime.Start(); string failureReason = null; runResults.ErrorDesc = null; // execute parallel runner and get the run result status int exitCode = ExecuteProcess(_parallelRunnerPath, arguments, ref failureReason); // set the status of the build based on the exit code RunResultsFromParallelRunnerExitCode(runResults, exitCode, failureReason, ref errorReason); // update the run time runResults.Runtime = runTime.Elapsed; // update the report location as the report should be // generated by now runResults.ReportLocation = resFolder; return(runResults); }
private bool runScenario(string scenario, ref string errorReason, RunCancelledDelegate runCancelled) { cleanENV(); ConsoleWriter.WriteLine(string.Format(Resources.LrInitScenario, scenario)); //start controller _engine = new LrEngine(); if (_engine == null) { errorReason = string.Format(Resources.LrFailToOpenController, scenario); return(false); } //try to register the end scenario event: _scenarioEndedEvent = false; try { _engine.Events.ScenarioEvents.OnScenarioEnded += ScenarioEvents_OnScenarioEnded; _scenarioEndedEvent = true; } catch (Exception e) { ConsoleWriter.WriteException(Resources.LrFailToRegisterEndScenarioEvent, e); _scenarioEndedEvent = false; } _engine.ShowMainWindow(0); #if DEBUG _engine.ShowMainWindow(1); #endif //pointer to the scenario object: LrScenario currentScenario = _engine.Scenario; //try to open the scenario and validate the scenario and connect to load generators if (openScenario(scenario, ref errorReason) && validateScenario(currentScenario, ref errorReason)) { //set the result dir: ConsoleWriter.WriteLine("setting scenario result folder to " + Path.Combine(_resultsFolder, LRR_FOLDER)); currentScenario.ResultDir = Path.Combine(_resultsFolder, LRR_FOLDER); ConsoleWriter.WriteLine("scenario result folder: " + currentScenario.ResultDir); //check if canceled or timedOut: if (_runCancelled()) { errorReason = Resources.GeneralTimedOut; return(false); } _scenarioEnded = false; ConsoleWriter.WriteLine(Resources.LrStartScenario); int ret = currentScenario.Start(); if (!currentScenario.ResultDir.Equals(Path.Combine(_resultsFolder, LRR_FOLDER))) { ConsoleWriter.WriteLine("controller failed to write to " + Path.Combine(_resultsFolder, LRR_FOLDER) + " setting result folder to " + currentScenario.ResultDir); _controller_result_dir = new DirectoryInfo(currentScenario.ResultDir).Name; ConsoleWriter.WriteLine("controller reult dir: " + _controller_result_dir); } if (ret != 0) { errorReason = string.Format(Resources.LrStartScenarioFail, scenario, ret); return(false); } //per scenario timeout stopwatch _stopWatch = Stopwatch.StartNew(); //wait for scenario to end: if (!waitForScenario(ref errorReason)) { //something went wrong during scenario execution, error reason set in errorReason string return(false); } else {//scenario has ended Console.WriteLine(string.Format(Resources.LrScenarioEnded, scenario, _stopWatch.Elapsed.Hours, _stopWatch.Elapsed.Minutes, _stopWatch.Elapsed.Seconds)); //collate results collateResults(); } } else { return(false); } return(true); }
public TestRunResults RunTest(TestInfo scenarioInf, ref string errorReason, RunCancelledDelegate runCancelled) { string scenarioPath = scenarioInf.TestPath; //prepare the instance that will contain test results for JUnit TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + scenarioPath); runDesc.TestType = TestType.LoadRunner.ToString(); _resultsFolder = Helper.GetTempDir(); //a directory with this name may already exist. try to delete it. if (Directory.Exists(_resultsFolder)) { try { // Directory.Delete(_resultsFolder, true); DirectoryInfo dir = new DirectoryInfo(_resultsFolder); dir.GetFiles().ToList().ForEach(file => file.Delete()); dir.GetDirectories().ToList().ForEach(subdir => subdir.Delete()); } catch (Exception) { Console.WriteLine(string.Format(Resources.CannotDeleteReportFolder, _resultsFolder)); } } else { try { Directory.CreateDirectory(_resultsFolder); } catch (Exception e) { errorReason = string.Format(Resources.FailedToCreateTempDirError, _resultsFolder); runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return runDesc; } } //create LRR folder: _controller_result_dir = Path.Combine(_resultsFolder, LRR_FOLDER); Directory.CreateDirectory(_controller_result_dir); //init result params runDesc.ErrorDesc = errorReason; runDesc.TestPath = scenarioPath; runDesc.TestState = TestState.Unknown; if (!Helper.isLoadRunnerInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.LoadRunnerNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return runDesc; } //from here on, we may delegate runCancelled(). _runCancelled = runCancelled; //start scenario stop watch Stopwatch scenarioStopWatch = Stopwatch.StartNew(); //set state to running runDesc.TestState = TestState.Running; //and run the scenario bool res = runScenario(scenarioPath, ref errorReason, runCancelled); if (!res) { //runScenario failed. print the error and set test as failed ConsoleWriter.WriteErrLine(errorReason); runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; runDesc.Runtime = scenarioStopWatch.Elapsed; //and try to close the controller closeController(); return runDesc; } else { try { ConsoleWriter.WriteLine(Resources.GeneralDoubleSeperator); runDesc.ReportLocation = _resultsFolder; ConsoleWriter.WriteLine(Resources.LrAnalysingResults); //close the controller, so Analysis can be opened ConsoleWriter.WriteLine("closing Controller"); closeController(); ConsoleWriter.WriteLine("Controller closed"); //generate report using Analysis: ConsoleWriter.WriteLine("calling analysis report generator"); generateAnalysisReport(runDesc); ConsoleWriter.WriteLine("analysis report generator finished"); //check for errors: if (File.Exists(Path.Combine(_resultsFolder, "errors.xml"))) { checkForErrors(); } ConsoleWriter.WriteLine(Resources.LRErrorsSummary); //count how many ignorable errors and how many fatal errors occured. int ignore = getErrorsCount(ERRORState.Ignore); int fatal = getErrorsCount(ERRORState.Error); ConsoleWriter.WriteLine(String.Format(Resources.LrErrorSummeryNum, ignore, fatal)); ConsoleWriter.WriteLine(""); if (_errors != null && _errors.Count > 0) { foreach (ERRORState state in Enum.GetValues(typeof(ERRORState))) { ConsoleWriter.WriteLine(printErrorSummary(state)); } } //if scenario ended with fatal errors, change test state if (fatal > 0) { ConsoleWriter.WriteErrLine(string.Format(Resources.LRTestFailDueToFatalErrors, fatal)); errorReason = buildErrorReasonForErrors(); runDesc.TestState = TestState.Failed; } else if (ignore > 0) { ConsoleWriter.WriteLine(string.Format(Resources.LRTestWarningDueToIgnoredErrors, ignore)); runDesc.HasWarnings = true; runDesc.TestState = TestState.Warning; } else { Console.WriteLine(Resources.LRTestPassed); runDesc.TestState = TestState.Passed; } } catch (Exception e) { ConsoleWriter.WriteException(Resources.LRExceptionInAnalysisRunner, e); runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.LRExceptionInAnalysisRunner; runDesc.Runtime = scenarioStopWatch.Elapsed; } //runDesc.ReportLocation = _resultsFolder; } runDesc.Runtime = scenarioStopWatch.Elapsed; if (!string.IsNullOrEmpty(errorReason)) runDesc.ErrorDesc = errorReason; closeController(); return runDesc; }
private bool runScenario(string scenario, ref string errorReason, RunCancelledDelegate runCancelled) { cleanENV(); ConsoleWriter.WriteLine(string.Format(Resources.LrInitScenario, scenario)); //start controller _engine = new LrEngine(); if (_engine == null) { errorReason = string.Format(Resources.LrFailToOpenController, scenario); return false; } //try to register the end scenario event: _scenarioEndedEvent = false; try { _engine.Events.ScenarioEvents.OnScenarioEnded += ScenarioEvents_OnScenarioEnded; _scenarioEndedEvent = true; } catch (Exception e) { ConsoleWriter.WriteException(Resources.LrFailToRegisterEndScenarioEvent, e); _scenarioEndedEvent = false; } _engine.ShowMainWindow(0); #if DEBUG _engine.ShowMainWindow(1); #endif //pointer to the scenario object: LrScenario currentScenario = _engine.Scenario; //try to open the scenario and validate the scenario and connect to load generators if (openScenario(scenario, ref errorReason) && validateScenario(currentScenario, ref errorReason)) { //set the result dir: ConsoleWriter.WriteLine("setting scenario result folder to " + Path.Combine(_resultsFolder, LRR_FOLDER)); currentScenario.ResultDir = Path.Combine(_resultsFolder, LRR_FOLDER); ConsoleWriter.WriteLine("scenario result folder: " + currentScenario.ResultDir); //check if canceled or timedOut: if (_runCancelled()) { errorReason = Resources.GeneralTimedOut; return false; } _scenarioEnded = false; ConsoleWriter.WriteLine(Resources.LrStartScenario); int ret = currentScenario.Start(); if (!currentScenario.ResultDir.Equals(Path.Combine(_resultsFolder, LRR_FOLDER))) { ConsoleWriter.WriteLine("controller failed to write to " + Path.Combine(_resultsFolder, LRR_FOLDER) + " setting result folder to " + currentScenario.ResultDir); _controller_result_dir = new DirectoryInfo(currentScenario.ResultDir).Name; ConsoleWriter.WriteLine("controller reult dir: " + _controller_result_dir); } if (ret != 0) { errorReason = string.Format(Resources.LrStartScenarioFail, scenario, ret); return false; } //per scenario timeout stopwatch _stopWatch = Stopwatch.StartNew(); //wait for scenario to end: if (!waitForScenario(ref errorReason)) { //something went wrong during scenario execution, error reason set in errorReason string return false; } else {//scenario has ended Console.WriteLine(string.Format(Resources.LrScenarioEnded, scenario,_stopWatch.Elapsed.Hours,_stopWatch.Elapsed.Minutes, _stopWatch.Elapsed.Seconds)); //collate results collateResults(); } } else { return false; } return true; }
/// <summary> /// Runs the provided test on all the environments. /// </summary> /// <param name="testInfo"> The test information. </param> /// <param name="errorReason"> failure reason </param> /// <param name="runCancelled"> delegate to RunCancelled </param> /// <returns> /// The run results for the current test. /// </returns> public TestRunResults RunTest(TestInfo testInfo, ref string errorReason, RunCancelledDelegate runCancelled) { ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running in parallel: " + testInfo.TestPath); if (string.IsNullOrWhiteSpace(testInfo.ReportPath)) { // maybe the report base directory is set, if so, // the report path for parallel runner shall be populated here if (!string.IsNullOrWhiteSpace(testInfo.ReportBaseDirectory)) { // "<report-base-dir>\<test-name>_ParallelReport" testInfo.ReportPath = Path.Combine(testInfo.ReportBaseDirectory, testInfo.TestName.Substring(testInfo.TestName.LastIndexOf('\\') + 1) + "_ParallelReport"); ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is generated under base directory: " + testInfo.ReportPath); } else { // neither ReportPath nor ReportBaseDirectory is given, use default report path: // "<TestPath>\ParallelReport" testInfo.ReportPath = testInfo.TestPath + @"\ParallelReport"; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is automatically generated: " + testInfo.ReportPath); } } else { ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is set explicitly: " + testInfo.ReportPath); } // this is to make sure that we do not overwrite the report // when we run the same test multiple times on the same build string resFolder = Helper.GetNextResFolder(testInfo.ReportPath, "Res"); var runResults = new TestRunResults { ReportLocation = testInfo.ReportPath, ErrorDesc = errorReason, TestState = TestState.Unknown, TestPath = testInfo.TestPath, TestType = TestType.ParallelRunner.ToString() }; // set the active test run ConsoleWriter.ActiveTestRun = runResults; if (!_canRun) { ConsoleWriter.WriteLine("Could not find parallel runner executable!"); errorReason = Resources.ParallelRunnerExecutableNotFound; runResults.TestState = TestState.Error; runResults.ErrorDesc = errorReason; return(runResults); } // change the DCOM setting for qtp application Helper.ChangeDCOMSettingToInteractiveUser(); // try to check if the UFT process already exists bool uftProcessExist = false; bool isNewInstance; using (Mutex m = new Mutex(true, "per_process_mutex_UFT", out isNewInstance)) { if (!isNewInstance) { uftProcessExist = true; } } // try to get qtp status via qtp automation object since the uft process exists if (uftProcessExist) { var type = Type.GetTypeFromProgID("Quicktest.Application"); var qtpApplication = Activator.CreateInstance(type) as QTObjectModelLib.Application; bool needKillUFTProcess = false; // status: Not launched / Ready / Busy / Running / Recording / Waiting / Paused string status = qtpApplication.GetStatus(); switch (status) { case "Not launched": if (uftProcessExist) { // UFT process exist but the status retrieved from qtp automation object is Not launched // it means the UFT is launched but not shown the main window yet // in which case it shall be considered as UFT is not used at all // so here can kill the UFT process to continue needKillUFTProcess = true; } break; case "Ready": case "Waiting": // UFT is launched but not running or recording, shall be considered as UFT is not used // so here can kill the UFT process to continue needKillUFTProcess = true; break; case "Busy": case "Running": case "Recording": case "Paused": // UFT is launched and somehow in use now, shouldn't kill UFT process // here make the test fail errorReason = Resources.UFT_Running; runResults.ErrorDesc = errorReason; runResults.TestState = TestState.Error; return(runResults); default: // by default, let the tool run test, the behavior might be unexpected break; } if (needKillUFTProcess) { Process[] procs = Process.GetProcessesByName("uft"); if (procs != null) { foreach (Process proc in procs) { proc.Kill(); } } } } // Try to create the ParalleReport path try { Directory.CreateDirectory(runResults.ReportLocation); } catch (Exception) { errorReason = string.Format(Resources.FailedToCreateTempDirError, runResults.ReportLocation); runResults.TestState = TestState.Error; runResults.ErrorDesc = errorReason; Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runResults); } ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " => Using ParallelRunner to execute test: " + testInfo.TestPath); _runCancelled = runCancelled; // prepare the json file for the process var configFilePath = string.Empty; try { configFilePath = ParallelRunnerEnvironmentUtil.GetConfigFilePath(testInfo, _mcConnectionInfo, _environments); _configFiles.Add(configFilePath); } catch (ParallelRunnerConfigurationException ex) // invalid configuration { errorReason = ex.Message; runResults.ErrorDesc = errorReason; runResults.TestState = TestState.Error; return(runResults); } // Parallel runner argument "-c" for config path and "-o static" so that // the output from ParallelRunner is compatible with Jenkins var arguments = String.Format(ParallelRunnerArguments, configFilePath); // the test can be started now runResults.TestState = TestState.Running; var runTime = new Stopwatch(); runTime.Start(); string failureReason = null; runResults.ErrorDesc = null; // execute parallel runner and get the run result status int exitCode = ExecuteProcess(_parallelRunnerPath, arguments, ref failureReason); // set the status of the build based on the exit code RunResultsFromParallelRunnerExitCode(runResults, exitCode, failureReason, ref errorReason); // update the run time runResults.Runtime = runTime.Elapsed; // update the report location as the report should be // generated by now runResults.ReportLocation = resFolder; return(runResults); }
/// <summary> /// runs the given test and returns resutls /// </summary> /// <param name="testPath"></param> /// <param name="errorReason"></param> /// <param name="runCanclled"></param> /// <returns></returns> public TestRunResults RunTest(string testPath, ref string errorReason, RunCancelledDelegate runCanclled) { TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testPath); runDesc.ReportLocation = testPath; runDesc.TestPath = testPath; runDesc.TestState = TestState.Unknown; _runCancelled = runCanclled; if (!Helper.IsQtpInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.GeneralQtpNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return runDesc; } try { ChangeDCOMSettingToInteractiveUser(); var type = Type.GetTypeFromProgID("Quicktest.Application"); lock (_lockObject) { _qtpApplication = Activator.CreateInstance(type) as Application; Version qtpVersion = Version.Parse(_qtpApplication.Version); if (qtpVersion.Equals(new Version(11,0))) { runDesc.ReportLocation = Path.Combine(testPath, "Report"); if (Directory.Exists(runDesc.ReportLocation)) { Directory.Delete(runDesc.ReportLocation, true); Directory.CreateDirectory(runDesc.ReportLocation); } } // Check for required Addins LoadNeededAddins(testPath); if (!_qtpApplication.Launched) { if (_runCancelled()) { QTPTestCleanup(); KillQtp(); runDesc.TestState = TestState.Error; return runDesc; } // Launch application after set Addins _qtpApplication.Launch(); _qtpApplication.Visible = false; } } } catch (Exception e) { errorReason = Resources.QtpNotLaunchedError; runDesc.TestState = TestState.Error; runDesc.ReportLocation = ""; runDesc.ErrorDesc = e.Message; return runDesc; } if (_qtpApplication.Test != null && _qtpApplication.Test.Modified) { var message = Resources.QtpNotLaunchedError; errorReason = message; runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return runDesc; } _qtpApplication.UseLicenseOfType(_useUFTLicense ? tagUnifiedLicenseType.qtUnifiedFunctionalTesting : tagUnifiedLicenseType.qtNonUnified); if (!HandleInputParameters(testPath, ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return runDesc; } GuiTestRunResult guiTestRunResult = ExecuteQTPRun(runDesc); runDesc.ReportLocation = guiTestRunResult.ReportPath; if (!guiTestRunResult.IsSuccess) { runDesc.TestState = TestState.Error; return runDesc; } if (!HandleOutputArguments(ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return runDesc; } QTPTestCleanup(); return runDesc; }
/// <summary> /// runs the given test and returns resutls /// </summary> /// <param name="testPath"></param> /// <param name="errorReason"></param> /// <param name="runCanclled"></param> /// <returns></returns> public TestRunResults RunTest(TestInfo testinf, ref string errorReason, RunCancelledDelegate runCanclled) { var testPath = testinf.TestPath; TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running test: " + testPath + " ..."); runDesc.TestPath = testPath; // check if the report path has been defined if (!string.IsNullOrWhiteSpace(testinf.ReportPath)) { runDesc.ReportLocation = Path.GetFullPath(testinf.ReportPath); ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is set explicitly: " + runDesc.ReportLocation); } else if (!String.IsNullOrEmpty(testinf.ReportBaseDirectory)) { testinf.ReportBaseDirectory = Path.GetFullPath(testinf.ReportBaseDirectory); if (!Helper.TrySetTestReportPath(runDesc, testinf, ref errorReason)) { return(runDesc); } ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is generated under base directory: " + runDesc.ReportLocation); } else { // default report location is the next available folder under test path // for example, "path\to\tests\GUITest1\Report123", the name "Report123" will also be used as the report name string reportBasePath = Path.GetFullPath(testPath); string testReportPath = Path.Combine(reportBasePath, "Report" + DateTime.Now.ToString("ddMMyyyyHHmmssfff")); int index = 0; while (index < int.MaxValue) { index++; string dir = Path.Combine(reportBasePath, "Report" + index.ToString()); if (!Directory.Exists(dir)) { testReportPath = dir; break; } } runDesc.ReportLocation = testReportPath; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is automatically generated: " + runDesc.ReportLocation); } runDesc.TestState = TestState.Unknown; _runCancelled = runCanclled; if (!Helper.IsQtpInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.GeneralQtpNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } string reason = string.Empty; if (!Helper.CanUftProcessStart(out reason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = reason; ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } try { ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " " + Properties.Resources.LaunchingTestingTool); ChangeDCOMSettingToInteractiveUser(); var type = Type.GetTypeFromProgID("Quicktest.Application"); lock (_lockObject) { // before creating qtp automation object which creates UFT process, // try to check if the UFT process already exists bool uftProcessExist = false; bool isNewInstance; using (Mutex m = new Mutex(true, "per_process_mutex_UFT", out isNewInstance)) { if (!isNewInstance) { uftProcessExist = true; } } // this will create UFT process _qtpApplication = Activator.CreateInstance(type) as Application; // try to get qtp status via qtp automation object // this might fail if UFT is launched and waiting for user input on addins manage window bool needKillUFTProcess = false; // status: Not launched / Ready / Busy / Running / Recording / Waiting / Paused string status = _qtpApplication.GetStatus(); switch (status) { case "Not launched": if (uftProcessExist) { // UFT process exist but the status retrieved from qtp automation object is Not launched // it means the UFT is launched but not shown the main window yet // in which case it shall be considered as UFT is not used at all // so here can kill the UFT process to continue needKillUFTProcess = true; } break; case "Ready": case "Waiting": // UFT is launched but not running or recording, shall be considered as UFT is not used // no need kill UFT process here since the qtp automation object can work properly break; case "Busy": case "Running": case "Recording": case "Paused": // UFT is launched and somehow in use now, shouldn't kill UFT process // here make the test fail errorReason = Resources.UFT_Running; runDesc.TestState = TestState.Error; runDesc.ReportLocation = ""; runDesc.ErrorDesc = errorReason; return(runDesc); default: // by default, let the tool run test, the behavior might be unexpected break; } if (needKillUFTProcess) { Process[] procs = Process.GetProcessesByName("uft"); if (procs != null) { foreach (Process proc in procs) { proc.Kill(); } } } Version qtpVersion = Version.Parse(_qtpApplication.Version); if (qtpVersion.Equals(new Version(11, 0))) { // use the defined report path if provided if (!string.IsNullOrWhiteSpace(testinf.ReportPath)) { runDesc.ReportLocation = Path.Combine(testinf.ReportPath, "Report"); } else if (!string.IsNullOrWhiteSpace(testinf.ReportBaseDirectory)) { runDesc.ReportLocation = Path.Combine(testinf.ReportBaseDirectory, "Report"); } else { runDesc.ReportLocation = Path.Combine(testPath, "Report"); } if (Directory.Exists(runDesc.ReportLocation)) { int lastIndex = runDesc.ReportLocation.IndexOf("\\"); var location = runDesc.ReportLocation.Substring(0, lastIndex); var name = runDesc.ReportLocation.Substring(lastIndex + 1); runDesc.ReportLocation = Helper.GetNextResFolder(location, name); Console.WriteLine("Report location is:" + runDesc.ReportLocation); Directory.CreateDirectory(runDesc.ReportLocation); } } // Check for required Addins LoadNeededAddins(testPath); // set Mc connection and other mobile info into rack if neccesary #region Mc connection and other mobile info // Mc Address, username and password if (!string.IsNullOrEmpty(_mcConnection.MobileHostAddress)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_HOST_ADDRESS, _mcConnection.MobileHostAddress); if (!string.IsNullOrEmpty(_mcConnection.MobileHostPort)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_HOST_PORT, _mcConnection.MobileHostPort); } } if (!string.IsNullOrEmpty(_mcConnection.MobileUserName)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_USER, _mcConnection.MobileUserName); } if (!string.IsNullOrEmpty(_mcConnection.MobileTenantId)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_TENANT, _mcConnection.MobileTenantId); } if (!string.IsNullOrEmpty(_mcConnection.MobilePassword)) { string encriptedMcPassword = WinUserNativeMethods.ProtectBSTRToBase64(_mcConnection.MobilePassword); if (encriptedMcPassword == null) { ConsoleWriter.WriteLine("ProtectBSTRToBase64 fail for mcPassword"); throw new Exception("ProtectBSTRToBase64 fail for mcPassword"); } _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PASSWORD, encriptedMcPassword); } // ssl and proxy info _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_USE_SSL, _mcConnection.MobileUseSSL); if (_mcConnection.MobileUseProxy == 1) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_USE_PROXY, _mcConnection.MobileUseProxy); _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_ADDRESS, _mcConnection.MobileProxySetting_Address); _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_PORT, _mcConnection.MobileProxySetting_Port); _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_AUTHENTICATION, _mcConnection.MobileProxySetting_Authentication); _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_USERNAME, _mcConnection.MobileProxySetting_UserName); string encriptedMcProxyPassword = WinUserNativeMethods.ProtectBSTRToBase64(_mcConnection.MobileProxySetting_Password); if (encriptedMcProxyPassword == null) { ConsoleWriter.WriteLine("ProtectBSTRToBase64 fail for mc proxy Password"); throw new Exception("ProtectBSTRToBase64 fail for mc proxy Password"); } _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_PROXY_SETTING_PASSWORD, encriptedMcProxyPassword); } // Mc info (device, app, launch and terminate data) if (!string.IsNullOrEmpty(_mobileInfo)) { _qtpApplication.TDPierToTulip.SetTestOptionsVal(MOBILE_INFO, _mobileInfo); } #endregion if (!_qtpApplication.Launched) { if (_runCancelled()) { QTPTestCleanup(); KillQtp(); runDesc.TestState = TestState.Error; return(runDesc); } // Launch application after set Addins _qtpApplication.Launch(); _qtpApplication.Visible = false; } } } catch (Exception e) { string errorMsg = e.Message; string errorStacktrace = string.IsNullOrWhiteSpace(e.StackTrace) ? string.Empty : e.StackTrace; errorReason = Resources.QtpNotLaunchedError + "\n" + string.Format(Resources.ExceptionDetails, errorMsg, errorStacktrace); if (e is SystemException) { errorReason += "\n" + Resources.QtpNotLaunchedError_PossibleSolution_RegModellib; } runDesc.TestState = TestState.Error; runDesc.ReportLocation = ""; runDesc.ErrorDesc = errorReason; return(runDesc); } if (_qtpApplication.Test != null && _qtpApplication.Test.Modified) { var message = Resources.QtpNotLaunchedError; errorReason = message; runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } _qtpApplication.UseLicenseOfType(_useUFTLicense ? tagUnifiedLicenseType.qtUnifiedFunctionalTesting : tagUnifiedLicenseType.qtNonUnified); Dictionary <string, object> paramList = testinf.GetParameterDictionaryForQTP(); if (!HandleInputParameters(testPath, ref errorReason, testinf.GetParameterDictionaryForQTP(), testinf)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } GuiTestRunResult guiTestRunResult = ExecuteQTPRun(runDesc); // consider backward compatibility, here move the report folder one outside // that is, after test run, the report file might be at "path\to\tests\GUITest1\Report123\Report\run_results.html" // here move the last directory "Report" one level outside, which is, "path\to\tests\GUITest1\Report123\run_results.html" // steps: // 1. move directory "path\to\tests\GUITest1\Report123" to "path\to\tests\GUITest1\tmp_ddMMyyyyHHmmssfff" string guiTestReportPath = guiTestRunResult.ReportPath; // guiTestReportPath: path\to\tests\GUITest1\Report123\Report string targetReportDir = Path.GetDirectoryName(guiTestReportPath); // reportDir: path\to\tests\GUITest1\Report123 string reportBaseDir = Path.GetDirectoryName(targetReportDir); // reportBaseDir: path\to\tests\GUITest1 string tmpDir = Path.Combine(reportBaseDir, "tmp_" + DateTime.Now.ToString("ddMMyyyyHHmmssfff")); // tmpDir: path\to\tests\GUITest1\tmp_ddMMyyyyHHmmssfff // 1.a) directory move may fail because UFT might still be writting report files, need retry const int maxMoveDirRetry = 30; int moveDirRetry = 0; bool dirMoved = false; do { try { Directory.Move(targetReportDir, tmpDir); dirMoved = true; break; } catch (IOException) { moveDirRetry++; if (moveDirRetry == 1) { ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + string.Format(" Report is not ready yet, wait up to {0} seconds ...", maxMoveDirRetry)); } Thread.Sleep(1000); } } while (moveDirRetry < maxMoveDirRetry); if (dirMoved) { // 2. move directory "path\to\tests\GUITest1\tmp_ddMMyyyyHHmmssfff\Report" to "path\to\tests\GUITest1\Report123" string tmpReportDir = Path.Combine(tmpDir, "Report"); // tmpReportDir: path\to\tests\GUITest1\tmp_ddMMyyyyHHmmssfff\Report Directory.Move(tmpReportDir, targetReportDir); // 3. delete the temp directory "path\to\test1\tmp_ddMMyyyyHHmmssfff" Directory.Delete(tmpDir, true); runDesc.ReportLocation = targetReportDir; } else { runDesc.ReportLocation = guiTestReportPath; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Warning: Report folder is still in use, leave it in: " + guiTestReportPath); } if (!guiTestRunResult.IsSuccess) { runDesc.TestState = TestState.Error; return(runDesc); } if (!HandleOutputArguments(ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } QTPTestCleanup(); return(runDesc); }
/// <summary> /// runs the given test and returns resutls /// </summary> /// <param name="testPath"></param> /// <param name="errorReason"></param> /// <param name="runCanclled"></param> /// <returns></returns> public TestRunResults RunTest(TestInfo testinf, ref string errorReason, RunCancelledDelegate runCanclled) { var testPath = testinf.TestPath; TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testPath); runDesc.ReportLocation = testPath; runDesc.TestPath = testPath; runDesc.TestState = TestState.Unknown; _runCancelled = runCanclled; if (!Helper.IsQtpInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.GeneralQtpNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } try { ChangeDCOMSettingToInteractiveUser(); var type = Type.GetTypeFromProgID("Quicktest.Application"); lock (_lockObject) { _qtpApplication = Activator.CreateInstance(type) as Application; Version qtpVersion = Version.Parse(_qtpApplication.Version); if (qtpVersion.Equals(new Version(11, 0))) { runDesc.ReportLocation = Path.Combine(testPath, "Report"); if (Directory.Exists(runDesc.ReportLocation)) { Directory.Delete(runDesc.ReportLocation, true); Directory.CreateDirectory(runDesc.ReportLocation); } } // Check for required Addins LoadNeededAddins(testPath); if (!_qtpApplication.Launched) { if (_runCancelled()) { QTPTestCleanup(); KillQtp(); runDesc.TestState = TestState.Error; return(runDesc); } // Launch application after set Addins _qtpApplication.Launch(); _qtpApplication.Visible = false; } } } catch (Exception e) { errorReason = Resources.QtpNotLaunchedError; runDesc.TestState = TestState.Error; runDesc.ReportLocation = ""; runDesc.ErrorDesc = e.Message; return(runDesc); } if (_qtpApplication.Test != null && _qtpApplication.Test.Modified) { var message = Resources.QtpNotLaunchedError; errorReason = message; runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } _qtpApplication.UseLicenseOfType(_useUFTLicense ? tagUnifiedLicenseType.qtUnifiedFunctionalTesting : tagUnifiedLicenseType.qtNonUnified); if (!HandleInputParameters(testPath, ref errorReason, testinf.GetParameterDictionaryForQTP())) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } GuiTestRunResult guiTestRunResult = ExecuteQTPRun(runDesc); runDesc.ReportLocation = guiTestRunResult.ReportPath; if (!guiTestRunResult.IsSuccess) { runDesc.TestState = TestState.Error; return(runDesc); } if (!HandleOutputArguments(ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; return(runDesc); } QTPTestCleanup(); return(runDesc); }
/// <summary> /// runs the given test /// </summary> /// <param name="testinf"></param> /// <param name="errorReason"></param> /// <param name="runCancelled">cancellation delegate, holds the function that checks cancellation</param> /// <returns></returns> public TestRunResults RunTest(TestInfo testinf, ref string errorReason, RunCancelledDelegate runCancelled) { TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testinf.TestPath); runDesc.TestPath = testinf.TestPath; // default report location is the test path runDesc.ReportLocation = testinf.TestPath; // check if the report path has been defined if (!String.IsNullOrEmpty(testinf.ReportPath)) { if (!Helper.TrySetTestReportPath(runDesc, testinf, ref errorReason)) { return(runDesc); } } runDesc.ErrorDesc = errorReason; runDesc.TestState = TestState.Unknown; if (!Helper.IsServiceTestInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.LauncherStNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } _runCancelled = runCancelled; if (!_stCanRun) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; return(runDesc); } string fileName = Path.Combine(_stExecuterPath, STRunnerName); if (!File.Exists(fileName)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; ConsoleWriter.WriteErrLine(Resources.STExecuterNotFound); return(runDesc); } //write the input parameter xml file for the API test string paramFileName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 10); string tempPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestParams"); Directory.CreateDirectory(tempPath); string paramsFilePath = Path.Combine(tempPath, "params" + paramFileName + ".xml"); string paramFileContent = testinf.GenerateAPITestXmlForTest(); string argumentString = ""; if (!string.IsNullOrWhiteSpace(paramFileContent)) { File.WriteAllText(paramsFilePath, paramFileContent); argumentString = String.Format("{0} \"{1}\" {2} \"{3}\" {4} \"{5}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation, STRunnerInputParamsArg, paramsFilePath); } else { argumentString = String.Format("{0} \"{1}\" {2} \"{3}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation); } Stopwatch s = Stopwatch.StartNew(); runDesc.TestState = TestState.Running; if (!ExecuteProcess(fileName, argumentString, ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; } else { runDesc.ReportLocation = Path.Combine(runDesc.ReportLocation, "Report"); if (!File.Exists(Path.Combine(runDesc.ReportLocation, "Results.xml")) && !File.Exists(Path.Combine(runDesc.ReportLocation, "run_results.html"))) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = "No Results.xml or run_results.html file found"; } } //File.Delete(paramsFilePath); runDesc.Runtime = s.Elapsed; return(runDesc); }
/// <summary> /// runs the given test /// </summary> /// <param name="testinf"></param> /// <param name="errorReason"></param> /// <param name="runCancelled">cancellation delegate, holds the function that checks cancellation</param> /// <returns></returns> public TestRunResults RunTest(TestInfo testinf, ref string errorReason, RunCancelledDelegate runCancelled) { TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testinf.TestPath); runDesc.ReportLocation = Helper.CreateTempDir(); runDesc.ErrorDesc = errorReason; runDesc.TestPath = testinf.TestPath; runDesc.TestState = TestState.Unknown; if (!Helper.IsServiceTestInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.LauncherStNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } _runCancelled = runCancelled; if (!_stCanRun) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; return(runDesc); } string fileName = Path.Combine(_stExecuterPath, STRunnerName); if (!File.Exists(fileName)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; ConsoleWriter.WriteErrLine(Resources.STExecuterNotFound); return(runDesc); } //write the input parameter xml file for the API test string paramsFile = Path.GetTempFileName(); string paramFileContent = testinf.GenerateAPITestXmlForTest(); string argumentString = ""; if (!string.IsNullOrWhiteSpace(paramFileContent)) { File.WriteAllText(paramsFile, paramFileContent); argumentString = String.Format("{0} \"{1}\" {2} \"{3}\" {4} \"{5}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation, STRunnerInputParamsArg, paramsFile); } else { argumentString = String.Format("{0} \"{1}\" {2} \"{3}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation); } Stopwatch s = Stopwatch.StartNew(); runDesc.TestState = TestState.Running; if (!ExecuteProcess(fileName, argumentString, ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; } else { runDesc.ReportLocation = Path.Combine(runDesc.ReportLocation, "Report"); if (!File.Exists(Path.Combine(runDesc.ReportLocation, "Results.xml"))) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = "No Results.xml file found"; } } runDesc.Runtime = s.Elapsed; return(runDesc); }
/// <summary> /// runs the given test /// </summary> /// <param name="testinf"></param> /// <param name="errorReason"></param> /// <param name="runCancelled">cancellation delegate, holds the function that checks cancellation</param> /// <returns></returns> public TestRunResults RunTest(TestInfo testinf, ref string errorReason, RunCancelledDelegate runCancelled) { TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testinf.TestPath); runDesc.TestPath = testinf.TestPath; // check if the report path has been defined if (!string.IsNullOrWhiteSpace(testinf.ReportPath)) { runDesc.ReportLocation = testinf.ReportPath; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is set explicitly: " + runDesc.ReportLocation); } else if (!String.IsNullOrEmpty(testinf.ReportBaseDirectory)) { if (!Helper.TrySetTestReportPath(runDesc, testinf, ref errorReason)) { return(runDesc); } ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is generated under base directory: " + runDesc.ReportLocation); } else { // default report location is the next available folder under test path // for example, "path\to\tests\APITest\Report123", the name "Report123" will also be used as the report name string reportBasePath = testinf.TestPath; string testReportPath = Path.Combine(reportBasePath, "Report" + DateTime.Now.ToString("ddMMyyyyHHmmssfff")); int index = 0; while (index < int.MaxValue) { index++; string dir = Path.Combine(reportBasePath, "Report" + index.ToString()); if (!Directory.Exists(dir)) { testReportPath = dir; break; } } runDesc.ReportLocation = testReportPath; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is automatically generated: " + runDesc.ReportLocation); } runDesc.ErrorDesc = errorReason; runDesc.TestState = TestState.Unknown; if (!Helper.IsServiceTestInstalled()) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = string.Format(Resources.LauncherStNotInstalled, System.Environment.MachineName); ConsoleWriter.WriteErrLine(runDesc.ErrorDesc); Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed; return(runDesc); } _runCancelled = runCancelled; if (!_stCanRun) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; return(runDesc); } string fileName = Path.Combine(_stExecuterPath, STRunnerName); if (!File.Exists(fileName)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = Resources.STExecuterNotFound; ConsoleWriter.WriteErrLine(Resources.STExecuterNotFound); return(runDesc); } //write the input parameter xml file for the API test string paramFileName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 10); string tempPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestParams"); Directory.CreateDirectory(tempPath); string paramsFilePath = Path.Combine(tempPath, "params" + paramFileName + ".xml"); string paramFileContent = testinf.GenerateAPITestXmlForTest(); string argumentString = ""; if (!string.IsNullOrWhiteSpace(paramFileContent)) { File.WriteAllText(paramsFilePath, paramFileContent); argumentString = String.Format("{0} \"{1}\" {2} \"{3}\" {4} \"{5}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation, STRunnerInputParamsArg, paramsFilePath); } else { argumentString = String.Format("{0} \"{1}\" {2} \"{3}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation); } Stopwatch s = Stopwatch.StartNew(); runDesc.TestState = TestState.Running; if (!ExecuteProcess(fileName, argumentString, ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; } else { // consider backward compatibility, here move the report folder one outside // that is, after test run, the report file might be at "path\to\tests\APITest1\Report123\Report\run_results.html" // here move the last directory "Report" one level outside, which is, "path\to\tests\APITest1\Report123\run_results.html" string apiTestReportPath = Path.Combine(runDesc.ReportLocation, "Report"); // apiTestReportPath: path\to\tests\APITest1\Report123\Report string targetReportDir = Path.GetDirectoryName(apiTestReportPath); // reportDir: path\to\tests\APITest1\Report123 string reportBaseDir = Path.GetDirectoryName(targetReportDir); // reportBaseDir: path\to\tests\APITest1 string tmpDir = Path.Combine(reportBaseDir, "tmp_" + DateTime.Now.ToString("ddMMyyyyHHmmssfff")); // tmpDir: path\to\tests\APITest1\tmp_ddMMyyyyHHmmssfff string tmpReportDir = Path.Combine(tmpDir, "Report"); // tmpReportDir: path\to\tests\APITest1\tmp_ddMMyyyyHHmmssfff\Report // since some files might not be closed yet, move the report folder might fail // so here will try a few times to move folder and let it as is (not moved) if still failed after several retry bool moveSuccess = false; string lastMoveError = string.Empty; int retry = 10; while (retry >= 0) { try { // steps: // 1. move directory "path\to\tests\APITest1\Report123" to "path\to\tests\APITest1\tmp_ddMMyyyyHHmmssfff" Directory.Move(targetReportDir, tmpDir); // 2. move directory "path\to\tests\APITest1\tmp_ddMMyyyyHHmmssfff\Report" to "path\to\tests\APITest1\Report123" Directory.Move(tmpReportDir, targetReportDir); // 3. delete empty directory "path\to\test1\tmp_ddMMyyyyHHmmssfff" Directory.Delete(tmpDir, true); // 4. update report location runDesc.ReportLocation = targetReportDir; moveSuccess = true; break; } catch (Exception ex) { lastMoveError = ex.Message; retry--; System.Threading.Thread.Sleep(500); } } if (!moveSuccess) { ConsoleWriter.WriteLine("Warning: Failed to change the report folder structure. " + lastMoveError); } if (!File.Exists(Path.Combine(runDesc.ReportLocation, "Results.xml")) && !File.Exists(Path.Combine(runDesc.ReportLocation, "run_results.html"))) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = "No Results.xml or run_results.html file found"; } } //File.Delete(paramsFilePath); runDesc.Runtime = s.Elapsed; return(runDesc); }