Tuesday, September 15, 2015

Execute selenium(C#) tests from command prompt/Batch File

Step 1: Create some test method in your project.


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace UnitTestProject2
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("https://www.google.co.in");
            driver.Quit();
        }
        [TestMethod]
        public void TestMethod2()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("https://in.yahoo.com");
            driver.Quit();
        }
        [TestMethod]
        public void TestMethod3()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.msn.com");
            driver.Quit();
        }
    }
}

Step 2: Create a batch file and write following commands in your batch file.


call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"

vstest.console.exe "C:\Projects\UnitTestProject2\UnitTestProject2\bin\Debug\UnitTestProject2.dll" /Tests:TestMethod1,TestMethod2,TestMethod3  /logger:trx 

Note:

  • Please make sure that path given above are correct.
  • Dll file should be ready at the given path.

Step 3: Execute this batch file and you are done.

No comments:

Post a Comment