ExecuteAutomation

Hand Coding Web Application using Coded UI Test

In the last post, we discussed record and playback of web application using Coded UI Test, in this part we will try to hand code the application as did in Hand coding of windows application. In this post we will again try to re-insist the “Parent Child” relationship of controls such as Browser Window, HtmlDocument and HtmlControls. So let discuss the complete hand coding in the video shown below Here is the complete code for the above video discussed
public  void CustomWebMethod()
{
    //Create the Browser Window
    BrowserWindow broWin = new BrowserWindow();
    broWin.SearchProperties[BrowserWindow.PropertyNames.Name] = "Execute Automation";

    HtmlDocument doc = new HtmlDocument(broWin);
    doc.FilterProperties[HtmlDocument.PropertyNames.Title] = "Execute Automation";

    HtmlEdit txtUserName = new HtmlEdit(doc);
    txtUserName.SearchProperties[HtmlEdit.PropertyNames.Name] = "UserName";
    Keyboard.SendKeys(txtUserName, "Karthik");

    HtmlInputButton btnLogin = new HtmlInputButton(doc);
    btnLogin.SearchProperties[HtmlInputButton.PropertyNames.Name] = "Login";
    Mouse.Click(btnLogin);

    broWin = new BrowserWindow();
    broWin.SearchProperties[UITestControl.PropertyNames.Name] = "Execute Automation";

    doc = new HtmlDocument(broWin);
    doc.FilterProperties[HtmlDocument.PropertyNames.Title] = "Execute Automation";

    System.Threading.Thread.Sleep(4000);

    HtmlEdit txtInitial = new HtmlEdit(doc);
    txtInitial.SearchProperties[HtmlEdit.PropertyNames.Name] = "Initial";

    Keyboard.SendKeys(txtInitial, "KK");

}

Thanks for watching the video and reading the blog !!! Please leave your comments and let me know if there is anything I need to improve in this article and video !!! Thanks, Karthik KK