コード例 #1
0
        public static string GetScriptAccessElement(IElement element, string instanceName)
        {
            string   re   = ElementCSharpCodeGeneration.FormatName(element.Attributes.Name);
            IElement temp = element.Parent;

            while (temp != null)
            {
                re   = ElementCSharpCodeGeneration.FormatName(temp.Attributes.Name) + "." + re;
                temp = temp.Parent;
            }
            return(instanceName + "." + re);
        }
コード例 #2
0
        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);
        }