org.openqa.selenium.support.events.WebDriverEventListener Java Examples
The following examples show how to use
org.openqa.selenium.support.events.WebDriverEventListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DriverFactory.java From carina with Apache License 2.0 | 6 votes |
/** * Reads 'driver_event_listeners' configuration property and initializes * appropriate array of driver event listeners. * * @return array of driver listeners */ private static WebDriverEventListener[] getEventListeners(TestArtifactType vncArtifact) { List<WebDriverEventListener> listeners = new ArrayList<>(); try { //explicitely add default carina com.qaprosoft.carina.core.foundation.webdriver.listener.ScreenshotEventListener DriverListener driverListener = new DriverListener(vncArtifact); listeners.add(driverListener); String listenerClasses = Configuration.get(Parameter.DRIVER_EVENT_LISTENERS); if (!StringUtils.isEmpty(listenerClasses)) { for (String listenerClass : listenerClasses.split(",")) { Class<?> clazz = Class.forName(listenerClass); if (WebDriverEventListener.class.isAssignableFrom(clazz)) { WebDriverEventListener listener = (WebDriverEventListener) clazz.newInstance(); listeners.add(listener); LOGGER.debug("Webdriver event listener registered: " + clazz.getName()); } } } } catch (Exception e) { LOGGER.error("Unable to register webdriver event listeners: " + e.getMessage(), e); } return listeners.toArray(new WebDriverEventListener[listeners.size()]); }
Example #2
Source File: MouseActionsTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void testClickViaJavascript() { when(webDriverProvider.get()).thenReturn(webDriver); WebElement body = mock(WebElement.class); WebDriverEventListener webDriverEventListener = mock(WebDriverEventListener.class); List<WebDriverEventListener> webDriverEventListeners = new ArrayList<>(); webDriverEventListeners.add(webDriverEventListener); mouseActions.setWebDriverEventListeners(webDriverEventListeners); when(webDriver.findElement(BODY_XPATH_LOCATOR)).thenReturn(body); ClickResult result = mouseActions.clickViaJavascript(webElement); verify(webDriverEventListener).beforeClickOn(webElement, webDriver); verify(webDriverEventListener).afterClickOn(webElement, webDriver); assertFalse(result.isNewPageLoaded()); verify(alertActions).waitForAlert(webDriver); verify(eventBus).post(any(PageLoadEndEvent.class)); verifyNoInteractions(webUiContext); }
Example #3
Source File: WebdriverModule.java From bobcat with Apache License 2.0 | 6 votes |
@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); install(new FactoryModuleBuilder() .implement(ClosingAwareWebDriver.class, ClosingAwareWebDriverWrapper.class) .build(ClosingAwareWebDriverFactory.class)); bind(WebDriver.class).toProvider(WebDriverProvider.class); bind(Actions.class).toProvider(ActionsProvider.class); bind(Capabilities.class).toProvider(CapabilitiesProvider.class); bind(JavascriptExecutor.class).toProvider(JavascriptExecutorProvider.class); }
Example #4
Source File: ListenerInvocationHandler.java From java-client with Apache License 2.0 | 6 votes |
@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; }
Example #5
Source File: MouseActionsTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void shouldNotProcessAlertsAfterClickForElectronApps() { when(webDriverProvider.get()).thenReturn(webDriver); WebElement body = mock(WebElement.class); WebDriverEventListener webDriverEventListener = mock(WebDriverEventListener.class); mouseActions.setWebDriverEventListeners(List.of(webDriverEventListener)); when(webDriver.findElement(BODY_XPATH_LOCATOR)).thenReturn(body); when(webDriverManager.isElectronApp()).thenReturn(true); ClickResult result = mouseActions.clickViaJavascript(webElement); verify(webDriverEventListener).beforeClickOn(webElement, webDriver); verify(webDriverEventListener).afterClickOn(webElement, webDriver); assertFalse(result.isNewPageLoaded()); verifyNoInteractions(webUiContext, alertActions, eventBus); }
Example #6
Source File: WebUIDriver.java From seleniumtestsframework with Apache License 2.0 | 5 votes |
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; }
Example #7
Source File: ListenerInvocationHandler.java From java-client with Apache License 2.0 | 5 votes |
private Method findElementInWebDriverEventListener(Method m) { try { return WebDriverEventListener.class.getMethod(m.getName(), m.getParameterTypes()); } catch (NoSuchMethodException e) { return null; } }
Example #8
Source File: DefaultListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public <X> void beforeGetScreenshotAs(OutputType<X> target) { ((WebDriverEventListener) dispatcher).beforeGetScreenshotAs(target); }
Example #9
Source File: EventFiringTouch.java From selenium with Apache License 2.0 | 4 votes |
public EventFiringTouch(WebDriver driver, WebDriverEventListener dispatcher) { this.driver = driver; this.dispatcher = dispatcher; this.touchScreen = ((HasTouchScreen) this.driver).getTouch(); }
Example #10
Source File: EventFiringMouse.java From selenium with Apache License 2.0 | 4 votes |
public EventFiringMouse(WebDriver driver, WebDriverEventListener dispatcher) { this.driver = driver; this.dispatcher = dispatcher; this.mouse = ((HasInputDevices) this.driver).getMouse(); }
Example #11
Source File: EventFiringKeyboard.java From selenium with Apache License 2.0 | 4 votes |
public EventFiringKeyboard(WebDriver driver, WebDriverEventListener dispatcher) { this.driver = driver; this.dispatcher = dispatcher; this.keyboard = ((HasInputDevices) this.driver).getKeyboard(); }
Example #12
Source File: DefaultListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public void afterSwitchToWindow(String windowName, WebDriver driver) { ((WebDriverEventListener) dispatcher).afterSwitchToWindow(windowName, driver); }
Example #13
Source File: DefaultListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public void beforeSwitchToWindow(String windowName, WebDriver driver) { ((WebDriverEventListener) dispatcher).beforeSwitchToWindow(windowName, driver); }
Example #14
Source File: DefaultListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public void beforeAlertDismiss(WebDriver driver) { ((WebDriverEventListener) dispatcher).beforeAlertDismiss(driver); }
Example #15
Source File: DefaultListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public void afterAlertDismiss(WebDriver driver) { ((WebDriverEventListener) dispatcher).afterAlertDismiss(driver); }
Example #16
Source File: DefaultListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public void afterAlertAccept(WebDriver driver) { ((WebDriverEventListener) dispatcher).afterAlertAccept(driver); }
Example #17
Source File: DefaultListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public void beforeAlertAccept(WebDriver driver) { ((WebDriverEventListener) dispatcher).beforeAlertAccept(driver); }
Example #18
Source File: DefaultListener.java From java-client with Apache License 2.0 | 4 votes |
@Override public <X> void afterGetScreenshotAs(OutputType<X> target, X screenshot) { ((WebDriverEventListener) dispatcher).afterGetScreenshotAs(target, screenshot); }
Example #19
Source File: VividusWebDriverFactory.java From vividus with Apache License 2.0 | 4 votes |
public void setWebDriverEventListeners(List<WebDriverEventListener> webDriverEventListeners) { this.webDriverEventListeners = Collections.unmodifiableList(webDriverEventListeners); }
Example #20
Source File: GridHandler.java From kurento-java with Apache License 2.0 | 4 votes |
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 = { ImmutableList.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); } }
Example #21
Source File: DriverConfig.java From seleniumtestsframework with Apache License 2.0 | 4 votes |
public void setWebDriverListeners(final ArrayList<WebDriverEventListener> webDriverListeners) { this.webDriverListeners = webDriverListeners; }
Example #22
Source File: DriverConfig.java From seleniumtestsframework with Apache License 2.0 | 4 votes |
public ArrayList<WebDriverEventListener> getWebDriverListeners() { return webDriverListeners; }
Example #23
Source File: MouseActions.java From vividus with Apache License 2.0 | 4 votes |
public void setWebDriverEventListeners(List<WebDriverEventListener> webDriverEventListeners) { this.webDriverEventListeners = Collections.unmodifiableList(webDriverEventListeners); }