public QtestTestSuite ImportTestSetData(QtestTestSuite TS) { ConnectALMServer(); testrunApi = new QTestApi.TestrunApi(connObj.Configuration); testcaseApi = new QTestApi.TestcaseApi(connObj.Configuration); QTestApiModel.ParameterPostQueryResponse existedParameters = null; try { QTestApi.ParametersApi parametersApi = new QTestApi.ParametersApi(ALMCore.DefaultAlmConfig.ALMUserName, ALMCore.DefaultAlmConfig.ALMPassword, connObj.Configuration); existedParameters = parametersApi.GetAllParameters((long)Convert.ToInt32(ALMCore.DefaultAlmConfig.ALMProjectKey)); } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); } List <QTestApiModel.TestRunWithCustomFieldResource> testRunList = testrunApi.GetOf((long)Convert.ToInt32(ALMCore.DefaultAlmConfig.ALMProjectKey), (long)Convert.ToInt32(TS.ID), "test-suite"); foreach (QTestApiModel.TestRunWithCustomFieldResource testRun in testRunList) { QTestApiModel.TestRunWithCustomFieldResource testRunCurrent = testrunApi.Get((long)Convert.ToInt32(ALMCore.DefaultAlmConfig.ALMProjectKey), testRun.Id, "testcase.teststep"); QtestTest test = GetQtestTest(testRun.TestCase.Id, existedParameters, testRunCurrent.TestCase); test.Runs = new List <QtestTestRun>(); test.Runs.Add(new QtestTestRun(testRun.Id.ToString(), testRun.Name, testRun.Properties[0].ToString(), testRun.CreatorId.ToString())); TS.Tests.Add(test); } return(TS); }
public QtestTest GetQtestTest(long?testID, QTestApiModel.ParameterPostQueryResponse existedParameters = null, QTestApiModel.TestCaseWithCustomFieldResource testCase = null) { testcaseApi = new QTestApi.TestcaseApi(connObj.Configuration); if (testCase == null) { testCase = testcaseApi.GetTestCase((long)Convert.ToInt32(ALMCore.DefaultAlmConfig.ALMProjectKey), testID); } QtestTest test = new QtestTest(); test.Description = testCase.Description; test.TestName = testCase.Name; test.TestID = testCase.Id.ToString(); foreach (QTestApiModel.TestStepResource testStep in testCase.TestSteps) { if (testStep.CalledTestCaseId != null) { QTestApiModel.TestCaseWithCustomFieldResource calledTestCase = testcaseApi.GetTestCase((long)Convert.ToInt32(ALMCore.DefaultAlmConfig.ALMProjectKey), testStep.CalledTestCaseId); calledTestCase.TestSteps.ForEach(z => test.Steps.Add(new QtestTestStep(z.Id.ToString(), StripHTML(z.Description), StripHTML(z.Expected), testStep.CalledTestCaseId.ToString()))); } else { string stepName = testStep.Description; string stepDesc = testStep.Description; if (testStep.Description.Contains("=>")) { string[] activityData = testStep.Description.Split(new[] { "=>" }, StringSplitOptions.None); stepName = activityData[0]; stepDesc = activityData[1]; } QtestTestStep newStep = new QtestTestStep(testStep.Id.ToString(), stepDesc, testStep.Expected, null, stepName); if ((testStep.ParameterValues != null) && (testStep.ParameterValues.Count > 0) && (testStep.ParameterValues[0] != null)) { if (existedParameters != null) { if (testStep.RootCalledTestCaseId != null) { QTestApiModel.ParameterModel currentParameter = existedParameters.Items.Where(z => z.TcIds.Contains(testStep.RootCalledTestCaseId) && z.Values.Contains(testStep.ParameterValues[0])).FirstOrDefault(); newStep.Params = new QtestTestParameter(); newStep.Params.Value = testStep.ParameterValues[0]; newStep.Params.Values = currentParameter.Values.Split(',').ToList(); newStep.Params.Name = currentParameter.Description; } } } test.Steps.Add(newStep); } } return(test); }