2012-04-05 11 views
11

Ho il seguente codice HTML:supporto per i tag HTML5 WatiN

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

devo digitare il testo in esso da WatiN:

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

Ma il campo non può essere trovato. Questo perché WatiN non supporta ancora i tag HTML5. Ho trovato un solution a questo creando un esteso TextField-classe:

[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); 
    } 
} 

Dopo aver registrato il tipo e l'esecuzione del codice ancora non funziona. Qualcuno può vedere perché o qualcuno ha un'altra soluzione per questo problema?

+1

Grazie - funziona benissimo - hai omesso un attributo: [ElementTag ("input", InputType = "tel", Index = 11)] –

risposta

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

Cerca di ottenere il campo di testo con id email e quindi non riesce per il tipo TextFieldExtended.

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

Ottiene il campo di testo esteso con ID e-mail.

+1

Se nessun altro non ha avuto accesso a 'TextFieldExtend': https: // github .com/sergiomokshin/DiarioEscolar/blob/master/DiarioEscolar.AcceptanceTests/StepHelpers/TextFieldExtended.cs – BenR