All Downloads are FREE. Search and download functionalities are using the official Maven repository.

im.yagni.driveby.BrowserFactory.scala Maven / Gradle / Ivy

The newest version!
package im.yagni.driveby

import browser.ProbingBrowser
import driver.webdriver.{WebDriverFactory, WebDriverDriver}
import tracking.{BrowserOpened, BrowserOpenRequested, Tracker, TrackingIds}

object BrowserType {
  val ie = "ie"
  val firefoxPortable = "firefoxPortable"
  val firefox = "firefox"
  val htmlunit = "htmlunit"
}

object BrowserFactory {
  import BrowserType._

  def create(browserType: String) = {
    val browserId = TrackingIds.nextBrowserId
    Tracker.add(BrowserOpenRequested(browserType, browserId))

    val browser = new ProbingBrowser(WebDriverDriver(browserType match {
      case `ie` => WebDriverFactory.ie
      case `firefoxPortable` => WebDriverFactory.firefoxPortable
      case `firefox` => WebDriverFactory.firefox
      case `htmlunit` => WebDriverFactory.htmlunit
      case _ => throw new IllegalArgumentException("Sorry, don't know how to create a browser of type: " + browserType)
    }), browserId)

    Tracker.add(BrowserOpened(browserType, browserId))
    browser
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy