I’m creating multiple UI tests and instead of opening a new instance of Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow I’d like to check to see if a BrowserWindow object is already available – meaning IE is already open on the host machine – and get a handle to it. I’ve found this question but I want my BrowserWindow wrapper class to get the handle and playback has already been initialized at the point of class initialization so the suggested method won’t work.
This is my existing code…
public class uiBrowserWindow : BrowserWindow {
public static void launchUrl(string url) {
Launch(url);
}
}
EDIT
I’ve got it working, it’s not ideal but it works. Is there a better way?
public class uiBrowserWindow : BrowserWindow {
public void launchUrl(string url) {
try {
SearchProperties[PropertyNames.ClassName] = "IEFrame";
NavigateToUrl(new Uri(url));
} catch (Exception) {
Launch(url);
}
}
An exception is thrown if a
BrowserWindowinstance has not been launched when theNavigateToUrl()method is called. I decided to catch the exception and launch the url otherwise onceBrowserWindowis launched just callNavigateToUrl(). This works but takes too long on the first test method when catching the exception. I’ll reassign the answer if a better solution is offered…