views:

931

answers:

1

Is it possible to unit test the MS AJAX Control Toolkit's HTML Editor? I've tried Watin, WebAii and Selenium without any success...

Watin

I can find the textbox related to the control but I get an exception trying to access it:

using (Browser ie = new IE()) {
    ie.GoTo(testUri);
    Assert.IsTrue(ie.ContainsText("Expected text"));

    var textBox = ie.TextField(Find.ById(id => id.Contains("Editor")));
    textBox.TypeText("testing 123");
}

System.Runtime.InteropServices.COMException: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.

Selenium

I tried the Selenium IDE also without any success. When I loaded ASP.net's sample page, typed some text into the editor and clicked the "Submit" button here is the test case it made:

[Test]
public void TheUntitledTest() {
    selenium.Open("/AJAX/AjaxControlToolkit/Samples/HTMLEditor/HTMLEditor.aspx");
    // Text was typed at this point
    selenium.Click("ctl00_SampleContent_submit");
}

Here is the log messages from rerunning the recorded actions in the Selenium IDE:

[info] Executing: |open | /AJAX/AjaxControlToolkit/Samples/HTMLEditor/HTMLEditor.aspx | |

[info] Executing: |click | ctl00_SampleContent_submit | |

+1  A: 

Looking the control it is an IFrame where the editor is actually an editable body

<body contentEditable="true">

You should be able to update the inner text with javascript using the

IE.Frame(Find.BySrc(frameSrc)).Eval( ... javascript goes here ... );

command in watiN then click the button.

Another approach would be to do a mouse move, then click, then send keys.

Bruce McLeod