public void ProcessMarkupFile(SeleniumGeneratorConfiguration seleniumConfiguration)
        {
            var viewTree = ResolveControlTree(seleniumConfiguration.ViewFullPath);

            // get all ui tests selectors used in current view
            var usedSelectors = GetUsedSelectors(viewTree);

            // resolve master pages of current page
            var masterPageObjectDefinitions = ResolveMasterPages(dotvvmConfig, seleniumConfiguration, viewTree);

            // union used unique names across all master pages and current view
            var allUsedNames = UnionUsedUniqueNames(masterPageObjectDefinitions, usedSelectors);

            // get content of page object of current view
            var pageObject = CreatePageObjectDefinition(seleniumConfiguration, viewTree, allUsedNames);

            // combine all master page objects with current page object so we can generate page object class for all proxies
            pageObject = CombineViewHelperDefinitions(pageObject, masterPageObjectDefinitions);

            // generate the page object class
            GeneratePageObjectClass(seleniumConfiguration, pageObject);

            // update view markup file
            UpdateMarkupFile(pageObject, seleniumConfiguration.ViewFullPath);
        }
示例#2
0
        private void UpdateMarkupFile(SeleniumGeneratorConfiguration seleniumConfiguration, HelperDefinition helper)
        {
            var sb = new StringBuilder(File.ReadAllText(seleniumConfiguration.ViewFullPath, Encoding.UTF8));

            foreach (var modification in helper.MarkupFileModifications.OrderByDescending(m => m.Position))
            {
                modification.Apply(sb);
            }
            File.WriteAllText(seleniumConfiguration.ViewFullPath, sb.ToString(), Encoding.UTF8);
        }
        private MasterPageObjectDefinition GetMasterPageObjectDefinition(
            SeleniumGeneratorConfiguration seleniumConfiguration,
            IAbstractTreeRoot masterTree,
            IAbstractDirective masterPageFile,
            HashSet <string> usedSelectors)
        {
            var definition = CreatePageObjectDefinition(seleniumConfiguration, masterTree, usedSelectors);

            return(MapPageObjectDefinition(definition, masterPageFile));
        }
示例#4
0
        private static HelperDefinition CreateHelperDefinition(SeleniumGeneratorConfiguration seleniumConfiguration, IAbstractTreeRoot tree)
        {
            // traverse the tree
            var visitor = new SeleniumHelperVisitor();

            visitor.PushScope(new HelperDefinition()
            {
                Name = seleniumConfiguration.HelperName
            });
            visitor.VisitView((ResolvedTreeRoot)tree);
            return(visitor.PopScope());
        }
        private PageObjectDefinition CreatePageObjectDefinition(
            SeleniumGeneratorConfiguration seleniumConfiguration,
            IAbstractTreeRoot tree,
            HashSet <string> masterUsedUniqueSelectors = null)
        {
            var pageObjectDefinition = GetPageObjectDefinition(seleniumConfiguration, masterUsedUniqueSelectors);

            // traverse the tree
            visitor.PushScope(pageObjectDefinition);
            visitor.VisitView((ResolvedTreeRoot)tree);
            return(visitor.PopScope());
        }
示例#6
0
        public void ProcessMarkupFile(DotvvmConfiguration dotvvmConfiguration, SeleniumGeneratorConfiguration seleniumConfiguration)
        {
            // resolve control tree
            var tree = ResolveControlTree(seleniumConfiguration.ViewFullPath, dotvvmConfiguration);

            // var helper
            var helper = CreateHelperDefinition(seleniumConfiguration, tree);

            // generate the class
            GenerateHelperClass(seleniumConfiguration, helper);

            // update the markup file
            UpdateMarkupFile(seleniumConfiguration, helper);
        }
        private PageObjectDefinition GetPageObjectDefinition(SeleniumGeneratorConfiguration seleniumConfiguration,
                                                             HashSet <string> masterUsedUniqueSelectors)
        {
            var pageObjectDefinition = new PageObjectDefinition {
                Name = seleniumConfiguration.PageObjectName
            };

            if (masterUsedUniqueSelectors != null)
            {
                pageObjectDefinition.ExistingUsedSelectors.UnionWith(masterUsedUniqueSelectors);
            }

            return(pageObjectDefinition);
        }
示例#8
0
        private void GenerateHelperClass(SeleniumGeneratorConfiguration seleniumConfiguration, HelperDefinition helper)
        {
            var tree = CSharpSyntaxTree.Create(
                SyntaxFactory.CompilationUnit().WithMembers(SyntaxFactory.List(new MemberDeclarationSyntax[]
            {
                SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName(seleniumConfiguration.TargetNamespace))
                .WithMembers(SyntaxFactory.List(new MemberDeclarationSyntax[]
                {
                    GenerateHelperClassContents(helper)
                }))
            }))
                .NormalizeWhitespace()
                );

            File.WriteAllText(seleniumConfiguration.HelperFileFullPath, tree.ToString(), Encoding.UTF8);
        }
        private List <MasterPageObjectDefinition> ResolveMasterPages(
            DotvvmConfiguration dotvvmConfiguration,
            SeleniumGeneratorConfiguration seleniumConfiguration,
            IAbstractTreeRoot viewTree)
        {
            var pageObjectDefinitions = new List <MasterPageObjectDefinition>();

            CreateMasterPageObjectDefinitions(seleniumConfiguration, viewTree, pageObjectDefinitions);

            foreach (var pageObjectDefinition in pageObjectDefinitions)
            {
                UpdateMarkupFile(pageObjectDefinition, pageObjectDefinition.MasterPageFullPath);
            }

            return(pageObjectDefinitions);
        }
        private void GeneratePageObjectClass(SeleniumGeneratorConfiguration seleniumConfiguration, PageObjectDefinition pageObject)
        {
            var tree = CSharpSyntaxTree.Create(
                SyntaxFactory.CompilationUnit()
                .WithUsings(GetSeleniumHelpersUsingList())
                .WithMembers(SyntaxFactory.List(new MemberDeclarationSyntax[]
            {
                SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName(seleniumConfiguration.TargetNamespace))
                .WithMembers(SyntaxFactory.List(new MemberDeclarationSyntax[]
                {
                    GenerateHelperClassContents(pageObject)
                }))
            }))
                .NormalizeWhitespace()
                );

            FileSystemHelpers.WriteFile(seleniumConfiguration.PageObjectFileFullPath, tree.ToString(), false);
        }
        private void CreateMasterPageObjectDefinitions(SeleniumGeneratorConfiguration seleniumConfiguration,
                                                       IAbstractTreeRoot viewTree,
                                                       ICollection <MasterPageObjectDefinition> pageObjectDefinitions)
        {
            if (IsNestedInMasterPage(viewTree))
            {
                var masterPageFile = viewTree.Directives[ParserConstants.MasterPageDirective].FirstOrDefault();
                if (masterPageFile != null)
                {
                    var masterTree    = ResolveControlTree(masterPageFile.Value);
                    var usedSelectors = GetUsedSelectors(masterTree);

                    var masterPageObjectDefinition = GetMasterPageObjectDefinition(seleniumConfiguration, masterTree, masterPageFile, usedSelectors);

                    pageObjectDefinitions.Add(masterPageObjectDefinition);

                    // recursion
                    CreateMasterPageObjectDefinitions(seleniumConfiguration, masterTree, pageObjectDefinitions);
                }
            }
        }
 private static void GeneratePageObject(SeleniumPageObjectGenerator generator,
                                        SeleniumGeneratorConfiguration config)
 => generator.ProcessMarkupFile(config);