private By CreateElementLocator(MemberInfo memberInfo)
        {
            var attributes = memberInfo.GetCustomAttributes(typeof(FindsByAttribute), true);

            if (attributes.Length == 0)
            {
                return(ByFactory.Create(How.Id, memberInfo.Name));
            }

            if (attributes.Length > 1)
            {
                var errorBuilder = new StringBuilder();

                errorBuilder.AppendFormat(
                    "Multiple attributes [{0}] found on [{1}] which is member of [{2}] class.",
                    typeof(FindsByAttribute), memberInfo.Name, memberInfo.DeclaringType);

                errorBuilder.AppendFormat(
                    "Having multiple attribute for a single class member is not supported by [{0}].", this);

                throw new ArgumentException(errorBuilder.ToString(), "memberInfo");
            }

            return(ByFactory.Create(attributes[0] as FindsByAttribute));
        }
 public void ShouldCreateLocatorFromTypeAttribute()
 {
     Assert.That(
         ByFactory.Create(new ElementLocatorAttribute {
         How = How.Id, Using = "username"
     }),
         Is.EqualTo(By.Id("username"))
         );
 }
 public void ShouldCreateLocatorFromMemberAttribute()
 {
     Assert.That(
         ByFactory.Create(new FindsByAttribute {
         How = How.Id, Using = "username"
     }),
         Is.EqualTo(By.Id("username"))
         );
 }
 public void ShouldThrowArgumentErrorWhenLocatorTypeIsNowKnown()
 {
     Assert.That(() => ByFactory.Create((How)13, "username"), Throws.ArgumentException);
 }
 public By ShouldCreateLocator(How how, string locator)
 {
     return(ByFactory.Create(how, locator));
 }