@Override protected void configure() { bind(ReportEntryLogger.class).to(ReportEntryLoggerImpl.class); bind(TestEventCollector.class).to(TestEventCollectorImpl.class); bind(ReportingHandler.ACTIVE_REPORTERS).toProvider(ReporterProvider.class).in(Singleton.class); SubreportInterceptor subreportInterceptor = new SubreportInterceptor(); requestInjection(subreportInterceptor); bindInterceptor(Matchers.any(), Matchers.annotatedWith(Subreport.class), subreportInterceptor); Multibinder<WebDriverEventListener> webDriverListenerBinder = Multibinder.newSetBinder(binder(), WebDriverEventListener.class); webDriverListenerBinder.addBinding().to(WebDriverLogger.class); Multibinder<ProxyEventListener> proxyListenerBinder = Multibinder.newSetBinder(binder(), ProxyEventListener.class); proxyListenerBinder.addBinding().to(ProxyLogger.class); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { for (Listener l: listeners) { boolean isInvoked = false; if (method.getDeclaringClass().isAssignableFrom(l.getClass())) { method.invoke(l, args); isInvoked = true; } if (isInvoked) { continue; } Method webDriverEventListenerMethod = findElementInWebDriverEventListener(method); if (webDriverEventListenerMethod != null && WebDriverEventListener.class.isAssignableFrom(l.getClass())) { webDriverEventListenerMethod.invoke(l, args); } } return null; }
private boolean isExceptionFromWebDriverEventListerAfterXYHook(Throwable throwable) { if (throwable instanceof StaleElementReferenceException) { for (StackTraceElement stackTraceElement : throwable.getStackTrace()) { String className = stackTraceElement.getClassName(); Class<?> clazz = null; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { log.debug(e.getMessage(), e); } // some sun classes are not accessible if (clazz == null) { continue; } if (WebDriverEventListener.class.isAssignableFrom(clazz) && stackTraceElement.getMethodName().startsWith("after")) { return true; } } } return false; }
@Test @SuppressWarnings("unchecked") public void shouldBeWrappedInEventFiringWebdriver() throws Throwable { AbstractWebDriverEventListener eventListener = new AbstractWebDriverEventListener() { }; driverService = new DriverService(DriverType.PHANTOMJS, eventListener); driverService.before(); WebDriver driver = driverService.getDriver(); assertThat(driver).isInstanceOf(EventFiringWebDriver.class); EventFiringWebDriver eventFiringWebDriver = (EventFiringWebDriver) driver; Field field = EventFiringWebDriver.class.getDeclaredField("eventListeners"); field.setAccessible(true); assertThat(((List<WebDriverEventListener>) field.get(eventFiringWebDriver)).size()).isEqualTo(1); }
@Inject protected HtmlUnitDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners, final HtmlUnitWebDriverParams webDriverParams, final HtmlUnitSSLParams sslParams, final BrowserVersion browserVersion, final AjaxController ajaxController, final Map<String, CredentialsProvider> credentialsProviderMap, final Provider<DumpFileCreator> htmlFileCreatorProvider, @ModuleArchiveDir final Provider<File> moduleArchiveDirProvider, final Provider<Set<WebWindowListener>> listenersProvider, final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) { super(config, eventListeners, capabilitiesMap, eventBus); this.webDriverParams = webDriverParams; this.sslParams = sslParams; this.browserVersion = browserVersion; this.ajaxController = ajaxController; this.credentialsProviderMap = credentialsProviderMap; this.htmlFileCreatorProvider = htmlFileCreatorProvider; this.moduleArchiveDirProvider = moduleArchiveDirProvider; this.listenersProvider = listenersProvider; }
protected DelegatingWebDriver(final WebDriver delegate) { // copy/pasted from EventFiringWebDriver Class<?>[] allInterfaces = extractInterfaces(delegate); this.delegate = (WebDriver) Proxy.newProxyInstance( WebDriverEventListener.class.getClassLoader(), allInterfaces, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("getWrappedDriver".equals(method.getName())) { return delegate; } try { return method.invoke(delegate, args); } catch (InvocationTargetException e) { onExceptionFromAdditionalInterfaceProxyInvocation(e); throw e.getTargetException(); } } }); }
@Override protected void configure() { Multibinder.newSetBinder(binder(), WebDriverEventListener.class); Multibinder<WebDriverClosedListener> closedListeners = Multibinder .newSetBinder(binder(), WebDriverClosedListener.class); closedListeners.addBinding().to(FrameSwitcher.class); closedListeners.addBinding().to(ProxyCloser.class); }
private Method findElementInWebDriverEventListener(Method m) { try { return WebDriverEventListener.class.getMethod(m.getName(), m.getParameterTypes()); } catch (NoSuchMethodException e) { return null; } }
protected WebDriver handleListeners(WebDriver driver) { ArrayList<WebDriverEventListener> listeners = config.getWebDriverListeners(); if (listeners != null && listeners.size() > 0) { for (int i = 0; i < config.getWebDriverListeners().size(); i++) { driver = new CustomEventFiringWebDriver(driver).register(listeners.get(i)); } } return driver; }
public DriverService(DriverType drivertype, WebDriverEventListener... listeners) { this.drivertype = drivertype; this.listeners = Arrays.asList(listeners); try { this.configuration = drivertype.getDriverConfigurationClass().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } }
@Override public WebDriver enhance(WebDriver instance, Class<? extends Annotation> qualifier) { //System.out.println("Adding AngularJS capabilities to WebDriver"); instance.manage().timeouts().setScriptTimeout(2, TimeUnit.SECONDS); EventFiringWebDriver driver = new EventFiringWebDriver(instance); WebDriverEventListener listener = new AngularJSEventHandler(); driver.register(listener); return driver; }
@Override protected void doConfigureWebDriverModule() { // Create an extra binding for the WebDriverEventListener using a qualifier annotation. // The Multibinder for the event listener will then link to this binding so it may be overridden. // This is necessary because multibindings themselves cannot be overridden. bind(WebDriverEventListener.class).annotatedWith(DefaultWebDriverEventListener.class).to( JFunkWebDriverEventListener.class); bindWebDriverEventListener().to(Key.get(WebDriverEventListener.class, DefaultWebDriverEventListener.class)); bind(BrowserVersion.class).toInstance(BrowserVersion.BEST_SUPPORTED); bind(AjaxController.class).to(NicelyResynchronizingAjaxController.class); bind(DumpFileCreator.class); bindWebDriver(WebConstants.WEBDRIVER_HTMLUNIT, HtmlUnitDriverProvider.class); bindWebDriver(WebConstants.WEBDRIVER_FIREFOX, FirefoxDriverProvider.class); bindWebDriver(WebConstants.WEBDRIVER_CHROME, ChromeDriverProvider.class); bindWebDriver(WebConstants.WEBDRIVER_INTERNET_EXPLORER, InternetExplorerDriverProvider.class); bindWebDriver(WebConstants.WEBDRIVER_REMOTE, RemoteWebDriverProvider.class); bindDisposable(Key.get(WebDriver.class)).to(WebDriverDisposable.class); bind(new TypeLiteral<Map<String, DesiredCapabilities>>() { // }).toProvider(CapabilitiesProvider.class); bind(WebDriver.class).toProvider(WebDriverProvider.class).in(scopeAnnotationClass); bind(WebElementFinder.class).toProvider(WebElementFinderProvider.class).in(scopeAnnotationClass); bind(FormInputHandler.class).toProvider(FormInputHandlerProvider.class).in(scopeAnnotationClass); bind(WebDriverTool.class).in(scopeAnnotationClass); }
public BaseWebDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners, final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) { this.config = config; this.eventListeners = eventListeners; this.capabilitiesMap = capabilitiesMap; this.eventBus = eventBus; }
@Override public WebDriver get() { String webDriverKey = config.get(WebConstants.WEBDRIVER_KEY); log.info("Creating new WebDriver instance with key '{}'...", webDriverKey); DesiredCapabilities capabilities = capabilitiesMap.get(webDriverKey); // we must disable WebDriver's overlapping check to be able to use our own topMostElementCheck flag capabilities.setCapability("overlappingCheckDisabled", true); //TODO this flag tells FirefoxDriver whether to run in legacy mode or in Marionette mode // => remove it, once the W3C actions API is correctly implemented in GeckoDriver Boolean isWebdriverFirefoxMarionette = config.getBoolean(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE); capabilities.setCapability(FirefoxDriver.MARIONETTE, isWebdriverFirefoxMarionette); // post event so users can customize capabilities eventBus.post(new BeforeWebDriverCreationEvent(webDriverKey, capabilities)); WebDriver webDriver = createWebDriver(capabilities); checkState(!(webDriver instanceof EventFiringWebDriver), "WebDrivers must not be wrapped explicitly into an EventFiringWebDriver. This is implicitly done by jFunk."); long implicitWaitSeconds = config.getLong(WebConstants.WEBDRIVER_IMPLICIT_WAIT_SECONDS, 0L); if (implicitWaitSeconds > 0) { webDriver.manage().timeouts().implicitlyWait(implicitWaitSeconds, TimeUnit.SECONDS); } EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(webDriver); for (WebDriverEventListener listener : eventListeners) { eventFiringWebDriver.register(listener); } return eventFiringWebDriver; }
@Override protected final void doConfigure() { webDriverEventListenersBinder = Multibinder.newSetBinder(binder(), WebDriverEventListener.class); webWindowListenersBinder = Multibinder.newSetBinder(binder(), WebWindowListener.class); doConfigureWebDriverModule(); }
/** * Reads 'driver_event_listeners' configuration property and initializes appropriate array of driver event listeners. * * @return array of driver listeners */ private static WebDriverEventListener [] getEventListeners() { List<WebDriverEventListener> listeners = new ArrayList<>(); try { String listenerClasses = Configuration.get(Parameter.DRIVER_EVENT_LISTENERS); if(!StringUtils.isEmpty(listenerClasses)) { for(String listenerClass : listenerClasses.split(",")) { Class<?> clazz = Class.forName(listenerClass); if(IConfigurableEventListener.class.isAssignableFrom(clazz)) { IConfigurableEventListener listener = (IConfigurableEventListener) clazz.newInstance(); if(listener.enabled()) { listeners.add(listener); LOGGER.debug("Webdriver event listener registered: " + clazz.getName()); } } } } } catch (Exception e) { LOGGER.error("Unable to register webdriver event listeners: " + e.getMessage()); } return listeners.toArray(new WebDriverEventListener[listeners.size()]); }
@Override public MockedSeleniumProvider addWebDriverEventListener(WebDriverEventListener listener) { return this; }
@Override public <T extends WebDriverEventListener & TestRule> SeleniumRule<P, D> addWebDriverEventListener(T listener) { defaultSeleniumProvider.addWebDriverEventListener(listener); return secondOuterRule(listener); }
@Override public <T extends WebDriverEventListener & TestRule> P addWebDriverEventListener(T listener) { eventListeners.add(listener); return getThis(); }
public ArrayList<WebDriverEventListener> getWebDriverListeners() { return webDriverListeners; }
public void setWebDriverListeners(final ArrayList<WebDriverEventListener> webDriverListeners) { this.webDriverListeners = webDriverListeners; }
public DriverService(DriverType drivertype, List<WebDriverEventListener> listeners, DriverConfiguration configuration) { this.drivertype = drivertype; this.listeners = listeners; this.configuration = configuration; }
public void startNode(GridNode node) { try { countDownLatch = new CountDownLatch(1); log.debug("Launching node {}", node.getHost()); node.startSsh(); final String chromeDriverSource = System.getProperty("webdriver.chrome.driver"); final Class<?>[] classpath = { GridLauncher.class, ImmutableList.class, HttpListener.class, NetworkUtils.class, WebDriverException.class, LogFactory.class, HttpServlet.class, ChromeDriver.class, FirefoxDriver.class, JsonElement.class, HttpEntity.class, HttpClient.class, WebDriverEventListener.class, ExecuteWatchdog.class }; // OverThere SCP need absolute path, so home path must be known String remoteHome = node.getHome(); final String remoteFolder = remoteHome + "/" + REMOTE_FOLDER; final String remoteChromeDriver = remoteFolder + "/chromedriver"; final String remoteScript = node.getTmpFolder() + "/" + LAUNCH_SH; final String remotePort = String.valueOf(node.getSshConnection().getFreePort()); if (!node.getSshConnection().exists(remoteFolder) || node.isOverwrite()) { node.getSshConnection().execAndWaitCommand("mkdir", "-p", remoteFolder); } if (!node.getSshConnection().exists(remoteChromeDriver) || node.isOverwrite()) { node.getSshConnection().scp(chromeDriverSource, remoteChromeDriver); node.getSshConnection().execAndWaitCommand("chmod", "+x", remoteChromeDriver); } String cp = ""; for (Class<?> clazz : classpath) { if (!cp.isEmpty()) { cp += ":"; } String jarSource = getJarPath(clazz).getAbsolutePath(); String remoteSeleniumJar = remoteFolder + "/" + getJarPath(clazz).getName(); cp += remoteSeleniumJar; if (!node.getSshConnection().exists(remoteSeleniumJar) || node.isOverwrite()) { node.getSshConnection().scp(jarSource, remoteSeleniumJar); } } // Script is always overwritten createRemoteScript(node, remotePort, remoteScript, remoteFolder, remoteChromeDriver, cp, node.getBrowserType(), node.getMaxInstances()); // Launch node node.getSshConnection().execCommand(remoteScript); // Wait to be available for Hub waitForNode(node.getHost(), remotePort); // Set started flag to true node.setStarted(true); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
@Inject public RemoteWebDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners, final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) { super(config, eventListeners, capabilitiesMap, eventBus); }
protected LinkedBindingBuilder<WebDriverEventListener> bindWebDriverEventListener() { return webDriverEventListenersBinder.addBinding(); }
@Inject public InternetExplorerDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners, final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) { super(config, eventListeners, capabilitiesMap, eventBus); }
@Inject protected FirefoxDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners, final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) { super(config, eventListeners, capabilitiesMap, eventBus); }
@Inject protected ChromeDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners, final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) { super(config, eventListeners, capabilitiesMap, eventBus); }
/** * Registers a new instance of {@link WebDriverEventListener} {@literal &} {@link TestRule} to the created * {@link SeleniumProvider}. * * @param listener Implementation of {@link WebDriverEventListener} {@literal &} {@link TestRule} added to the list of listeners * @return the provider itself to make method chaining possible */ <T extends WebDriverEventListener & TestRule> P addWebDriverEventListener(T listener);