Class EventFiringDecorator

  • @Beta
    public class EventFiringDecorator
    extends WebDriverDecorator
    This decorator creates a wrapper around an arbitrary WebDriver instance that notifies registered listeners about events happening in this WebDriver and derived objects, such as WebElements and Alert.

    Listeners should implement WebDriverListener. It supports three types of events:

    • "before"-event: a method is about to be called;
    • "after"-event: a method was called successfully and returned some result;
    • "error"-event: a method was called and thrown an exception.
    To use this decorator you have to prepare a listener, create a decorator using this listener, decorate the original WebDriver instance with this decorator and use the new WebDriver instance created by the decorator instead of the original one: WebDriver original = new FirefoxDriver(); WebDriverListener listener = new MyListener(); WebDriver decorated = new EventFiringDecorator(listener).decorate(original); decorated.get(""); WebElement header = decorated.findElement(By.tagName("h1")); String headerText = header.getText();

    The instance of WebDriver created by the decorator implements all the same interfaces as the original driver.

    A listener can subscribe to "specific" or "generic" events (or both). A "specific" event correspond to a single specific method, a "generic" event correspond to any method called in a class or in any class.

    To subscribe to a "specific" event a listener should implement a method with a name derived from the target method to be watched. The listener methods for "before"-events receive the parameters passed to the decorated method. The listener methods for "after"-events receive the parameters passed to the decorated method as well as the result returned by this method. WebDriverListener listener = new WebDriverListener() {

    • Constructor Detail

      • EventFiringDecorator

        public EventFiringDecorator​(WebDriverListener... listeners)
    • Method Detail

      • afterCall

        public void afterCall​(Decorated<?> target,
                              java.lang.reflect.Method method,
                              java.lang.Object[] args,
                              java.lang.Object result)
        afterCall in class WebDriverDecorator
      • onError

        public java.lang.Object onError​(Decorated<?> target,
                                        java.lang.reflect.Method method,
                                        java.lang.Object[] args,
                                        java.lang.reflect.InvocationTargetException e)
                                 throws java.lang.Throwable
        onError in class WebDriverDecorator