/// <summary>
/// creates instance of the runner given a source.
/// </summary>
/// <param name="sources"></param>
/// <param name="timeout"></param>
/// <param name="scriptRtsSet"></param>
/// <param name="reportPath">The report base directory for all running tests.</param>
/// <param name="controllerPollingInterval"></param>
/// <param name="perScenarioTimeOutMinutes"></param>
/// <param name="ignoreErrorStrings"></param>
/// <param name="jenkinsEnvVariables"></param>
/// <param name="mcConnection"></param>
/// <param name="mobileInfo"></param>
/// <param name="parallelRunnerEnvironments"></param>
/// <param name="displayController"></param>
/// <param name="analysisTemplate"></param>
/// <param name="summaryDataLogger"></param>
/// <param name="useUftLicense"></param>
public FileSystemTestsRunner(List <TestData> sources,
TimeSpan timeout,
int controllerPollingInterval,
TimeSpan perScenarioTimeOutMinutes,
List <string> ignoreErrorStrings,
Dictionary <string, string> jenkinsEnvVariables,
McConnectionInfo mcConnection,
string mobileInfo,
Dictionary <string, List <string> > parallelRunnerEnvironments,
bool displayController,
string analysisTemplate,
SummaryDataLogger summaryDataLogger,
List <ScriptRTSModel> scriptRtsSet,
string reportPath,
bool useUftLicense = false)
{
_jenkinsEnvVariables = jenkinsEnvVariables;
//search if we have any testing tools installed
if (!Helper.IsTestingToolsInstalled(TestStorageType.FileSystem))
{
ConsoleWriter.WriteErrLine(string.Format(Resources.FileSystemTestsRunner_No_HP_testing_tool_is_installed_on, System.Environment.MachineName));
Environment.Exit((int)Launcher.ExitCodeEnum.Failed);
}
_timeout = timeout;
ConsoleWriter.WriteLine("FileSystemTestRunner timeout is " + _timeout);
_stopwatch = Stopwatch.StartNew();
_pollingInterval = controllerPollingInterval;
_perScenarioTimeOutMinutes = perScenarioTimeOutMinutes;
_ignoreErrorStrings = ignoreErrorStrings;
_useUFTLicense = useUftLicense;
_displayController = displayController;
_analysisTemplate = analysisTemplate;
_summaryDataLogger = summaryDataLogger;
_scriptRTSSet = scriptRtsSet;
_tests = new List <TestInfo>();
_mcConnection = mcConnection;
_mobileInfoForAllGuiTests = mobileInfo;
_parallelRunnerEnvironments = parallelRunnerEnvironments;
if (!string.IsNullOrWhiteSpace(_mcConnection.MobileHostAddress))
{
ConsoleWriter.WriteLine("UFT Mobile connection info is - " + _mcConnection.ToString());
}
if (reportPath != null)
{
ConsoleWriter.WriteLine("Results base directory (for all tests) is: " + reportPath);
}
//go over all sources, and create a list of all tests
foreach (TestData source in sources)
{
List <TestInfo> testGroup = new List <TestInfo>();
try
{
//--handle directories which contain test subdirectories (recursively)
if (Helper.IsDirectory(source.Tests))
{
var testsLocations = Helper.GetTestsLocations(source.Tests);
foreach (var loc in testsLocations)
{
var test = new TestInfo(loc, loc, source.Tests, source.Id)
{
ReportPath = source.ReportPath
};
testGroup.Add(test);
}
}
//--handle mtb files (which contain links to tests)
else
//file might be LoadRunner scenario or
//mtb file (which contain links to tests)
//other files are dropped
{
testGroup = new List <TestInfo>();
FileInfo fi = new FileInfo(source.Tests);
if (fi.Extension == Helper.LoadRunnerFileExtention)
{
testGroup.Add(new TestInfo(source.Tests, source.Tests, source.Tests, source.Id)
{
ReportPath = source.ReportPath
});
}
else if (fi.Extension == ".mtb")
//if (source.TrimEnd().EndsWith(".mtb", StringComparison.CurrentCultureIgnoreCase))
{
MtbManager manager = new MtbManager();
var paths = manager.Parse(source.Tests);
foreach (var p in paths)
{
testGroup.Add(new TestInfo(p, p, source.Tests, source.Id));
}
}
else if (fi.Extension == ".mtbx")
{
testGroup = MtbxManager.Parse(source.Tests, _jenkinsEnvVariables, source.Tests);
// set the test Id for each test from the group
// this is important for parallel runner
foreach (var testInfo in testGroup)
{
testInfo.TestId = source.Id;
}
}
}
}
catch (Exception)
{
testGroup = new List <TestInfo>();
}
//--handle single test dir, add it with no group
if (testGroup.Count == 1)
{
testGroup[0].TestGroup = "Test group";
}
_tests.AddRange(testGroup);
}
if (_tests == null || _tests.Count == 0)
{
ConsoleWriter.WriteLine(Resources.FsRunnerNoValidTests);
Environment.Exit((int)Launcher.ExitCodeEnum.Failed);
}
// if a custom path was provided,set the custom report path for all the valid tests(this will overwrite the default location)
if (reportPath != null)
{
foreach (TestInfo t in _tests)
{
if (string.IsNullOrWhiteSpace(t.ReportBaseDirectory))
{
t.ReportBaseDirectory = reportPath;
}
}
}
ConsoleWriter.WriteLine(string.Format(Resources.FsRunnerTestsFound, _tests.Count));
foreach (var test in _tests)
{
ConsoleWriter.WriteLine("" + test.TestName);
if (parallelRunnerEnvironments.ContainsKey(test.TestId))
{
parallelRunnerEnvironments[test.TestId].ForEach(
env => ConsoleWriter.WriteLine(" " + env));
}
}
ConsoleWriter.WriteLine(Resources.GeneralDoubleSeperator);
}