Simple Steps to Automate UI Testing in ASP.NET Core | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (172).NET Core  (29).NET MAUI  (192)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (209)BoldSign  (12)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (63)Flutter  (131)JavaScript  (219)Microsoft  (118)PDF  (80)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (882)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (49)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (125)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (62)Development  (613)Doc  (7)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (37)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (488)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (41)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (368)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (30)Visual Studio Code  (17)Web  (577)What's new  (313)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Simple Steps to Automate UI Testing in ASP.NET Core

Simple Steps to Automate UI Testing in ASP.NET Core

Testing is an indispensable part of software development. It helps us analyze and evaluate products to ensure they satisfy our requirements. It helps us easily find and fix bugs. But manual testing is not easy. It requires patience, effort, and time to manually test any product.

So instead, we can go for automation!

Automatic testing is a technique in which the testing is carried out by automation tools like Selenium and Cucumber. They will considerably reduce the testing time and enhance efficiency.

In this blog post, we will see how to automate UI testing for a login module in an ASP.NET Core application.

Note: All data should be clear and gathered based on the module for automating UI testing.

Prerequisites

We are going to use the Selenium automation tool for UI testing. So, install the following packages in your application.

Note: Use the latest Chrome browser version to use the latest version of these packages.

Automate UI testing for login module

On the login page, we are going to validate the input fields, such as username and password, as well as the SEO-related items, such as page title and h1 tags.

Automate UI Testing for Login Module in ASP.NET Core App
Automate UI Testing for Login Module in ASP.NET Core App

Step #1: Initialize the login page details.

First, let’s connect to the login page to write the test cases. For each test case, we have to initialize the Chrome driver to navigate to the login page.

So, create a constructor for initialization. Then, define the code for disposing of the web driver after each test case execution.

Refer to the following code example.

public class Login : IDisposable
{
     private readonly IWebDriver _driver;
     public Login()
     {
         _driver = new ChromeDriver();
         _driver.Navigate().GoToUrl("http://localhost:1693/");  // URL should be your target site such as localhost or staging.
     }

     public void Dispose()
     {
         _driver.Quit();
         _driver.Dispose();
     }
}

Step #2: Write test cases.

While writing test cases, use the FindElement method to find the ID, class name, tag name, actual element name, link text, and page details such as page title and URL directly.

Basic scenarios

A login page should have a username field and its input should be in text format.

Refer to the following code example to validate a username.

[Test]
public void CheckUsernameField()
{
     var userNameField = _driver.FindElement(By.CssSelector("Input[type*='text'"));
     Assert.IsNotNull(userNameField);
}

A login page should also have a password field. Refer to the following code example to validate a password.

[Test]
public void CheckPasswordField()
{
   var passwordField = _driver.FindElement(By.CssSelector("Input[type*='password'"));
   Assert.IsNotNull(passwordField);
}

SEO scenarios

A webpage’s title is one of the elements that directly influence the SEO ranking of a page. Let’s validate the presence of the page title with the expected value.

[Test]
public void CheckTitle()
{
   Assert.IsNotEmpty(_driver.Title);
   Assert.IsNotNull(_driver.Title);
   Assert.AreEqual("Login Page", _driver.Title);
}

A login page should have an h1 title that describes the page content briefly. To confirm this, validate the h1 title with the expected value.

Refer to the following code example.

[Test]
public void CheckH1Title()
{
   var h1Text = _driver.FindElement(By.CssSelector("h1"));
   Assert.IsNotNull(h1Text);
   Assert.IsNotNull(h1Text.Text);
   Assert.IsNotEmpty(h1Text.Text);
   Assert.AreEqual("Login", h1Text.Text);
 }

Like these, we can perform testing based on the page details. For example, we can automate the UI testing for validating a submit button, sign-up option, forgot password link, and more.

Output

Now, we are going to use the NUnit testing framework to run the test cases.

After successful execution of the test cases, we will get output like in the following screenshot.

Automating UI Testing in ASP.NET Core App
Automating UI Testing in ASP.NET Core App

GitHub reference

For more details, refer to the example Automate UI testing in ASP.NET Core apps on GitHub.

Conclusion

Thanks for reading! In this blog, we have seen how to automate UI testing in an ASP.NET Core application for a login module. This will help us reduce testing time and enhance efficiency. Try out the steps in this blog post and enjoy hassle-free UI testing automation!

The Syncfusion ASP.NET Core UI controls library, powered by Essential JS 2, is the only suite you will ever need to build an app. It contains over 70 high-performance, lightweight, modular, and responsive UI controls in a single package. Use them to increase your productivity in app development!

If you’re already a Syncfusion user, you can download the product setup. If not, you can download a free 30-day trial to evaluate our products.

You can contact us through our support forumsupport portal, or feedback portal. As always, we are happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed
Scroll To Top