Automated Software Testing with SpecFlow in Selenium

SeleniumAutomation TestingTesting Tools

We can have automated software testing with SpecFlow by configuring Selenium in C#. We will use the Visual Studio editor, to develop the Selenium tests using the NUnit framework. Click on Create a new project from the Visual Studio welcome page.

Enter NUnit in the search edit box within the Create a new project window. Then choose the option NUnit Test Project(.NET Core) from the result dropdown. Click on Next to proceed.

Populate the Project name, Location and click on Create.

Once the project is successfully configured, the Setup and Test methods are provided automatically along with the import statement - using NUnit.Framework.

Then click on the Tools menu and choose the option NuGet Package Manager. Next, click on Package Manager Console.

Execute the following commands in the Package Manager Console, for Selenium installation −

Install-Package Selenium.WebDriver
Install-Package Selenium.Firefox.WebDriver
Install-Package Selenium.Chrome.WebDriver

Execute the following commands for NUnit installation in the Package Console −

Install-Package NUnit
Install-Package NUnit3TestAdapter

To verify that all the required packages have been installed successfully, run the command −

Get-Package

Example

Implementation with Selenium WebDriver in C#

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
namespace NUnitTestProject1{
   public class Tests{
      String url = "https://www.tutorialspoint.com/index.htm";
      IWebDriver driver;
      [SetUp]
      public void Setup(){
         //creating object of FirefoxDriver
         driver = new FirefoxDriver("<path of geckodriver.exe>");
      }
      [Test]
      public void Test1(){
         //URL launch
         driver.Navigate().GoToUrl(url);
         Console.WriteLine("Url launched");
      }
      [TearDown]
      public void close_Browser(){
         driver.Close();
      }
   }
}

Output

raja
Published on 07-Apr-2021 12:32:10
Advertisements