| .. | ||
| ESuite.UI.E2E | ||
| .gitattributes | ||
| .gitignore | ||
| azure-pipelines.yml | ||
| DependencyConfig.cs | ||
| ESuite.UI.E2E.sln | ||
| nuget.config | ||
| README.md | ||
Automated UI End to End(E2E) tests using ReqnRoll BDD, MSTest, and Chrome
Prerequisites
- Visual Studio with ReqnRoll extension installed
- Chrome browser installed
- .NET Core SDK (please take a look of required version)
Project Setup
-
Create a new SpecFlow project in Visual Studio.
-
Install the required NuGet packages:
- Reqnroll
- Reqnroll.MSTest
- Selenium.WebDriver
- Selenium.WebDriver.ChromeDriver
Writing the Test. Example
-
Create a new feature file named "Login.feature" in the "Features" folder of your SpecFlow project.
-
Add the following scenario to the "Login.feature" file:
Feature: User Authentication
In order to access my account
As a user
I want to be able to authenticate in the system
Scenario: Successful User Login
Given I am on the login page
When I enter valid credentials
And I click the login button
Then I should be redirected to the home page
-
Right-click on the "Login.feature" file and choose "Generate Step Definitions."
-
Select the class where you want to generate the step definitions or create a new class.
Writing the Test Code
-
Open the step definition file corresponding to the "Login.feature" scenario.
-
Add the following code to the step definition file:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TechTalk.SpecFlow;
namespace YourNamespace
{
[Binding]
public class LoginSteps
{
private IWebDriver driver;
[Given(@"I am on the login page")]
public void GivenIAmOnTheLoginPage()
{
driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://localhost:3000/login");
}
[When(@"I enter valid credentials")]
public void WhenIEnterValidCredentials()
{
// Enter valid credentials in the login fields here
var usernameField = driver.FindElement(By.Id("username"));
usernameField.SendKeys("yourusername");
var passwordField = driver.FindElement(By.Id("password"));
passwordField.SendKeys("yourpassword");
}
[When(@"I click the login button")]
public void WhenIClickTheLoginButton()
{
var loginButton = driver.FindElement(By.Id("login-button"));
loginButton.Click();
}
[Then(@"I should be redirected to the home page")]
public void ThenIShouldBeRedirectedToTheHomePage()
{
Assert.AreEqual("http://localhost:3000/", driver.Url);
}
[AfterScenario]
public void AfterScenario()
{
driver.Quit();
}
}
}
Running the Test
-
Build your ReqnRoll project to compile the code.
-
In Visual Studio, open the "Test Explorer" window.
-
Click the "Run All Tests" button to execute the authentication test.