One of the advantages of the WebdriverIO framework is that it can be extended in various ways to fit your needs and requirements. Custom reporter and custom services provide a way to encapsulate logic into single building blocks and provide them for teams in your organization. It is an excellent way to share code across multiple projects.
In this chapter we want to build a custom service and reporter to improve logging in our framework. The objectives are:
- Create a custom reporter that prints out the duration of a test with its name
- Allow the user of that reporter to specify an option
showState
which if set totrue
shows the state of the test too - Write a custom service and integrate it into your test suite
- Move the code you have written to generate the Allure report into the service and remove it from the config file
- Enhance the service to clean up the old Allure report before the test starts
- Allow the user of that service to specify an option
outputDir
that allows to specify the directory where the report should be stored
Services are custom classes that can interfere with the test using hooks. They have their own scope and can store a certain state over a period of time throughout the test. This allows you to e.g. store the history of commands and their results.
While services and reporters are plugins that can be written by the community and published as NPM packages, they can also just be internal packages to be required in your config and added to the services/reporter list.