Search Results for

    Show / Hide Table of Contents

    Web

    This quick start will get you up and running with writing UI tests for a Web application using the ChromeDriver and Legerity.

    Prerequisites

    This quick start requires the following:

    • An understanding of Selenium and working with the WebDriver APIs in .NET
    • A functioning installation of the .NET runtime and SDK

    Install Legerity templates

    Legerity includes project templates to simplify the creation of new UI test projects. To install the templates, run the following command:

    dotnet new -i Legerity.Templates
    

    When creating a project, the template will automatically add to an existing solution file if it can locate one, otherwise you will have to add it manually.

    Create a new Web UI test project with NUnit

    To create a new Web UI test project with NUnit in your existing repository, created a new project folder and from within it, run the following command:

    dotnet new legerity-web
    

    This will create a new Web UI test project with the following structure:

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

    The project will include dependencies for NUnit, Selenium, ChromeDriver, and Legerity for Web.

    Note

    The ChromeDriver is used to demonstrate the use of the Web driver. You can run your UI tests on as many browsers as you like by installing the relevant driver NuGet package into the project and providing additional PlatformOptions to your BaseTestClass. Legerity supports Chrome, Firefox, Opera, Safari, Edge, and Internet Explorer.

    The BaseTestClass class is a simple abstraction used for all of your test classes, based on the Legerity LegerityTestClass. The base test class is a great way to centralize common logic for your tests, to abstract the boilerplate code away from your tests, such as managing the application drivers.

    Note

    The BaseTestClass in this template is currently configured to launch https://www.example.com. This should be updated to launch your own application via the WebApplication constant.

    The SamplePage and SampleTests classes are used to show the basic structure of a page object and test class. In this template, they highlight locating the main h1 tag and verifying the element is shown.

    Note

    The SamplePage and SampleTests classes are intended to be used as a guide for structuring tests. These should be removed and replaced with your own tests and page objects.

    Run the tests

    To run the tests, you can use the following command from the UI test project:

    dotnet test
    

    Chrome should launch at the expected URL and the tests should pass.

    Dive into more

    Now that you have your test project up and running, you can dive deeper into:

    • Using the base test class
    • Creating page objects
    • Creating test classes
    • Locating elements with Legerity by locators
    • Using and creating element wrappers
    • Using custom conditions to wait for elements
    • Improve this Doc
    In This Article
    Back to top Copyright (c) MADE Apps