WinCoder Blog

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.


See: Running Automated Tests from the Command Line

2 comments for “Schedule Coded UI Test to Execute At a Specific Time

  1. May 30, 2012 at 2:09 pm

    How did you get mstest to interact with desktop when lauched from scheduled task? For me this is not working when I’m logged off from machine, this only works when user is logged on.

    • May 30, 2012 at 2:23 pm

      Good question, to get around this I used Mouse Jiggler ( to keep my machine from locking down. It is suggested that you create a safe functional account if you are to leave a machine logged in and unlocked in an enterprise environment. As far as I know, there is not way to unlock the desktop via a scheduled task.

Leave a Reply

Your email address will not be published. Required fields are marked *