Transcript

In the previous chapter, we learned two things. One, how we can use hooks to write setup and teardown code to run before or after our features, scenarios and steps, and two, how to use tags to group features and scenarios, and how to scope hooks, bindings classes and individual step definitions to tags.

In earlier chapters, we learned a lot about the BDD process, how Reqnroll can be used to support that process, and we saw how to get started with Reqnroll and create executable specifications from our requirements and expected behaviour documented in the Gherkin format.

To create proper acceptance tests that interact with your application under test, be it through the graphical user interface, an API, a database or even directly with the code, Reqnroll and the test runner you use to run your feature files and scenarios often are not enough. Reqnroll does not offer any classes, methods or other types of utilities to do this. It is great at turning specifications into executable code, but that's where its responsibilities end.

Therefore, to properly turn our specifications into automated acceptance tests, we will need additional libraries that can help us do exactly that. In this chapter, we are going to look at two different ways of implementing the step definitions we created earlier for our loan application system.

First, we're going to use Selenium WebDriver to turn our specifications into an automated acceptance test that operates on the graphical user interface of our online bank, which is accessible through any modern web browser.

Next, we're going to implement the same scenario as a test at the API level by directly performing the HTTP API calls that the browser would make anyway, using a library called RestAssured .Net.

But let's start by creating a user interface-driven acceptance test using Selenium WebDriver. By the way, instead of Selenium, I could have used Playwright, another very popular open source web UI automation framework, too, as well as other UI automation libraries, for desktop, web or other types of graphical user interfaces.

The Given, When and Then step definitions implement the actions described in the corresponding steps. In the Given, everything is set up to ensure that our user can start filing a loan application. In this case, all they need to do is to log in to the system. In the When step, the actual loan application is submitted, and in the Then step, the loan application result is compared to the expected result in an assertion.

I will not go into further detail about the implementation of the code, and especially that of the Page Objects used here, as that is beyond the scope of this course. Also, once we start to dive deeper into this code, we move away from the responsibilities of Reqnroll and into the responsibilities of our UI automation library.

Next to the step definition code, there's also a BeforeScenario and AfterScenario hook. In this case, the hooks take care of managing the driver object that is used by Selenium to send instructions to our browser. In the BeforeScenario we start a new Chrome instance and maximize the window, and in the AfterScenario method, we close the browser and all connections that Selenium opened to it.

Again, it's good to remember, as we've discussed in the previous chapter, that After hooks like this AfterScenario one are guaranteed to run, even if our acceptance test fails, which means that the browser will always be properly closed in this way.

When we run this scenario outline, with its two examples, we see that two tests are run. One for the loan application of 999 dollars, and one for the loan application for 1 dollar.

Looking at the results, we see that the example for the loan application for 999 dollars passes, but for some reason, the loan application for a loan of a single dollar is denied. It's safe to assume that there's probably some work to be done here, still!

Next, let's have a look at how to implement the same scenario with an API testing and automation library. I have chosen to use RestAssured .Net here for its readability and ease of use, but I could have picked any other C# HTTP library, such as RestSharp, just as easily. To tie the steps in our feature file to the step definitions using RestAssured .Net instead of those using Selenium, all I need to do is change the feature-level tag from userinterface to api.

I've scoped two separate step definitions classes to one of these tags each, as you can see here. When I run the scenario again, Reqnroll will now use the step definitions in this class instead of the one used in the UI automation with Selenium example we just saw earlier.

In these step definitions, I'm performing the same steps as I did at the UI level, but now using APIs: Given performs the login, When performs the loan application submission and Then checks that the response contains the proper result, that is, either approved or denied.

This demonstrates the benefit we discussed earlier of keeping your feature files and scenarios free of implementations details as much as possible. No matter if we write the acceptance test against the user interface or against an API, the scenarios remain the same, as they describe behaviour, not implementation. Additionally, we could have written our acceptance tests directly against the code, or against any other relevant interface, all without having to change the scenarios.

If we now run the same scenarios using our step definitions using the ParaBank API, we see the same test results: one scenario passes, while the other one fails.

There are many more examples that I could have given here, using different libraries and tools, but the gist of the story remains the same: Reqnroll can be combined with many different tools and libraries in the C# automation space to implement acceptance tests driven by your Gherkin feature files and scenarios as you see fit.

In the final chapter of this course, we'll have a look at how to make our scenarios part of a CI/CD pipeline.

The current state of this project is available on GitHub, in the 'chapter9' branch of the repository you see linked in the video right now.



Resources



© 2026 Applitools. All rights reserved. Terms and Conditions Privacy Policy GDPR