-
Notifications
You must be signed in to change notification settings - Fork 5
before you run any unit tests
Part of the reason why you set up a custom develop.ucosmic.com host for the project is because it helps with the automated UI testing suite. UCosmic's WebFacts unit test project uses the WebDriver and SpecFlow tools to automate certain UI features, but requires some effort to get running the first time.
WebDriver is capable of automating quite a few HTTP clients. The 3 UCosmic currently uses are the Google Chrome, Internet Explorer, and Firefox web browsers. WebDriver does not yet have an API for Safari, but both Safari and Google Chrome are based on WebKit. In my experience, if a something works right on Chrome, it also works in Safari.
Google Chrome is unlike IE and FF because WebDriver operates it through a special executable file. You can find this file, named chromedriver.exe, in the Etc folder of the source code project.
Locate that file and copy it to your C drive, so that it can be run from the location C:\chromedriver.exe. This is where WebDriver will try to find the file, as evidenced by the dependency injection configuration in the WebFacts app.config file:
<!-- default injection container -->
<container>
<!-- When injecting dependencies for IWebDriver, inject up to 3 browsers -->
<!-- to test with less than 3, temporarily comment out the undesired browsers -->
<register name="ChromeDriver" type="IWebDriver" mapTo="ChromeDriver">
<lifetime type="singleton" />
<constructor>
<param name="chromeDriverDirectory" value="C:\" />
</constructor>
</register>
If you have any wonderful ideas on how to integrate the chromedriver so that developers need not copy it to the C drive, while maintaining the ability to add / remove Chrome from the test suite using dependency injection configuration, please help us out with a fork.
As developers, IE is the bane of our existence. At least Microsoft is starting to recognize this and attempt to make it better. But for now, there are a few special steps you will need to take to make sure WebDriver can play nicely with IE.
The first thing you need to do is open IE, and go to our old friend Tools > Internet Options. On the Security tab of that dialog, you will see 4 zones at the top. In the lower section, there is also a checkbox for "Enable Protected Mode (requires restarting Internet Explorer)". For WebDriver to work with IE, this checkbox setting has to be the same for all 4 zones. So you can have it checked for all 4 zones, or unchecked for all 4 zones (my setup has all 4 checked). Click through each of the zones at the top, make sure all share the same Protected Mode setting, click OK, and restart IE.
The second thing you need to do is allow popups from develop.ucosmic.com. The test suite has code to ensure that browser windows are opened to a certain width, and it does this by opening the site in a popup window. Click Tools > Pop-up Blocker > Pop-up Blocker Settings. Type develop.ucosmic.com into the "Address of website to allow" text box and click Add. Click Close to dismiss the Pop-up Blocker Settings dialog.
Finally, the IE debugger should be disabled during WebFact test runs. To do this, click Tools > Internet Options, then open the Advanced tab. Under "Browsing", make sure both the "Disable script debugging" checkboxes are checked. Seems kind of backwards to me, like you should check the box to enable the debugger, but then again this is IE we're talking about.
As long as you have Firefox installed, that should be all that's needed for WebDriver to work with it. Surprisingly, FF seems to be the most compatible with WebDriver. I have tried running the test suite with FF versions 3, 4, 7, 8 & 9. Although a recent WebDriver release seems to run more slowly with FF, it requires no initial setup or customization that I'm aware of.
The other unit test projects are named differently, as CodeFacts instead of WebFacts. You shouldn't need to do any special setup to run these tests. It is usually a good idea to run the code unit tests separately from the web (automated UI) tests. However because all ultimately use the MSTest framework, you will see them all in the VS Test View (or ReSharper Unit Test Explorer).
<< Back: Extra Credit: Access from another machine | Next: Return to wiki home