예제 #1
0
 protected void AddGenericPageObjectProperties(PageObjectDefinition pageObject,
                                               SeleniumGeneratorContext context,
                                               string type,
                                               string itemHelperName)
 {
     pageObject.Members.Add(GeneratePropertyForProxy(context.UniqueName, type, itemHelperName));
     pageObject.ConstructorStatements.Add(GenerateInitializerForProxy(context, type, itemHelperName));
 }
예제 #2
0
        private void AddUITestNameProperty(PageObjectDefinition pageObject, SeleniumGeneratorContext context, string uniqueName)
        {
            // find end of the tag
            var token = context.Control.DothtmlNode.Tokens.First(t => t.Type == DothtmlTokenType.CloseTag || t.Type == DothtmlTokenType.Slash);

            pageObject.MarkupFileModifications.Add(new MarkupFileInsertText()
            {
                Text     = " UITests.Name=\"" + uniqueName + "\"",
                Position = token.StartPosition
            });
        }
예제 #3
0
        protected virtual string DetermineName(PageObjectDefinition pageObject, SeleniumGeneratorContext context)
        {
            // if selector is set, just read it and don't add data context prefixes
            //var shouldAddDataContextPrefixes = uniqueName == null;
            var shouldAddDataContextPrefixes = true;

            // if not found, use the name properties to determine the name

            string uniqueName = null;

            foreach (var nameProperty in NameProperties)
            {
                uniqueName = SelectorStringHelper.TryGetNameFromProperty(context.Control, nameProperty);
                if (uniqueName != null)
                {
                    uniqueName = SelectorStringHelper.NormalizeUniqueName(uniqueName);
                    break;
                }
            }

            // if not found, try to use the content of the control to determine the name
            if (uniqueName == null && CanUseControlContentForName)
            {
                uniqueName = SelectorStringHelper.GetTextFromContent(context.Control.Content);
            }

            // check if control is userControl and assign control's name as unique name
            if (uniqueName == null && context.Control.DothtmlNode is DothtmlElementNode htmlNode)
            {
                uniqueName = htmlNode.TagName;

                // not add DataContext when generating page object for user control
                shouldAddDataContextPrefixes = false;
            }

            // if not found, use control name
            if (uniqueName == null)
            {
                uniqueName = typeof(TControl).Name;
            }

            if (shouldAddDataContextPrefixes)
            {
                uniqueName = SelectorStringHelper.AddDataContextPrefixesToName(pageObject.DataContextPrefixes, uniqueName);
            }

            return(uniqueName);
        }
예제 #4
0
 protected StatementSyntax GenerateInitializerForProxy(SeleniumGeneratorContext context, string typeName, params string[] genericTypeNames)
 {
     return(SyntaxFactory.ExpressionStatement(
                SyntaxFactory.AssignmentExpression(
                    SyntaxKind.SimpleAssignmentExpression,
                    SyntaxFactory.IdentifierName(context.UniqueName),
                    SyntaxFactory.ObjectCreationExpression(RoslynHelper.ParseTypeName(typeName, genericTypeNames))
                    .WithArgumentList(
                        SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(new[]
     {
         SyntaxFactory.Argument(SyntaxFactory.ThisExpression()),
         SyntaxFactory.Argument(RoslynHelper.GetPathSelectorObjectInitialization(context.Selector))
     }))
                        )
                    )
                ));
 }
예제 #5
0
        /// <summary>
        /// Gets a list of declarations emitted by the control.
        /// </summary>
        public void AddDeclarations(PageObjectDefinition pageObject, SeleniumGeneratorContext context)
        {
            string propertyName;

            var htmlName = SelectorStringHelper.TryGetNameFromProperty(context.Control, UITests.NameProperty);

            if (htmlName == null)
            {
                // determine the name
                propertyName = DetermineName(pageObject, context);
            }
            else
            {
                propertyName = htmlName;
            }

            // normalize name
            var normalizedName = SelectorStringHelper.RemoveNonIdentifierCharacters(propertyName);
            // make the name unique
            var uniqueName = MakePropertyNameUnique(context.UsedNames, normalizedName);

            context.UsedNames.Add(uniqueName);
            context.UniqueName = uniqueName;

            // determine the selector
            if (htmlName == null)
            {
                context.Selector = uniqueName;
                AddUITestNameProperty(pageObject, context, uniqueName);
            }
            else
            {
                context.Selector = htmlName;
            }

            context.UsedNames.Add(propertyName);

            AddDeclarationsCore(pageObject, context);
        }
예제 #6
0
 public virtual bool CanAddDeclarations(PageObjectDefinition pageObject, SeleniumGeneratorContext context)
 {
     return(true);
 }
예제 #7
0
 protected abstract void AddDeclarationsCore(PageObjectDefinition pageObject, SeleniumGeneratorContext context);
예제 #8
0
 protected void AddControlPageObjectProperty(PageObjectDefinition pageObject, SeleniumGeneratorContext context, string type)
 {
     pageObject.Members.Add(GeneratePropertyForProxy(context.UniqueName, type));
     pageObject.ConstructorStatements.Add(GenerateInitializerForControl(context.UniqueName, context.Selector, type));
 }