public bool GenerateRanorexProject(List <IElement> listRootElements, List <SpecScreen> screensExpanded, string repoFilePath, string folderOutPath, string appPath, MyLog myLog) { string tempFolderPath = Utils.CreateTempFolder(PROJECT_NAME + "_" + DateTime.Now.ToString("yyMMdd_HHmmss")); ZipFile.ExtractToDirectory(PROJECT_TEMPLATE_PATH, tempFolderPath); string projectTempFolder = Path.Combine(tempFolderPath, PROJECT_NAME); // generate scripts Tuple <Dictionary <string, string>, List <string> > pair = null; if (screensExpanded != null && screensExpanded.Count > 0) { RanorexScriptsGeneration scriptsGeneration = new RanorexScriptsGeneration(); pair = scriptsGeneration.Generate( screensExpanded, projectTempFolder, null, null, appPath, PROJECT_NAME + REPOSITORY, PROJECT_NAME, INSTANCE, myLog, "repo"); if (pair == null) { myLog.Error("An error occured when generating C# scripts"); return(false); } } RanorexSolutionGeneration gen = new RanorexSolutionGeneration(); bool rGenCheck = gen.Generate(repoFilePath, folderOutPath, tempFolderPath, projectTempFolder, pair?.Item1, pair?.Item2, appPath, myLog); if (!rGenCheck) { myLog.Error("An error occured when generating Ranorex project"); return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="projectFolderPath">MyTestProject_180529_163316\MyTestProject</param> /// <param name="mapFilesAndIds"></param> /// <param name="myLog"></param> /// <returns></returns> public bool Modify(string projectFolderPath, Dictionary <string, string> mapFilesAndIds, List <string> otherFilesRelativePath, MyLog myLog) { List <DirectoryInfo> listFolders = new List <DirectoryInfo>(); List <string> listTestIds = new List <string>(); List <FileInfo> listCsFiles = new List <FileInfo>(); foreach (KeyValuePair <string, string> pair in mapFilesAndIds) { string filePath = pair.Key; string id = pair.Value; FileInfo file = new FileInfo(Path.Combine(projectFolderPath, filePath)); listCsFiles.Add(file); DirectoryInfo folder = file.Directory; if (listFolders.FirstOrDefault(ele => ele.FullName.Equals(folder.FullName)) == null) { listFolders.Add(folder); } listTestIds.Add(id); } string csProjFilePath = SearchCsProjFilePath(projectFolderPath); string rxtstFilePath = SearchRxtstFilePath(projectFolderPath); if (csProjFilePath == null || rxtstFilePath == null) { myLog.Error("An error occured when generating project, exit!"); return(false); } ModifyCsProjNode(csProjFilePath, mapFilesAndIds, otherFilesRelativePath); ModifyRxtstNode(rxtstFilePath, listFolders, listCsFiles, listTestIds); return(true); }
public static void LogError(string expression, string screenName, int scId, MyLog myLog, string node = null) { string log = "[Error] Expression: " + expression + " at sheet " + screenName + ", testcase #" + scId; if (node != null) { log += " (" + node + " object)"; } myLog.Error(log); }
private void DoExpand(SpecScreen screen, string pathToApp, MyLog myLog, List <ClassExpression> allClassesExp) { for (int fi = 0; fi < screen.Scenarios.Count; fi++) { IScenario tempScenario = screen.Scenarios[fi]; if (tempScenario is SpecScenario) { SpecScenario scenario = tempScenario as SpecScenario; List <string> listActionExp = scenario.UserActionsInString; List <Color> colors = scenario.Colors; for (int se = 0; se < listActionExp.Count; se++) { string actionExp = listActionExp[se]; if (actionExp == null) { myLog.Error("NULL at (" + (fi + 1) + "," + (se + 2) + ")"); continue; } SpecNode specNode = screen.ListSpecNodes[se]; ScriptGenerationParams _params = null; AbstractSpecUserAction specUserAction = null; int lastInd = IsValidationUserCode(se, screen.ListValidationUserCode); if (lastInd > se) { specUserAction = new ValidationUserCodeSpecUserAction(); _params = new ValidationUCScriptGenerationParams(); List <string> listExp = new List <string>(); for (int th = se; th <= lastInd; th++) { String tempActionExp = listActionExp[th]; AbstractSpecUserAction temp = handleUserActionExpression( tempActionExp.Trim(), specNode, colors[th], myLog); if (!(temp is ValidationSpecUserAction)) { myLog.Warn("Expression: " + tempActionExp + " must be validation", logger); screen = null; return; } else { if (tempActionExp != null && !tempActionExp.Trim().Equals("")) { listExp.Add(tempActionExp.Trim()); } } } (specUserAction as ValidationUserCodeSpecUserAction).ListExps = listExp; ((ValidationUCScriptGenerationParams)_params).ListExps = listExp; if (screen is TestSpecificationScreen) { ((ValidationUCScriptGenerationParams)_params).ClassExpressions = allClassesExp; } ((ValidationUCScriptGenerationParams)_params).ClassName = AbstractSpecUserAction.GetFolderNameFromScreen(screen) + "_Validation"; ((ValidationUCScriptGenerationParams)_params).FunctionName = "Validate_" + Regex.Replace(specNode.Expression, "[^A-Za-z0-9]", "_"); SetAttributes(scenario, specUserAction, specNode, screen, pathToApp, colors, _params, se, myLog); se = lastInd; } else { string[] listActionsEpx = splitAction(actionExp, AbstractSpecUserAction.AND); foreach (string action in listActionsEpx) { specUserAction = handleUserActionExpression(action.Trim(), specNode, colors[se], myLog); if (specUserAction != null) { if (specUserAction is UserCodeSpecUserAction userCodeExpression) { _params = new UserCodeScriptGenerationParams(); ((UserCodeScriptGenerationParams)_params).MapAliasWithNode = screen.MappingAliasWithNode; if (screen is TestSpecificationScreen testSpecScreen) { ((UserCodeScriptGenerationParams)_params).ClassExpressions = allClassesExp; } } else if (specUserAction is WaitValidateSpecUserAction waitUserAction) { _params = new WaitValidateScriptGenerationParams(); } else { _params = new ScriptGenerationParams(); } SetAttributes(scenario, specUserAction, specNode, screen, pathToApp, colors, _params, se, myLog); } } } } } } }
public bool Generate(List <IElement> listRootElements, List <SpecScreen> screensExpanded, string folderOutPath, string projectName, string appPath, MyLog myLog) { string tempFolderPath = Utils.CreateTempFolder(projectName + "_" + DateTime.Now.ToString("yyMMdd_HHmmss")); // generate CSharp code ElementCSharpCodeGeneration elementCSharpCodeGeneration = new ElementCSharpCodeGeneration(); string repoClassName = projectName + DEFINITION; FileInfo csFile = elementCSharpCodeGeneration.Generate( listRootElements, tempFolderPath, repoClassName, projectName); if (csFile == null) { myLog.Error("An error occured when generating C# codes"); return(false); } // generate .xml file(s) ElementXmlGeneration elementXmlGeneration = new ElementXmlGeneration(); string repoFileName = projectName + REPO; string imgCapFileName = projectName + IMAGE_CAPTURE; List <FileInfo> listXmlFile = elementXmlGeneration.Store(listRootElements, Path.Combine(tempFolderPath, repoFileName), Path.Combine(tempFolderPath, imgCapFileName)); if (listXmlFile == null) { myLog.Error("An error occured when generating .xml files"); return(false); } // generate scripts Tuple <Dictionary <string, string>, List <string> > pair = null; if (screensExpanded != null && screensExpanded.Count > 0) { CSharpScriptsGeneration scriptsGeneration = new CSharpScriptsGeneration(); pair = scriptsGeneration.Generate( screensExpanded, tempFolderPath, repoFileName, imgCapFileName, appPath, repoClassName, projectName, INSTANCE, myLog); if (pair == null) { myLog.Error("An error occured when generating C# scripts"); return(false); } } // generate visual studio solution List <FileInfo> listFiles = new List <FileInfo>(); listFiles.Add(csFile); listFiles.AddRange(listXmlFile); //generate text file contain all running class if (pair != null) { File.WriteAllText(Path.Combine(tempFolderPath, RUNNING_TEST_FILE_NAME), string.Join(CSharpScriptsGeneration.NEW_LINE, pair.Item1)); pair.Item2.Add(RUNNING_TEST_FILE_NAME); } VsSolutionGeneration gen = new VsSolutionGeneration(); bool vsGenCheck = gen.Generate(listFiles, projectName, folderOutPath, // read from user's settings Properties.Settings.Default.path_GUI_Testing_Automation_ref, Properties.Settings.Default.path_to_vstemplate_output_proj, tempFolderPath, pair?.Item1, pair?.Item2, appPath); if (!vsGenCheck) { myLog.Error("An error occured when generating Visual Studio project"); return(false); } return(true); }