The next best practice we're going to add to our framework is a Runner Object. The runner object allows us to do a couple of things. Firstly, we can specify whether we want to run with the Classic Runner, which is the way we've been running our tests so far, or the Ultrafast Grid Runner, which we will touch on in the next chapter. Additionally, the runner object keeps track of all of the test results that have been run and allows you access those results from within your framework. In this section, we'll add in a Runner object to our code and then check out the test results that we now have access to.
Let's start by adding a runner object to our code. Let's go over the changes that we made. Firstly, we added in an EyesRunner variable to the top of our code.
Next, we initialized this variable to be an instance of the ClassicRunner. This means that our tests will still continue to run the same way as they have been for now. We'll learn more about other Runner option that allows us to use the Ultrafast Grid in the next chapter.
We then passed our runner object to the constructor of our Eyes instance.
Finally, In the afterAll hook, we added a call to the getAllTestResults() method. This method returns a TestResultsSummary object containing a summary of all the test runs performed with this runner object. For now, we are simply printing out the result summary. Let's go ahead and run our tests again and review what was printed out.
After running our tests, we can see the test results summary printed to the console. For each test that used our runner object, we'll get the test status as well as links to the test results in our Applitools dashboard. In my case, I'm simply printing this information to the console. However, in practice you may want to take these test results and pass them to a test reporter or perform any other analysis on them that you'd like. Perhaps you want to take some extra action if you notice that some tests failed. It's up to you to take this information returned from the runner object and use it as needed.
Additionally, similar to the Configuration object, using a runner can be very useful as your automation framework continues to scale. If you pass the same runner object to all of your test files, you will then be able to tap into the results across your entire test suite rather than just a singular test file. One final note before we wrap up our section on runners, the runner object is also helpful when you're running tests multi-threadedly. You can pass the same runner object to each thread and then access the results for all of them after your threads complete.
Before moving on, let's quickly recap what we just did. We added in a BatchInfo object to our code and successfully grouped together all of our test runs. This will make our test results easier to review on the Applitools Dashboard. We then added a Configuration object to organize our Configuration settings and clean up our code. This will help us as our framework scales to more and more test cases. Lastly, we added a Runner Object to allow us to tap into test results within our framework as well as specify the type of tests we want to run, either Classic or the Ultrafast Grid, which we'll see in the next chapter. All of these best practices that we've added in this section are absolutely critical to writing an automation framework with Applitools. They lay the ground work for scalability, organization and getting the most out of your tests with Applitools. Great job adding in those best practices! Let's head into the last chapter where we'll discuss the Ultrafast Grid.