Search code examples
c#visual-studio-2013automated-testsui-automationcoded-ui-tests

Some elements take too long to be identified when playing your coded UI test


Let's say I have an automated test case that launches Google.com and searches for a string.

  • Launch google.com
  • Search "Malaysian Airline"

I have all the necessary properties for search field identified so that playback can find this very easy and run through it. But, when I run the test, it takes up to 10-14 seconds only to find the search field in Google.com and then searching in it.

My Code is

BrowserWindow browser = BrowserWindow.Launch("www.google.com");
            UITestControl UISearch = new UITestControl(browser);
            UISearch.TechnologyName = "Web";
            UISearch.SearchProperties.Add("ControlType", "Edit");
            UISearch.SearchProperties.Add("Id", "lst-ib");
            Mouse.Click(UISearch);
            Keyboard.SendKeys(UISearch, "Malaysian Airline");

You guys could also try it out. There are next to nothing else on Google.com still it takes too long to find the element where I have already given possible and the only unique Id.


Solution

  • To avoid robots Google uses a dynamic container that changes/wraps the position of search filed hence your script that once worked won't work again.

    The idea is then to write the test code with full deeper path. i.e. dont just put the xpath to search text filed but also to the Div and container it belongs.