Logo of Techdays 2014

Techdays 2014 – Automated crossbrowser testing with CodedUI tests

Presented by Marcel de Vries. Was an interesting presentation with a overview of CodedUI tests and the UIMap. There’s loads of information available on-line, so I wont repeat that here. Some bits that did stick in my mind.

CodedUI webtests use Selenium as driver for Internet Explorer. You’ll need at least Visual Studio 2012 with update 1. You can also get support for Firefox or Chrome by installing the “Selenium components for Cross Browser Testing” Visual Studio Add-on/Extension. This Add-on will require you to install .Net 3.5 first.

You can select which browser you want to use with the following code

BrowserWindow.CurrentBrowser = "IE";
BrowserWindow.CurrentBrowser = "Chrome";
BrowserWindow.CurrentBrowser = "Firefox";

When you run your tests, you might be surprised that by default they run quite slow. This is due to the fact, that the framework will wait for all outstanding events and AJAX requests on the webpage to be fully complete. Classic Selenium only waits for a pageload to be complete and you’d explicitly have to write code using WebDriverWait to ensure your test isn’t going faster than your webpage can update itself. Microsoft’s framework can be configured to wait as much or as little as you want

//Wait until all actions are complete
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;

//Only wait for render of the initial DOM 
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly; 

//Only wait for pageload to be complete
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;   

The Page Object pattern is a good way of keeping your testcases maintainable. It introduces a nice separation between what a testcase wants to do and how it finds and uses the various controls such as text boxes, links and images.