2012-04-05 7 views
11

Tengo el siguiente código HTML:apoyo WatiN para las etiquetas HTML5

<input type="email" id="email"> 

Quiero escribir texto en él desde WatiN:

var field = Browser.TextField("email"); 
Assert.IsTrue(field.Exists); 

Pero el campo no se puede encontrar. Esto se debe a que WatiN aún no admite etiquetas HTML5. me encontré con un solution a esto mediante la creación de una clase TextField extendida:

[ElementTag("input", InputType = "text", Index = 0)] 
[ElementTag("input", InputType = "password", Index = 1)] 
[ElementTag("input", InputType = "textarea", Index = 2)] 
[ElementTag("input", InputType = "hidden", Index = 3)] 
[ElementTag("textarea", Index = 4)] 
[ElementTag("input", InputType = "email", Index = 5)] 
[ElementTag("input", InputType = "url", Index = 6)] 
[ElementTag("input", InputType = "number", Index = 7)] 
[ElementTag("input", InputType = "range", Index = 8)] 
[ElementTag("input", InputType = "search", Index = 9)] 
[ElementTag("input", InputType = "color", Index = 10)] 
public class TextFieldExtended : TextField 
{ 
    public TextFieldExtended(DomContainer domContainer, INativeElement element) 
     : base(domContainer, element) 
    { 
    } 

    public TextFieldExtended(DomContainer domContainer, ElementFinder finder) 
     : base(domContainer, finder) 
    { 
    } 

    public static void Register() 
    { 
     Type typeToRegister = typeof (TextFieldExtended); 
     ElementFactory.RegisterElementType(typeToRegister); 
    } 
} 

Después de registrar el tipo y ejecutar el código que todavía no funciona. ¿Alguien puede ver por qué o alguien tiene otra solución para este problema?

+1

Gracias - funciona bien: usted omitió un atributo: [ElementTag ("input", InputType = "tel", Index = 11)] –

Respuesta

14
var field = Browser.TextField("email"); 

Intenta obtener el TextField con el id. De correo electrónico y, por lo tanto, falla para el tipo TextFieldExtended.

var field = Browser.ElementOfType<TextFieldExtended>("email"); 

Obtiene TextFieldExtended con el id. De correo electrónico.

+1

Si alguien más no tuvo acceso a 'TextFieldExtend': https: // github .com/sergiomokshin/DiarioEscolar/blob/master/DiarioEscolar.AcceptanceTests/StepHelpers/TextFieldExtended.cs – BenR