Site Loader
Auckland, New Zealand
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

Post Author: Karthik kk

25 Replies to “Hand Coding Web Application using Coded UI Test”

  1. Hi Karthik,

    What is exact difference between Search properties and Filter Properties? which is better and faster for identify the control according to the coding standards which one is more preferable to use?

    Thanks
    Anudeep

  2. Hi,
    can anyone help me out how to automate by hand coding in coded ui to test a web application by hovering menu items and then clicking the sub menu under them

  3. HI karthick,
    I have a web application which has a number of Html Custom menu items (capable of being recognized by coded ui) but has a number of submenus too some of which are HtmlCustom controls and some as HtmlHyperlink controls. These sub menu items are hidden . My aim is to hover over the menu items (i.e html custom control)and then when they get expanded to click on the sub menu items which act as hyperlink. I am not able to do this. i use this code for clicking all the hyperlink .help me out how to handle with the HtmlCustom and then click items below it.

  4. hi karthick,
    let me explain you brief so it might give you some idea to help me out
    1)I launch the url
    2)i extracted all the hyperlinks from the web page
    3)It extracted all the links including main menu which involves only in hovering and then go to sub menu for clicking event which acts as hyperlinks
    issue which i undergone is the browser is cannot able to identify those main menu so i cannot able to click other hyperlinks further in sub menu.

    My aim is to hover over the menu items (i.e html custom control)and then when they get expanded to click on the sub menu items which act as hyperlink. I am not able to do this. i use this code for clicking all the hyperlink .help me out how to handle with the HtmlCustom and then click items below it.

    HtmlControl controls = new HtmlControl(browser);
    controls.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, “HtmlHyperlink”);
    UITestControlCollection collection = controls.FindMatchingControls();

    foreach (UITestControl links in collection)
    {
    HtmlHyperlink hyperlink = (HtmlHyperlink)links;
    string h = hyperlink.Href.ToString();
    // To generate code for this test, select “Generate Code for Coded UI Test” from the shortcut menu and select one of the menu items.
    Console.WriteLine(h);

    }

    give me ideas for further action to be proceeded that will be helpfull for me, and show me some sample code for hovering over main menu and then clicking the sub menu hyperlinks.

    Regards,
    suruthi.s

  5. hi karthick,
    let me explain you brief so it might give you some idea to help me out
    1)I launch the url
    2)i extracted all the hyperlinks from the web page
    3)It extracted all the links including main menu which involves only in hovering and then go to sub menu for clicking event which acts as hyperlinks
    issue which i undergone is the browser is cannot able to identify those main menu so i cannot able to click other hyperlinks further in sub menu.

    My aim is to hover over the menu items (i.e html custom control)and then when they get expanded to click on the sub menu items which act as hyperlink. I am not able to do this. i use this code for clicking all the hyperlink .help me out how to handle with the HtmlCustom and then click items below it.

    HtmlControl controls = new HtmlControl(browser);
    controls.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, “HtmlHyperlink”);
    UITestControlCollection collection = controls.FindMatchingControls();

    foreach (UITestControl links in collection)
    {
    HtmlHyperlink hyperlink = (HtmlHyperlink)links;
    string h = hyperlink.Href.ToString();
    // To generate code for this test, select “Generate Code for Coded UI Test” from the shortcut menu and select one of the menu items.
    Console.WriteLine(h);

    }

    give me ideas for further action to be proceeded that will be helpfull for me, and show me some sample code for hovering over main menu and then clicking the sub menu hyperlinks.

    1. Got it !!!

      The reason is because the submenus will be rendered in page only while you hover, since they may be a Javascript to display the UL or LI.

      Well, hovering I have not did personally, but let me do it and see if I could achieve it.

      If not its open to community to respond your query as well, Any thoughts guys ?

      Thanks,
      Karthik KK

  6. Hi Karthick,
    Really thanks for your response and suggest me after you are trying it, so that it will be helpfull for me.if any one could help me then suggest me your ideas

    Thanks,
    Suruthi.S

  7. Hi,

    If i am launching a browser with an url and adding new tab to the same browser how to pass another url to the new tab..its technology name is MSAA and control type is client how to handle with it

  8. Hi,

    can anyone help me out how to check the performance or speed for loading a webpage links simaltanious using coded ui c# hand coding

  9. Hi Karthik,
    I was wondering that if you knew of a good book that can help us out understanding the Microsoft errors and something that has the methods. Ex: You knew about the SendKeys method but as a beginner I had no idea about it. So if the book can also have the methods listed out that would be useful :)!! And these tutorials are fantastic, better than every other tutorial out there

    1. Thanks for your comments Ashjeet !

      There are no documentation as such, but you can drill down the API for more information.

      Thanks,
      Karthik KK

  10. Hi Karthik,
    I have another question. Instead of using the Keyboard.SendKeys method and hard coding a value for initials, is there a way where we can dynamically pause the code the during runtime and the user enters the initials. And then the code continues on ?

  11. Hi Karthik ,

    My question is how to access the data from csv file in other methods, i.e., other than test method . Instead of hardcoding the data can we access through the csv file to “CustomWebMethod()”?.

  12. Hi Karthik,

    My question is, can we send the data without hard coding using CSV file for other methods than the test method?i.e., can i send the data though csv for CustomWebMethod()?

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

    I get an error message when I debug test (The playback failed to find the control with the given search properties)

    Please advise.

Leave a Reply to Sifiso Cancel reply

Your email address will not be published. Required fields are marked *