Beispiel #1
0
        /// <summary>
        /// Gets a list of declarations emitted by the control.
        /// </summary>
        public void AddDeclarations(HelperDefinition helper, SeleniumGeneratorContext context)
        {
            // determine the name
            var uniqueName = DetermineName(context);

            // make the name unique
            if (context.UsedNames.Contains(uniqueName))
            {
                var index = 1;
                while (context.UsedNames.Contains(uniqueName + index))
                {
                    index++;
                }
                uniqueName = uniqueName + index;
            }
            context.UsedNames.Add(uniqueName);
            context.UniqueName = uniqueName;

            // determine the selector
            var selector = TryGetNameFromProperty(context.Control, UITests.NameProperty);

            if (selector == null)
            {
                selector = uniqueName;

                AddUITestNameProperty(helper, context, uniqueName);
            }
            context.Selector = selector;

            AddDeclarationsCore(helper, context);
        }
Beispiel #2
0
        protected virtual string DetermineName(SeleniumGeneratorContext context)
        {
            // get the name from the UITest.Name property
            var uniqueName = TryGetNameFromProperty(context.Control, UITests.NameProperty);

            // if not found, use the name properties to determine the name
            if (uniqueName == null)
            {
                foreach (var nameProperty in NameProperties)
                {
                    uniqueName = TryGetNameFromProperty(context.Control, nameProperty);
                    if (uniqueName != null)
                    {
                        break;
                    }
                }
            }

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

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

            return(uniqueName);
        }
Beispiel #3
0
        private void AddUITestNameProperty(HelperDefinition helper, 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);

            helper.MarkupFileModifications.Add(new MarkupFileInsertText()
            {
                Text     = " UITests.Name=\"" + uniqueName + "\"",
                Position = token.StartPosition
            });
        }
Beispiel #4
0
 protected MemberDeclarationSyntax GeneratePropertyForProxy(SeleniumGeneratorContext context, string typeName, params string[] genericTypeNames)
 {
     return(SyntaxFactory.PropertyDeclaration(
                ParseTypeName(typeName, genericTypeNames),
                context.UniqueName
                )
            .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)))
            .AddAccessorListAccessors(
                SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
                ));
 }
Beispiel #5
0
 protected StatementSyntax GenerateInitializerForProxy(SeleniumGeneratorContext context, string propertyName, string typeName, params string[] genericTypeNames)
 {
     return(SyntaxFactory.ExpressionStatement(
                SyntaxFactory.AssignmentExpression(
                    SyntaxKind.SimpleAssignmentExpression,
                    SyntaxFactory.IdentifierName(propertyName),
                    SyntaxFactory.ObjectCreationExpression(ParseTypeName(typeName, genericTypeNames))
                    .WithArgumentList(
                        SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(new[]
     {
         SyntaxFactory.Argument(SyntaxFactory.ThisExpression()),
         SyntaxFactory.Argument(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(context.Selector)))
     }))
                        )
                    )
                ));
 }
Beispiel #6
0
 public virtual bool CanAddDeclarations(HelperDefinition helperDefinition, SeleniumGeneratorContext context)
 {
     return(true);
 }
Beispiel #7
0
 protected abstract void AddDeclarationsCore(HelperDefinition helper, SeleniumGeneratorContext context);