org.openqa.selenium.support.events.EventFiringWebDriver Java Examples
The following examples show how to use
org.openqa.selenium.support.events.EventFiringWebDriver.
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: VividusWebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
private void runCreateTest(boolean remoteExecution, String browserName) throws Exception { vividusWebDriverFactory.setRemoteExecution(remoteExecution); vividusWebDriverFactory.setWebDriverEventListeners(List.of(webDriverEventListener)); when(bddRunContext.getRunningStory()).thenReturn(createRunningStory(browserName)); EventFiringWebDriver eventFiringWebDriver = mock(EventFiringWebDriver.class); PowerMockito.whenNew(EventFiringWebDriver.class).withArguments(driver).thenReturn(eventFiringWebDriver); Options options = mock(Options.class); when(eventFiringWebDriver.manage()).thenReturn(options); Window window = mock(Window.class); when(options.window()).thenReturn(window); when(eventFiringWebDriver.getCapabilities()).thenReturn(mock(Capabilities.class)); BrowserWindowSize windowSize = new BrowserWindowSize("1920x1080"); when(browserWindowSizeProvider.getBrowserWindowSize(remoteExecution)) .thenReturn(windowSize); VividusWebDriver vividusWebDriver = vividusWebDriverFactory.create(); assertEquals(eventFiringWebDriver, vividusWebDriver.getWrappedDriver()); verify(eventFiringWebDriver).register(webDriverEventListener); assertEquals(remoteExecution, vividusWebDriver.isRemote()); verify(webDriverManagerContext).reset(WebDriverManagerParameter.DESIRED_CAPABILITIES); verify(webDriverManager).resize(eventFiringWebDriver, windowSize); }
Example #2
Source File: Browser.java From coteafs-selenium with Apache License 2.0 | 6 votes |
@Override public void start() { LOG.i("Starting the browser..."); String target = this.browserName; if (target == null) { target = getProperty(BROWSER, appSetting().getBrowser() .name()); } this.availableBrowser = AvailableBrowser.valueOf(target.toUpperCase()); final WebDriver driver = setupDriver(this.availableBrowser); if (isNull(driver)) { fail(DriverNotSetupError.class, "Driver was not setup properly."); } final EventFiringWebDriver wd = new EventFiringWebDriver(driver); wd.register(this.listener); setSession(new BrowserSession(wd)); setupDriverOptions(); if (this.availableBrowser != AvailableBrowser.REMOTE) { perform().startRecording(); } else { LOG.w("Video recording is disabled for Remote execution..."); } }
Example #3
Source File: WebDriverProvider.java From bobcat with Apache License 2.0 | 6 votes |
private ClosingAwareWebDriver create() { WebDriverCreator webDriverCreator = webDriverCreators.stream() .filter(creator -> StringUtils.equalsIgnoreCase(type, creator.getId())) .findFirst() .orElseThrow(() -> new IllegalStateException( "No WebDriverCreator registered for the provided type: " + type)); final WebDriver raw = webDriverCreator.create(capabilities); final WebDriver modified = webDriverModifiers.modifyWebDriver(raw); final ClosingAwareWebDriver closingAwareWebDriver = closingAwareWebDriverFactory.create(modified); closedListeners.forEach(closingAwareWebDriver::addListener); listeners.forEach(((EventFiringWebDriver) closingAwareWebDriver)::register); registry.add(closingAwareWebDriver); return closingAwareWebDriver; }
Example #4
Source File: IDriverPool.java From carina with Apache License 2.0 | 6 votes |
/** * Get driver by WebElement. * * @param sessionId * - session id to be used for searching a desired driver * * @return default WebDriver */ public static WebDriver getDriver(SessionId sessionId) { for (CarinaDriver carinaDriver : driversPool) { WebDriver drv = carinaDriver.getDriver(); if (drv instanceof EventFiringWebDriver) { EventFiringWebDriver eventFirDriver = (EventFiringWebDriver) drv; drv = eventFirDriver.getWrappedDriver(); } SessionId drvSessionId = ((RemoteWebDriver) drv).getSessionId(); if (drvSessionId != null) { if (sessionId.equals(drvSessionId)) { return drv; } } } throw new DriverPoolException("Unable to find driver using sessionId artifacts. Returning default one!"); }
Example #5
Source File: DefaultSession.java From selenium with Apache License 2.0 | 6 votes |
private DefaultSession( final DriverFactory factory, TemporaryFilesystem tempFs, final Capabilities capabilities) { this.knownElements = new KnownElements(); this.tempFs = tempFs; final BrowserCreator browserCreator = new BrowserCreator(factory, capabilities); // Ensure that the browser is created on the single thread. EventFiringWebDriver initialDriver = browserCreator.call(); if (!isQuietModeEnabled(browserCreator, capabilities)) { // Memo to self; this is not a constructor escape of "this" - probably ;) initialDriver.register(new SnapshotScreenListener(this)); } this.driver = initialDriver; this.capabilities = browserCreator.getCapabilityDescription(); this.sessionId = browserCreator.getSessionId(); }
Example #6
Source File: IAmTheDriver.java From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License | 6 votes |
public static void main(String... args){ System.setProperty("webdriver.chrome.driver", "./src/test/resources/drivers/chromedriver"); WebDriver driver = new ChromeDriver(); try { EventFiringWebDriver eventFiringDriver = new EventFiringWebDriver(driver); IAmTheEventListener eventListener = new IAmTheEventListener(); eventFiringDriver.register(eventListener); eventFiringDriver.get("http://www.google.com"); eventFiringDriver.get("http://www.facebook.com"); eventFiringDriver.navigate().back(); } finally { driver.close(); driver.quit(); } }
Example #7
Source File: RegisteringMultipleListeners.java From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License | 6 votes |
public static void main(String... args){ System.setProperty("webdriver.chrome.driver", "./src/test/resources/drivers/chromedriver"); WebDriver driver = new ChromeDriver(); try { EventFiringWebDriver eventFiringDriver = new EventFiringWebDriver(driver); IAmTheEventListener eventListener = new IAmTheEventListener(); IAmTheEventListener2 eventListener2 = new IAmTheEventListener2(); eventFiringDriver.register(eventListener); eventFiringDriver.register(eventListener2); eventFiringDriver.get("http://www.google.com"); eventFiringDriver.get("http://www.facebook.com"); eventFiringDriver.navigate().back(); } finally { driver.close(); driver.quit(); } }
Example #8
Source File: CarinaListener.java From carina with Apache License 2.0 | 6 votes |
private String takeScreenshot(ITestResult result, String msg) { String screenId = ""; ConcurrentHashMap<String, CarinaDriver> drivers = getDrivers(); try { for (Map.Entry<String, CarinaDriver> entry : drivers.entrySet()) { String driverName = entry.getKey(); WebDriver drv = entry.getValue().getDriver(); if (drv instanceof EventFiringWebDriver) { drv = ((EventFiringWebDriver) drv).getWrappedDriver(); } if (Screenshot.isEnabled()) { screenId = Screenshot.capture(drv, driverName + ": " + msg, true); // in case of failure } } } catch (Throwable thr) { LOGGER.error("Failure detected on screenshot generation after failure: ", thr); } return screenId; }
Example #9
Source File: BrowserStatement.java From neodymium-library with MIT License | 6 votes |
private boolean isWebDriverStillOpen(WebDriver webDriver) { if (webDriver == null) { return false; } try { RemoteWebDriver driver = (RemoteWebDriver) ((EventFiringWebDriver) webDriver).getWrappedDriver(); return driver.getSessionId() != null; } catch (Exception e) { LOGGER.warn("Couldn't detect if the WebDriver is still open!", e); return true; } }
Example #10
Source File: WebDriverFactory.java From dropwizard-experiment with MIT License | 6 votes |
/** * Create a WebDriver instance with useful settings based on the WEBDRIVER environment variable. * @return The WebDriver */ public static EventFiringWebDriver createFromEnvVar() { String browser = System.getenv(WEBDRIVER_ENV_NAME); if (browser == null) { log.info("WebDriver type not specified, defaulting to Chrome."); browser = "chrome"; } switch (browser.toLowerCase()) { case "firefox": return createFirefox(); default: log.warn("Unknown WebDriver type '{}', defaulting to Chrome.", browser); case "chrome": return createChrome(); } }
Example #11
Source File: AbstractDriver.java From frameworkium-core with Apache License 2.0 | 5 votes |
private EventFiringWebDriver setupEventFiringWebDriver(Capabilities capabilities) { Capabilities caps = addProxyIfRequired(capabilities); logger.debug("Browser Capabilities: " + caps); EventFiringWebDriver eventFiringWD = new EventFiringWebDriver(getWebDriver(caps)); eventFiringWD.register(new LoggingListener()); if (ScreenshotCapture.isRequired()) { eventFiringWD.register(new CaptureListener()); } if (!Driver.isNative()) { eventFiringWD.manage().timeouts().setScriptTimeout(10, SECONDS); } return eventFiringWD; }
Example #12
Source File: MobileContextUtils.java From carina with Apache License 2.0 | 5 votes |
private WebDriver getDriverSafe() { WebDriver driver = getDriver(); if (driver instanceof EventFiringWebDriver) { driver = ((EventFiringWebDriver) driver).getWrappedDriver(); } return driver; }
Example #13
Source File: TestCase.java From simpleWebtest with Apache License 2.0 | 5 votes |
/** * 如果当前进程没有绑定driver,创建一个然后绑定上,如果已经有了就直接返回 * create a driver for this thread if not exist. or return it directly */ public static WebDriver getDriver(){ WebDriver driver= DriverManager.ThreadDriver.get(); if (driver==null){ if (browserType.equals("firefox")){ driver = new EventFiringWebDriver(new FirefoxDriver()).register(new LogEventListener()); ThreadDriver.set(driver); //找东西前等三秒wait 3 second for every find by DriverManager.getDriver().manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); } //有需求的同学自己在这里添加IE等浏览器的支持 //you can add ie/chrome or other driver here } return driver; }
Example #14
Source File: MobileContextUtils.java From carina-demo with Apache License 2.0 | 5 votes |
private WebDriver getDriverSafe() { WebDriver driver = getDriver(); if (driver instanceof EventFiringWebDriver) { driver = ((EventFiringWebDriver) driver).getWrappedDriver(); } return driver; }
Example #15
Source File: WebDriverFactory.java From dropwizard-experiment with MIT License | 5 votes |
/** * Create a Chrome WebDriver instance. * @return The WebDriver */ public static EventFiringWebDriver createChrome() { String chromeDriverBinary = WebDriverBinaryFinder.findChromeDriver(); System.setProperty("webdriver.chrome.driver", chromeDriverBinary); log.info("Using ChromeDriver binary from {}", chromeDriverBinary); // Prevent annoying yellow warning bar from being displayed. ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("excludeSwitches", ImmutableList.of("ignore-certificate-errors")); DesiredCapabilities caps = getCapabilities(); caps.setCapability(ChromeOptions.CAPABILITY, options); return withReports(new ChromeDriver(caps)); }
Example #16
Source File: ReportContext.java From carina with Apache License 2.0 | 5 votes |
/** * generate url for artifact by name * * @param driver WebDriver * @param name String * @return String */ private static String getUrl(WebDriver driver, String name) { String seleniumHost = Configuration.get(Parameter.SELENIUM_HOST).replace("wd/hub", "download/"); WebDriver drv = (driver instanceof EventFiringWebDriver) ? ((EventFiringWebDriver) driver).getWrappedDriver() : driver; String sessionId = ((RemoteWebDriver) drv).getSessionId().toString(); String url = seleniumHost + sessionId + "/" + name; LOGGER.debug("url: " + url); return url; }
Example #17
Source File: DriverListener.java From carina with Apache License 2.0 | 5 votes |
/** * Cast Carina driver to WebDriver removing all extra listeners (try to avoid direct operations via WebDriver as it doesn't support logging etc) * * @return WebDriver */ private WebDriver castDriver(WebDriver drv) { if (drv instanceof EventFiringWebDriver) { drv = ((EventFiringWebDriver) drv).getWrappedDriver(); } return drv; }
Example #18
Source File: IMobileUtils.java From carina with Apache License 2.0 | 5 votes |
/** * Cast Carina driver to WebDriver removing all extra listeners (try to avoid direct operations via WebDriver as it doesn't support logging etc) * * @return WebDriver */ default public WebDriver castDriver() { WebDriver drv = getDriver(); if (drv instanceof EventFiringWebDriver) { drv = ((EventFiringWebDriver) drv).getWrappedDriver(); } return drv; }
Example #19
Source File: MobileUtils.java From carina with Apache License 2.0 | 5 votes |
public static WebDriver getDriver() { WebDriver drv = IDriverPool.getDefaultDriver(); if (drv instanceof EventFiringWebDriver) { return ((EventFiringWebDriver) drv).getWrappedDriver(); } else { return drv; } }
Example #20
Source File: VividusWebDriverFactory.java From vividus with Apache License 2.0 | 5 votes |
@Override public VividusWebDriver create() { VividusWebDriver vividusWebDriver = createVividusWebDriver(bddRunContext.getRunningStory()); WebDriver webDriver; DesiredCapabilities desiredCapabilities = vividusWebDriver.getDesiredCapabilities(); if (proxy.isStarted()) { desiredCapabilities.setCapability(CapabilityType.PROXY, createSeleniumProxy(remoteExecution)); desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); } if (remoteExecution) { webDriver = webDriverFactory.getRemoteWebDriver(desiredCapabilities); vividusWebDriver.setRemote(true); } else { webDriver = webDriverFactory.getWebDriver(desiredCapabilities); } EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(webDriver); webDriverEventListeners.forEach(eventFiringWebDriver::register); vividusWebDriver.setWebDriver(eventFiringWebDriver); webDriverManager.resize(vividusWebDriver.getWrappedDriver(), browserWindowSizeProvider.getBrowserWindowSize(remoteExecution)); return vividusWebDriver; }
Example #21
Source File: BaseDriverAction.java From coteafs-selenium with Apache License 2.0 | 5 votes |
@SuppressWarnings ("unchecked") @Override public <T> T execute (final String script, final Object... args) { return (T) get (d -> { if (d instanceof EventFiringWebDriver) { return ((EventFiringWebDriver) d).executeScript (script, args); } return ((RemoteWebDriver) d).executeScript (script, args); }); }
Example #22
Source File: OtherWebDriverTest.java From webdrivermanager with Apache License 2.0 | 5 votes |
@Parameters(name = "{index}: {0} {1}") public static Collection<Object[]> data() { return asList(new Object[][] { { SafariDriver.class, WebDriverException.class }, { EventFiringWebDriver.class, InstantiationException.class }, { HtmlUnitDriver.class, null }, { RemoteWebDriver.class, IllegalAccessException.class } }); }
Example #23
Source File: DebugUtilsTest.java From neodymium-library with MIT License | 5 votes |
@Test public void testWaiting() { NeodymiumWebDriverTestListener eventListener = new NeodymiumWebDriverTestListener(); ((EventFiringWebDriver) Neodymium.getDriver()).register(eventListener); Neodymium.configuration().setProperty("neodymium.debugUtils.highlight", "true"); // one wait due to navigation Selenide.open("https://blog.xceptance.com/"); Assert.assertEquals(0, eventListener.implicitWaitCount); // one wait due to find $("body #masthead").should(exist); Assert.assertEquals(1, eventListener.implicitWaitCount); assertJsSuccessfullyInjected(); // two waits due to chain finding $("body").findElements(By.cssSelector("#content article")); Assert.assertEquals(3, eventListener.implicitWaitCount); // two waits due to find and click $("#text-3 h1").click(); Assert.assertEquals(4, eventListener.implicitWaitCount); // additional two waits due to find and click $("#masthead .search-toggle").click(); Assert.assertEquals(5, eventListener.implicitWaitCount); // three waits due to find and change value (consumes 2 waits) $("#search-container .search-form input.search-field").val("abc"); Assert.assertEquals(6, eventListener.implicitWaitCount); // two waits due to find and press enter $("#search-container .search-form input.search-field").pressEnter(); Assert.assertEquals(7, eventListener.implicitWaitCount); }
Example #24
Source File: BrowserPage.java From coteafs-selenium with Apache License 2.0 | 5 votes |
@Override public <T extends IPage<EventFiringWebDriver, BrowserActions, WebElement>> T nextPage (final Class<T> pageCls) { T page = null; try { page = pageCls.newInstance (); } catch (final InstantiationException | IllegalAccessException e) { handleError (FILTER_PKG, e).forEach (LOG::e); } return page; }
Example #25
Source File: AI.java From neodymium-library with MIT License | 5 votes |
/** * Returns the browser name using Selenium methods * * @param webDriver * the WebDriver to query * @return the browser name */ private String getBrowserName(final WebDriver webDriver) { EventFiringWebDriver firingWebDriver = ((EventFiringWebDriver) webDriver); final Capabilities capabilities = ((RemoteWebDriver) firingWebDriver.getWrappedDriver()).getCapabilities(); final String browserName = capabilities.getBrowserName(); // TODO: change to browserProfileName in a next dev step since resolution influences the detection anyway // final String browserName = Context.get().browserProfileName; return browserName == null ? "unknown" : browserName; }
Example #26
Source File: WebDriverFactory.java From dropwizard-experiment with MIT License | 4 votes |
private static EventFiringWebDriver withReports(WebDriver driver) { return ReportingWebDriverEventListener.applyTo(driver, REPORTS_CLASS_PREFIX); }
Example #27
Source File: Browser.java From coteafs-selenium with Apache License 2.0 | 4 votes |
@Override public EventFiringWebDriver getDriver() { return getSession().getDriver(); }
Example #28
Source File: ExtendedWebElement.java From carina with Apache License 2.0 | 4 votes |
private WebDriver castDriver(WebDriver drv) { if (drv instanceof EventFiringWebDriver) { drv = ((EventFiringWebDriver) drv).getWrappedDriver(); } return drv; }
Example #29
Source File: BrowserActions.java From coteafs-selenium with Apache License 2.0 | 4 votes |
/** * @param driver driver * @author Wasiq Bhamla * @since 02-Jun-2019 */ BrowserActions (final EventFiringWebDriver driver) { super (driver); this.delaySetting = appSetting ().getPlayback () .getDelays (); }
Example #30
Source File: LocalWebDriverBuilder.java From justtestlah with Apache License 2.0 | 4 votes |
private WebDriver registerListener(WebDriver driver) { EventFiringWebDriver eventFiringDriver = new EventFiringWebDriver(driver); eventFiringDriver.register(new WebDriverLogEnricher()); eventFiringDriver.register(new WebDriverServerLogEnricher()); return eventFiringDriver; }