Using Selenium C# NUnit console and scheduling a Tests using Task Scheduler 

In one of the recent project, I needed to schedule an unattended test on a daily basis using Selenium Webdriver C#.  As we know, this could be achieved with Jenkins, Azure DevOps(CI/CD pipeline) or similar tools. But these tools need a lot of configuration which might add to an overhead/delay in the project timeline. Searching over the Internet I found that the easiest option for me would be to use the Window Task scheduler to automate the process.

In this blog, we will use the Windows task scheduler to automate execution of Selenium tests , but before we do that, we need to run the tests from the command line(i.e. using Nunit.console).

So without wasting any time, let’s get the first hurdle out of the way i.e. test from the command line.

Step 1: How to use Nunit.Console.

  • Download the NUnit.Console-3.10.0.zip and extract it to a folder.
  • Open the Command line(cmd) as Administrator and Change the directory to the Nunit.Console folder.
  • Run the command below, Note: You may need to modify it based on specifics for your project, but a very basic one would be
>> nunit3-console "F:\youproject\<selenium Project name>.dll"

On successful execution, you should get the output below.

Now that we have understood on how to use the Selenium console and executed a very basic test using NUnit.Console, let’s schedule it using the Window scheduler. However, before we schedule it we would need to create a batch file.

Step 2: Creating a Batch File.

  • A very basic example for the Batch file would be the Code below.
@echo off
::Change change directory command
cd /d C:\Users\clavin.fernandes\Downloads\NUnit.Console-3.10.0\bin\net35
::Start a program, command or batch script 
start nunit3-console nunit3-console "F:\Debug\spsch.dll"
  • Save the batch file as <Selinium.bat>.

Step 3: Run the Batch File Using The Task Scheduler In Windows Server.

  • Open control panel.
  • Go to <Administrative tool >>Task Scheduler.
  •  Create a Basic task to run the batch file and Click Next.
  • Specify, When you want the Task to Start(For this Demo, I will set it to Daily) and set the Start time and click on Next.
  • Specify the action you want the task to perform. For our demo, we will use “Start a program“.
  • Specify the path of the batch file and click on Next.
  • Review the Task scheduler task and click on Finish.

All Done! Its time to test(Run) your task(The part I Enjoy the most).

  • Open Task Scheduler > Select the Task with just created > Under Selected Item, click on Run.

Subscribe to this blog for the latest updates about SharePoint Online, Microsoft Flow, Power Apps, Automation Testing and document conversion and manipulation.

3 thoughts on “Using Selenium C# NUnit console and scheduling a Tests using Task Scheduler 

  1. I have gone through plenty of site and youtube videos…. somehow able to get information but all in pieces..until i find your blog. what a master piece….simple and straight forward method you have described all the detail….well done and Thanks.

    Liked by 1 person

  2. I don’t have the .dll file of the project in the project/bin/debug folder.
    Please let me know the reason for this .

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s