package io.tromba.testdriver;

import io.tromba.testdriver.exceptions.DriverNotFoundException;
import org.openqa.selenium.WebDriver;

import java.util.Set;

/**
 * Base test from which all testdriver tests will inherit.
 */
public class BaseTestdriverTest {

    private TestdriverManager testdriverManager;

    public BaseTestdriverTest(TestdriverManager testdriverManager) {
        this.testdriverManager = testdriverManager;
    }

    public WebDriver driver() {
        Set<String> methods = testdriverManager.getTestMethods();
        StackTraceElement stackTraceElements[] = Thread.currentThread().getStackTrace();
        for (StackTraceElement stackTraceElement: stackTraceElements) {
            String methodName = stackTraceElement.getMethodName();
            if (methods.contains(methodName)) {
                return testdriverManager.getDriver(methodName);
            }
        }
        throw new DriverNotFoundException();
    }
}

@@ -121,24 +121,65 @@
 m.WebDriver;
+%0Aimport org.testng.annotations.Listeners;
 %0A%0Aimport jav
@@ -258,16 +258,78 @@
 it.%0A */%0A
+@Listeners(%7B io.tromba.testdriver.TestdriverListener.class %7D)%0A
 public c

add listener