Introduced in the Legerity 0.13 release, the framework offers developers an option to get started with UI testing using dotnet new templates. These simplify the setup of your UI test projects, allowing you to focus on what matters, writing tests.

Let’s look at how you can use these templates for your next Windows, Android, iOS, web, or cross-platform application!

What is Legerity?

Before we look at how you can get started with UI testing using Legerity, it’s worth exploring what it is!

Legerity is an automated UI testing framework layer on top of Selenium. It enables the simplification of development for maintainable UI tests by applying best practices and abstracting UI complexities. It does this by providing platform-specific element wrappers, implementing the core interaction logic, and exposing properties that represent those of the controls they represent.

If you find that UI tests take too long to write and ones you’ve worked on have become unmaintainable, Legerity is there to solve those challenges!

Getting the Legerity templates to get started with UI testing

The Legerity project templates are published via NuGet as dotnet new templates that you can install via a command line.

dotnet new -i Legerity.Templates

Once installed, you can create a new Legerity UI testing project by generating a template using one of the platform-specific templates. They will generate the project structure for you including the setup for the AppManager for running your application. It will also automatically add to your solution file if one exists!

It’s worth noting, Legerity is agnostic of the test framework you prefer working with. Currently, the templates will generate UI testing projects using NUnit only.

Create a UI testing project with Legerity

If you’re building applications, generating a template with the following commands will set up the necessary structure for running UI tests against it.

Note, you will need to create a folder to generate your UI test project before running the command.

# For Windows
dotnet new legerity-windows

# For Android
dotnet new legerity-android

# For iOS
dotnet new legerity-ios

# For Web
dotnet new legerity-web

# For Cross-Platform
dotnet new legerity-xplat

When you run any of these commands, you’ll generate a UI testing project with the following structure.

MyProject
├── Elements
├── Pages
│   └── SamplePage.cs
├── Tests
│   └── SampleTests.cs
├── BaseTestClass.cs
├── GlobalUsing.cs
├── MyProject.csproj

Once you have your project setup to write tests, you’ll first want to update the constant values in the BaseTestClass to match your application’s name, ID, or URLs to launch them.

The sample page and sample tests provided are there to give you a starter. They’re a way of understanding the approaches to applying the page object pattern. They also show you how to write your first tests using the design pattern too, launching the application to perform an interaction.

Your next steps

With everything generated and configured, you’re now ready to apply your UI testing knowledge to build out your tests.

I recommend you read the Legerity usage guides which help you understand the fundamentals of the framework. There you will learn more about the AppManager used to manage your application under test, element wrappers and their benefits, and implementing the page object pattern.

Found this article useful?

Thank you for taking the time to read this article. I’m committing to sharing more of my knowledge through my blog and open-source projects! You’ll also catch me in casual conversation on Bluesky and LinkedIn too.

If you enjoy what you see, please consider subscribing to get a notification when new articles go live!


Discover more from James Croft

Subscribe to get the latest posts sent to your email.

James Croft

James is a senior software engineer at Microsoft with over 10 years experience designing and building large-scale, distributed, cloud-native systems. He's deeply experienced in C#, Python, and TypeScript, with specialization in AI agent architectures, retrieval-augmented generation (RAG), and production-grade Azure systems.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.