A question I have had a lot lately is how to test your websites responsive UI design with codedUI.

the main requirement here is that you would be able to check if you can enter values on a specific screen in different browsers in different window sizes.

So starting the browser in CodedUI is simple, you just use the BrowserWindow class and call the Launch method to start the browser in a reliable way. Starting different browsers (Chrome, firefox) is also possible by just setting the BrowserWindow.CurrentBrowser to a value of “chrome” or “firefox” so that is already solved.

the main issue is the size of the browser window. For the responsive UI to show, you need to run a test case in e.g. different screen sizes. Unfortunately there is no method on the BrowserWindow class to set the screen size of the browser.

But there is an easy fix for that.

The BrowserWIndow class has a property called WindowHandle. We can use this property to call a windows API to resize the window.

Here you have a Extension method that I created to fix this issue


The way you make this work in your CodedUI tests is as follows:

Hope this helps you solve this little inconvenience …

CTO at Xpirit, Microsoft Regional Director, Visual studio ALM MVP, Speaker, Pluralsight Author and IT Architect Consultant