org.openqa.selenium.support.events.EventFiringWebDriver源码实例Demo

类org.openqa.selenium.support.events.EventFiringWebDriver源码实例Demo

下面列出了org.openqa.selenium.support.events.EventFiringWebDriver 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: vividus   文件: VividusWebDriverFactoryTests.java
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);
}
 
源代码2 项目: coteafs-selenium   文件: Browser.java
@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...");
    }
}
 
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();
        }
    }
 
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();
        }
    }
 
源代码5 项目: neodymium-library   文件: BrowserStatement.java
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;
    }
}
 
源代码6 项目: bobcat   文件: WebDriverProvider.java
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;
}
 
源代码7 项目: selenium   文件: DefaultSession.java
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();
}
 
源代码8 项目: dropwizard-experiment   文件: WebDriverFactory.java
/**
 * 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();
    }
}
 
源代码9 项目: carina   文件: CarinaListener.java
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;
}
 
源代码10 项目: carina   文件: IDriverPool.java
/**
 * 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!");
}
 
源代码11 项目: vividus   文件: VividusWebDriverFactory.java
@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;
}
 
源代码12 项目: coteafs-selenium   文件: BaseDriverAction.java
@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);
    });
}
 
源代码13 项目: coteafs-selenium   文件: BrowserPage.java
@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;
}
 
源代码14 项目: neodymium-library   文件: AI.java
/**
 * 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;
}
 
源代码15 项目: neodymium-library   文件: DebugUtilsTest.java
@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);
}
 
源代码16 项目: webdrivermanager   文件: OtherWebDriverTest.java
@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 } });
}
 
源代码17 项目: frameworkium-core   文件: AbstractDriver.java
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;
}
 
源代码18 项目: simpleWebtest   文件: TestCase.java
/**
 * 如果当前进程没有绑定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;
}
 
源代码19 项目: carina-demo   文件: MobileContextUtils.java
private WebDriver getDriverSafe() {
    WebDriver driver = getDriver();
    if (driver instanceof EventFiringWebDriver) {
        driver = ((EventFiringWebDriver) driver).getWrappedDriver();
    }
    return driver;
}
 
源代码20 项目: dropwizard-experiment   文件: WebDriverFactory.java
/**
 * 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));
}
 
源代码21 项目: carina   文件: ReportContext.java
/**
 * 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;
}
 
源代码22 项目: carina   文件: DriverListener.java
/**
 * 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;
}
 
源代码23 项目: carina   文件: IMobileUtils.java
/**
 * 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;
}
 
源代码24 项目: carina   文件: MobileUtils.java
public static WebDriver getDriver() {
	WebDriver drv = IDriverPool.getDefaultDriver();
	if (drv instanceof EventFiringWebDriver) {
		return ((EventFiringWebDriver) drv).getWrappedDriver();
	} else {
		return drv;
	}
}
 
源代码25 项目: carina   文件: MobileContextUtils.java
private WebDriver getDriverSafe() {
    WebDriver driver = getDriver();
    if (driver instanceof EventFiringWebDriver) {
        driver = ((EventFiringWebDriver) driver).getWrappedDriver();
    }
    return driver;
}
 
源代码26 项目: coteafs-selenium   文件: Browser.java
@Override
public EventFiringWebDriver getDriver() {
    return getSession().getDriver();
}
 
源代码27 项目: coteafs-selenium   文件: BrowserActions.java
/**
 * @param driver driver
 * @author Wasiq Bhamla
 * @since 02-Jun-2019
 */
BrowserActions (final EventFiringWebDriver driver) {
    super (driver);
    this.delaySetting = appSetting ().getPlayback ()
        .getDelays ();
}
 
源代码28 项目: justtestlah   文件: LocalWebDriverBuilder.java
private WebDriver registerListener(WebDriver driver) {
  EventFiringWebDriver eventFiringDriver = new EventFiringWebDriver(driver);
  eventFiringDriver.register(new WebDriverLogEnricher());
  eventFiringDriver.register(new WebDriverServerLogEnricher());
  return eventFiringDriver;
}
 
源代码29 项目: neodymium-library   文件: Neodymium.java
public static EventFiringWebDriver getEventFiringWebdriver()
{
    return (EventFiringWebDriver) getDriver();
}
 
源代码30 项目: neodymium-library   文件: NeodymiumWebDriverTest.java
public static void assertWebDriverClosed(WebDriver webDriver)
{
    Assert.assertNotNull(webDriver);
    RemoteWebDriver driver = (RemoteWebDriver) ((EventFiringWebDriver) webDriver).getWrappedDriver();
    Assert.assertNull(driver.getSessionId());
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法