Dynamic Test Cases Azure DevOps

Learn to create automatically test cases based on tests in Azure DevOps.

What Is a Dynamic Test Case?

Dynamic test cases are a unique feature in BELLATRIX, where the framework automatically generates test cases in a popular test case management system based on your automated tests. It will populate the title, description, and other necessary properties automatically. Moreover, it will generate human-readable steps and expected results. The most significant benefit is that it will keep up to date your auto-generated test cases over time, no matter what you change in your tests. It is an excellent functionality to allow non-technical people of your company to see what your tests are doing.

Bellatrix

The test case is associated automatically to your automated test.

Bellatrix

The requirements such as stories, epics, bugs are automatically linked.

Bellatrix

The description and preconditions are populated too.

Bellatrix

Configuration

First, you need to install the Bellatrix.DynamicTestCases.AzureDevOps NuGet package to your tests project. Next, you need to enable the Azure DevOps dynamic test cases BELLATRIX extension in your TestInitialize file.

[TestClass]
public class TestsInitialize : WebTest
{
    [AssemblyInitialize]
    public static void AssemblyInitialize(TestContext testContext)
    {
        App.UseUnityContainer();
        App.UseMsTestSettings();
        App.UseBrowserBehavior();
        App.UseLogExecutionBehavior();
        App.UseControlLocalOverridesCleanBehavior();
        App.UseFFmpegVideoRecorder();
        App.UseFullPageScreenshotsOnFail();
        App.UseLogger();
        App.UseElementsBddLogging();
        App.UseHighlightElements();
        App.UseEnsureExtensionsBddLogging();
        App.UseLayoutAssertionExtensionsBddLogging();
        App.UseExceptionAnalysation();
        App.Initialize();
        
		App.UseDynamicTestCases();
    	App.UseAssertExtensionsDynamicTestCases();
    	App.UseEnsureExtensionsDynamicTestCases();
    	App.UseLayoutAssertionExtensionsDynamicTestCases();
    	App.UseAzureDevOpsDynamicTestCases();

        App.AssemblyInitialize();
    }

    [AssemblyCleanup]
    public static void AssemblyCleanUp() => App.Dispose();
}

You need to add the following lines:

App.UseDynamicTestCases();
App.UseAssertExtensionsDynamicTestCases();
App.UseEnsureExtensionsDynamicTestCases();
App.UseLayoutAssertionExtensionsDynamicTestCases();
App.UseAzureDevOpsDynamicTestCases();

They will turn on the feature and will assign listeners to common actions in the framework that will populate the auto-generated test case’s steps and expected results. Next, you need to add a new section in the testFrameworkSettings.json settings file.

"dynamicTestCasesSettings": {
    "isEnabled": "true",
    "url": "https://dev.azure.com/yourOrganization",
    "token": "authenticationToken",
    "organizationName": "yourOrganizationName",
    "projectName": "yourProjectName"
},

You can read the the following article how to generate an authentication token. The last step is to configure the test classes and tests.

[TestClass]
[Browser(BrowserType.Chrome, BrowserBehavior.RestartEveryTime)]
[AzureDevOpsDynamicTestCaseAttribute(AreaPath = "AutomateThePlanet", IterationPath = "AutomateThePlanet", RequirementId = "482")]
public class PageObjectsTests : WebTest
{
   [TestMethod]
   [AzureDevOpsDynamicTestCaseAttribute(
        Description = "Create a purchase of a rocket through the online rocket shop http://demos.bellatrix.solutions/")]
    public void PurchaseRocketWithPageObjects()
    {
		App.TestCases.AddPrecondition($"Navigate to http://demos.bellatrix.solutions/");
        var homePage = App.GoTo<HomePage>();
        homePage.FilterProducts(ProductFilter.Popularity);
        homePage.AddProductById(28);
        homePage.ViewCartButton.Click();

        var cartPage = App.Create<CartPage>();
        cartPage.ApplyCoupon("happybirthday");
        cartPage.ProceedToCheckout.Click();

        var billingInfo = new BillingInfo
                                    {
                                        FirstName = "In",
                                        LastName = "Deepthought",
                                        Company = "Automate The Planet Ltd.",
                                        Country = "Bulgaria",
                                        Address1 = "bul. Yerusalim 5",
                                        Address2 = "bul. Yerusalim 6",
                                        City = "Sofia",
                                        State = "Sofia-Grad",
                                        Zip = "1000",
                                        Phone = "+00359894646464",
                                        Email = "info@bellatrix.solutions",
                                        ShouldCreateAccount = true,
                                        OrderCommentsTextArea = "cool product",
                                    };

        var checkoutPage = App.Create<CheckoutPage>();
        checkoutPage.FillBillingInfo(billingInfo);
        checkoutPage.CheckPaymentsRadioButton.Click();
    }
}
[DynamicTestCase(SuiteId = "8260474")]

On top of your class you need to place the AzureDevOpsDynamicTestCaseAttribute attribute and specify the area, iteration and maybe an ID of a story to be associated.

[AzureDevOpsDynamicTestCaseAttribute(
        Description = "Create a purchase of a rocket through the online rocket shop http://demos.bellatrix.solutions/")]

On top of your class, you need to place the DynamicTestCase attribute and optionally you can specify custom test case name and description.

App.TestCases.AddPrecondition($"Navigate to http://demos.bellatrix.solutions/");

Through TestCases property, you can add preconditions, custom steps, or expected results. You have access to it through the App service or directly in the BELLATRIX page objects.