This project is read-only.

how to write code for web application through coded UI

Oct 3, 2014 at 5:23 AM
I was creating a sample application:

Step1: opened internal Explorer and typed http://www.bing.com/

Step2: typed sachin and click on search

Step4: clicked on "Sachin Tendulkar - Wikipedia, the free encyclopedia"

I wrote the code. It was working but, my concern is line number of code. I have to identify object but before that I have to identify parents item and every new page it will change. I also follow this link (Hand-coding a Coded UI Test) but, it was showing error in HtmlProperties


Here is my code:

BrowserWindow browserWindow = BrowserWindow.Launch(new System.Uri("http://www.bing.com/"));

BrowserWindow bw1 = new BrowserWindow(); // (browserWindow);
     bw1.SearchProperties[UITestControl.PropertyNames.Name] = "Bing - Windows Internet Explorer";
     bw1.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame";
     bw1.SearchProperties[UITestControl.PropertyNames.TechnologyName] = "MSAA";
     // bw1.DrawHighlight();

     HtmlDocument document = new HtmlDocument(bw1);
     document.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
     document.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
     document.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "False";
     document.FilterProperties[HtmlDocument.PropertyNames.Title] = "Bing";
     document.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/";
     document.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://www.bing.com/";
     document.WindowTitles.Add("Bing");
HtmlEdit ed = new HtmlEdit(document);
     //  htmlt ed = new HtmlEdit(document);
     ed.SearchProperties[HtmlEdit.PropertyNames.Id] = "sb_form_q";
     ed.SearchProperties[HtmlEdit.PropertyNames.Name] = "q";
     ed.FilterProperties[HtmlEdit.PropertyNames.Class] = "b_searchbox";
     ed.Text = "sachine";


     HtmlInputButton button = new HtmlInputButton(document);
     button.SearchProperties[HtmlButton.PropertyNames.Id] = "sb_form_go";
     button.SearchProperties[HtmlButton.PropertyNames.Name] = "go";
     button.FilterProperties[HtmlButton.PropertyNames.Type] = "submit";
     // button.DrawHighlight();
     Mouse.Click(button);


     BrowserWindow bw2 = new BrowserWindow(); // (browserWindow);
     bw2.SearchProperties[UITestControl.PropertyNames.Name] = "sachine - Bing";
     bw2.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame";
     // bw1.SearchProperties[UITestControl.PropertyNames.TechnologyName] = "MSAA";
     // bw1.DrawHighlight();

     HtmlDocument document2 = new HtmlDocument(bw2);
     document2.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
     document.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
     // document.SearchProperties[HtmlDocument.PropertyNames.FrameDocument] = "False";
     document2.FilterProperties[HtmlDocument.PropertyNames.Title] = "sachine - Bing";
     document2.FilterProperties[HtmlDocument.PropertyNames.AbsolutePath] = "/search";
     document2.FilterProperties[HtmlDocument.PropertyNames.PageUrl] = "http://www.bing.com/search?q=sachine&qs=n&form=QBLH&pq=sachine&sc=8-7&sp=-1&sk=&cvid=7ea461a67db341c1a6e6d14071f6ca29";
     document2.WindowTitles.Add("sachine - Bing");
     // document2.DrawHighlight();

     HtmlCustom hc = new HtmlCustom(document2);
     hc.SearchProperties[HtmlDocument.PropertyNames.Id] = "b_results";
     hc.SearchProperties[HtmlDocument.PropertyNames.TagInstance] = "1";
     //  hc.DrawHighlight();

     HtmlHyperlink hhl = new HtmlHyperlink(hc);
     hhl.SearchProperties[HtmlDocument.PropertyNames.Id] = null;
     hhl.SearchProperties[HtmlDocument.PropertyNames.InnerText] = "Sachin Tendulkar - Wikipedia, the free encyclopedia";
     hhl.SearchProperties[HtmlDocument.PropertyNames.TagName] = "A";
     hhl.FilterProperties[HtmlHyperlink.PropertyNames.AbsolutePath] = "/wiki/Sachin_Tendulkar";
     // hhl.SearchProperties[HtmlDocument.PropertyNames.TagInstance] = "26";
     // hc.SearchProperties[HtmlDocument.PropertyNames] = "http://en.wikipedia.org/wiki/Sachin_Tendulkar";
     hhl.FilterProperties[HtmlHyperlink.PropertyNames.Href] = "http://en.wikipedia.org/wiki/Sachin_Tendulkar";
     hhl.FilterProperties[HtmlHyperlink.PropertyNames.Class] = null;
     hhl.WindowTitles.Add("sachine - Bing");
How to minimise no of line in this code.

vikash