Offers a straight forward xml abstraction layer for the registration of Selenium "WebDriverEventListener" event listener for more flexibility.
The project consists of the actual source code for the loading of event listener from xml, an example on how to use it and a gradle file, which can be used to import the code as an project into any gradle supporting IDE (IntelliJ, Eclipse, ...).
Benefits:
- Event listener for different environments by loading different xml files
- Adding/Removing event listener without code changes
- Selenium event listener allow you to do specific stuff at a specific time like
- Documenting actions
- Checking for JS errors
- Removing annoying stuff like sticky toolbars
The code to load the event listener is located in the "src/test/java/hooks" folder. Simply copy the content to your own project and use it however you like. All you need to do is call the "Hooks.registerHooks(seleniumWebDriverObject, "pathToHooks.xml");" method.
In order to use this feature you have to add the following dependencies to your project:
- Selenium server (tested with version 3.3.1)
- Simple XML (tested with version 2.7.1)
The version of the dependencies should not influence this projects behaviour. Look up the gradle file to see the gradle dependencies declarations.
<root>
<Hooks class="java.util.ArrayList">
<hook HookPath="example.hooks.CheckForJavascriptErrorsHook"/>
<hook HookPath="example.hooks.WebDriverActionProtocolHook"/>
</Hooks>
</root>
The root node "root" contains the node "Hooks" under which the list of hooks have to be placed. Each hook is one element and each element contains the attribute "HookPath". The "HookPath" attribute must point to the qualified name of a class, which implements the Selenium "WebDriverEventListener" interface.
This little example project registers two event listener by using the xml mechanism, visits the Bing search page, searches for the term "test" and opens the first search result. The project can be found in the "test" source folder in the "example" package. It consists of the following elements:
- "hooks": This package contains two example event listener.
- "CheckForJavascriptErrorsHook": This hook injects some javascript into the webpage and checks after each action if a javascript error occurred.
- "WebDriverActionProtocolHook": This hook prints actions like button clicks in the output terminal.
- "pages": This package contains a simple page object which represents the the Bing search page.
- "tests": This package contains the "Test" class which executes the test with the hooks from 1.