Monday, 20 July 2015

Schedule Coded UI Test to Execute At a Specific Time

The best way I have found to accomplish this is to create a .bat file which executes the test using the mstest command line tool, and setting this .bat to execute at a specific time using task scheduler. I currently do this daily on a project I am working on.
Here are the steps oulined to execute a .bat driven Coded UI test at a specified time.

Create a .bat similar to the following:
set mstestPath="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE"
 %mstestpath%\mstest /testcontainer:AutomatedUITest.dll  /resultsfile:TestOutput.trx
Test your script by double-clicking the .bat and assure that the test is properly executing.

Assuming you name this .bat “TestRunner.bat”, you would then open Task Scheduler (pre-installed on Windows, type “Task” into the search bar to locate). You will see Task Scheduler (local) in the upper left of the window. Right-click, then select create Task. Give the task a name and choose appropriate security settings. Click the Triggers tab, and assign when you wish the test to auto-execute. In this screen you can set the appropriate time to run. Now click the Actions tab, click new and assign your script “TestRunner.bat” to execute and any parameters you may wish to feed to your script. Now choose settings and allow the test to run on demand. Ensure your test is executing properly by clicking the Task Scheduler Library underneath Task Scheduler (local), locate your task, right-click and choose run. If everything executes as expected, you can rest assured that your scheduled task will properly execute at the time(s) you have designated.