/// <summary> /// This method handles the migration of Manual TestCase /// </summary> /// <param name="filePath">File Path of the ManualTestCase Excel sheet.</param> public void ProcessManualTestCaseFile(string filePath) { //ClosedXML has been used here to read the excel files. The library can be found in Tosca Installation Directory at '%TRICENTIS_HOME%\ToscaCommander'. //Alternatively, Microsoft.Office.Interop.Excel library or other third-party library can also be used. XLWorkbook workBook = new XLWorkbook(filePath); foreach (IXLWorksheet sheet in workBook.Worksheets) { IXLRange usedRange = sheet.RangeUsed(); int testCaseId = 0; int testStepId = 0; for (int row = 2; row <= usedRange.RowCount(); row++) { for (int column = 1; column <= usedRange.ColumnCount(); column++) { string cellValue = usedRange.Row(row).Cell(column).Value.ToString(); if (!string.IsNullOrEmpty(cellValue)) { switch (usedRange.Row(1).Cell(column).Value.ToString()) { case "TestCase": //Creates TestCase testCaseId = Builder.CreateTestCase(cellValue, Definition.TestCasesFolderId); break; case "Action": //Creates ManualTestStep testStepId = Builder.CreateManualTestStep(cellValue, testCaseId, null); break; case "Input Parameter": string value = string.IsNullOrEmpty(usedRange.Row(row).Cell(column + 1).Value.ToString()) ? "" : usedRange.Row(row).Cell(column + 1).Value.ToString(); //Creates ManualTestStepValue with ActionMode as Input Builder.CreateManualTestStepValue(cellValue, testStepId, value, ActionMode.Input.ToString(), null); break; case "Expected Result": //Creates ManualTestStepValue with ActionMode as Verify Builder.CreateManualTestStepValue(cellValue, testStepId, "", ActionMode.Verify.ToString(), null); break; } } } } } }
/// <summary> /// This method migrates the TestCase excel files. /// </summary> /// <param name="filepath">File path of the TestCase excel.</param> internal void ProcessTestScriptFile(string filepath) { //ClosedXML has been used here to read the excel files. The library can be found in Tosca Installation Directory at '%TRICENTIS_HOME%\ToscaCommander'. //Alternatively, Microsoft.Office.Interop.Excel library or other third-party library can also be used. XLWorkbook workbook = new XLWorkbook(filepath); foreach (IXLWorksheet sheet in workbook.Worksheets) { var xlRange = sheet.RangeUsed(); int pagenumber = 1; //Builder object provides all the methods to create Tosca Business Objects. Here we create a TestCase. Also, Definition object provide the root folder IDs for import. int testCaseId = builder.CreateTestCase(sheet.Name, definition.TestCasesFolderId); int moduleId = 0; int testStepId = 0; bool newModuleRequired = true; for (int row = 2; row <= xlRange.RowCount(); row++) { string keyword = null, locatorType = null, locatorValue = null, data = null; for (int column = 1; column <= xlRange.ColumnCount(); column++) { string cellValue = xlRange.Row(row).Cell(column).Value.ToString(); switch (xlRange.Row(1).Cell(column).Value.ToString()) { case "FunctionKeyword": keyword = cellValue; break; case "Locator Type": locatorType = cellValue; break; case "Locator Value": locatorValue = cellValue; break; case "Test Data": data = cellValue; break; } } int moduleAttributeId = 0; if (keyword == "enter_URL") { //Creates SpecialExecutionTask (The 'Open URL' module from Standard Subset is reused here). moduleId = builder.CreateSpecialExecutionTask("Open URL", definition.ModulesFolderId, "Framework", "OpenUrl"); testStepId = builder.CreateXTestStepFromXModule("Open URL", moduleId, testCaseId); moduleAttributeId = builder.CreateSpecialExecutionTaskAttribute("Url", moduleId); builder.SetXTestStepValue(data, testStepId, moduleAttributeId, null); continue; } if (keyword == "close_Window") { //Creates SpecialExecutionTask (The 'Window Operation' module from Standard Subset is reused here). moduleId = builder.CreateSpecialExecutionTask("TBox Window Operation", definition.ModulesFolderId, "Framework", "WindowOperation"); testStepId = builder.CreateXTestStepFromXModule("Close Window", moduleId, testCaseId); moduleAttributeId = builder.CreateSpecialExecutionTaskAttribute("Caption", moduleId); builder.SetXTestStepValue(data + "*", testStepId, moduleAttributeId, null); moduleAttributeId = builder.CreateSpecialExecutionTaskAttribute("Operation", moduleId); builder.SetXTestStepValue("Close", testStepId, moduleAttributeId, null); continue; } switch (keyword) { case "click_On_Button": if (moduleId == 0 || newModuleRequired) { moduleId = builder.CreateXModule("Page" + pagenumber, definition.ModulesFolderId, new Dictionary <string, string> { { "Title", "*" } }); testStepId = builder.CreateXTestStepFromXModule("Page" + pagenumber, moduleId, testCaseId); newModuleRequired = false; } moduleAttributeId = builder.CreateXModuleAttribute(locatorValue, "Button", ActionMode.Input.ToString(), moduleId, new Dictionary <string, string> { { GetToscaType(locatorType), locatorValue } }); builder.SetXTestStepValue("{CLICK}", testStepId, moduleAttributeId, ActionMode.Input.ToString()); newModuleRequired = true; ++pagenumber; break; case "select": if (moduleId == 0 || newModuleRequired) { moduleId = builder.CreateXModule("Page" + pagenumber, definition.ModulesFolderId, new Dictionary <string, string> { { "Title", "*" } }); testStepId = builder.CreateXTestStepFromXModule("Page" + pagenumber, moduleId, testCaseId); newModuleRequired = false; } moduleAttributeId = builder.CreateXModuleAttribute(locatorValue, "ComboBox", ActionMode.Input.ToString(), moduleId, new Dictionary <string, string> { { GetToscaType(locatorType), locatorValue } }); builder.SetXTestStepValue(data, testStepId, moduleAttributeId, ActionMode.Input.ToString()); break; case "enter_Text": if (moduleId == 0 || newModuleRequired) { moduleId = builder.CreateXModule("Page" + pagenumber, definition.ModulesFolderId, new Dictionary <string, string> { { "Title", "*" } }); testStepId = builder.CreateXTestStepFromXModule("Page" + pagenumber, moduleId, testCaseId); newModuleRequired = false; } moduleAttributeId = builder.CreateXModuleAttribute(locatorValue, "TextBox", ActionMode.Input.ToString(), moduleId, new Dictionary <string, string> { { GetToscaType(locatorType), locatorValue } }); builder.SetXTestStepValue(data, testStepId, moduleAttributeId, ActionMode.Input.ToString()); break; } } } }