Java 类org.openqa.selenium.support.events.WebDriverEventListener 实例源码

项目:bobcat    文件:ReporterModule.java   
@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);

}
项目:menggeqa    文件:ListenerInvocationHandler.java   
@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;
}
项目:de.lgohlke.selenium-webdriver    文件:ErrorLoggingWebDriverEventListener.java   
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;
}
项目:de.lgohlke.selenium-webdriver    文件:DriverServiceTest.java   
@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);
}
项目:jfunk    文件:HtmlUnitDriverProvider.java   
@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;
}
项目:webdriver-runner    文件:DelegatingWebDriver.java   
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();
                    }
                }
            });
}
项目:bobcat    文件:WebdriverModule.java   
@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);
}
项目:menggeqa    文件:ListenerInvocationHandler.java   
private Method findElementInWebDriverEventListener(Method m) {
    try {
        return WebDriverEventListener.class.getMethod(m.getName(), m.getParameterTypes());
    } catch (NoSuchMethodException e) {
        return null;
    }
}
项目:seleniumtestsframework    文件:WebUIDriver.java   
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;
}
项目:de.lgohlke.selenium-webdriver    文件:DriverService.java   
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);
    }
}
项目:JavaIncrementalParser    文件:AngularJSDroneExtension.java   
@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;
}
项目:jfunk    文件:ScopingWebDriverModule.java   
@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);
}
项目:jfunk    文件:BaseWebDriverProvider.java   
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;
}
项目:jfunk    文件:BaseWebDriverProvider.java   
@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;
}
项目:jfunk    文件:BaseWebDriverModule.java   
@Override
protected final void doConfigure() {
    webDriverEventListenersBinder = Multibinder.newSetBinder(binder(), WebDriverEventListener.class);
    webWindowListenersBinder = Multibinder.newSetBinder(binder(), WebWindowListener.class);

    doConfigureWebDriverModule();
}
项目:carina    文件:DriverFactory.java   
/**
 * 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()]);
}
项目:willtest    文件:MockedSeleniumProvider.java   
@Override
public MockedSeleniumProvider addWebDriverEventListener(WebDriverEventListener listener) {
    return this;
}
项目:willtest    文件:SeleniumRule.java   
@Override
public <T extends WebDriverEventListener & TestRule> SeleniumRule<P, D> addWebDriverEventListener(T listener) {
    defaultSeleniumProvider.addWebDriverEventListener(listener);
    return secondOuterRule(listener);
}
项目:willtest    文件:AbstractSeleniumProvider.java   
@Override
public <T extends WebDriverEventListener & TestRule> P addWebDriverEventListener(T listener) {
    eventListeners.add(listener);
    return getThis();
}
项目:seleniumtestsframework    文件:DriverConfig.java   
public ArrayList<WebDriverEventListener> getWebDriverListeners() {
    return webDriverListeners;
}
项目:seleniumtestsframework    文件:DriverConfig.java   
public void setWebDriverListeners(final ArrayList<WebDriverEventListener> webDriverListeners) {
    this.webDriverListeners = webDriverListeners;
}
项目:de.lgohlke.selenium-webdriver    文件:DriverService.java   
public DriverService(DriverType drivertype, List<WebDriverEventListener> listeners, DriverConfiguration configuration) {
    this.drivertype = drivertype;
    this.listeners = listeners;
    this.configuration = configuration;
}
项目:kurento-java    文件:GridHandler.java   
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);
  }
}
项目:jfunk    文件:RemoteWebDriverProvider.java   
@Inject
public RemoteWebDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners,
        final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) {
    super(config, eventListeners, capabilitiesMap, eventBus);
}
项目:jfunk    文件:BaseWebDriverModule.java   
protected LinkedBindingBuilder<WebDriverEventListener> bindWebDriverEventListener() {
    return webDriverEventListenersBinder.addBinding();
}
项目:jfunk    文件:InternetExplorerDriverProvider.java   
@Inject
public InternetExplorerDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners,
        final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) {
    super(config, eventListeners, capabilitiesMap, eventBus);
}
项目:jfunk    文件:FirefoxDriverProvider.java   
@Inject
protected FirefoxDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners,
        final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) {
    super(config, eventListeners, capabilitiesMap, eventBus);
}
项目:jfunk    文件:ChromeDriverProvider.java   
@Inject
protected ChromeDriverProvider(final Configuration config, final Set<WebDriverEventListener> eventListeners,
        final Map<String, DesiredCapabilities> capabilitiesMap, final EventBus eventBus) {
    super(config, eventListeners, capabilitiesMap, eventBus);
}
项目:willtest    文件:SeleniumProvider.java   
/**
 * 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);