Java Code Examples for org.openqa.selenium.support.events.EventFiringWebDriver#register()

The following examples show how to use org.openqa.selenium.support.events.EventFiringWebDriver#register() . 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: Browser.java    From coteafs-selenium with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: IAmTheDriver.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 6 votes vote down vote up
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 3
Source File: RegisteringMultipleListeners.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 6 votes vote down vote up
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 4
Source File: DefaultSession.java    From selenium with Apache License 2.0 6 votes vote down vote up
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 5
Source File: AbstractDriver.java    From frameworkium-core with Apache License 2.0 5 votes vote down vote up
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 6
Source File: LocalWebDriverBuilder.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
private WebDriver registerListener(WebDriver driver) {
  EventFiringWebDriver eventFiringDriver = new EventFiringWebDriver(driver);
  eventFiringDriver.register(new WebDriverLogEnricher());
  eventFiringDriver.register(new WebDriverServerLogEnricher());
  return eventFiringDriver;
}
 
Example 7
Source File: WebUIDriver.java    From seleniumtestsframework with Apache License 2.0 4 votes vote down vote up
public WebDriver createRemoteWebDriver(final String browser, final String mode) throws Exception {
    WebDriver driver = null;
    config.setBrowser(BrowserType.getBrowserType(browser));
    config.setMode(DriverMode.valueOf(mode));

    if (config.getMode() == DriverMode.ExistingGrid) {
        webDriverBuilder = new RemoteDriverFactory(this.config);
    } else {
        if (config.getBrowser() == BrowserType.FireFox) {
            webDriverBuilder = new FirefoxDriverFactory(this.config);
        } else if (config.getBrowser() == BrowserType.InternetExplore) {
            webDriverBuilder = new IEDriverFactory(this.config);
        } else if (config.getBrowser() == BrowserType.Chrome) {
            webDriverBuilder = new ChromeDriverFactory(this.config);
        } else if (config.getBrowser() == BrowserType.Safari) {
            webDriverBuilder = new SafariDriverFactory(this.config);
        } else if (config.getBrowser() == BrowserType.SauceLabs) {
            webDriverBuilder = new SauceLabsDriverFactory(this.config);
        } else if (config.getBrowser() == BrowserType.Android) {
            webDriverBuilder = new AndroidDriverFactory(this.config);
        } else if (config.getBrowser() == BrowserType.IPhone) {
            webDriverBuilder = new IPhoneDriverFactory(this.config);
        } else {
            throw new RuntimeException("Unsupported browser: " + browser);
        }
    }

    synchronized (this.getClass()) {
        driver = webDriverBuilder.createWebDriver();
        if(config.isEventFiringWebDriver()) {
            CustomEventListener eventListener = new CustomEventListener();
            EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(driver);
            eventFiringWebDriver.register(eventListener);
            WebUIDriver.setWebDriver(eventFiringWebDriver);
            driverSession.set(eventFiringWebDriver);
            driver = handleListeners(eventFiringWebDriver);
        } else {
            driverSession.set(driver);
            driver = handleListeners(driver);
        }
    }

    String browserVersion = ((RemoteWebDriver)(getWebDriverBuilder().getWebDriver())).getCapabilities().getVersion();
    SeleniumTestsContextManager.getTestLevelContext(SeleniumTestsContextManager.getGlobalContext().getTestNGContext()).setBrowserVersion(browserVersion);
    return driver;
}