im.yagni.driveby.browser.TrackedBrowser.scala Maven / Gradle / Ivy
The newest version!
package im.yagni.driveby.browser
import im.yagni.driveby.By
import im.yagni.driveby.Condition
import im.yagni.driveby.tracking.{BrowserCommand, Tracker}
import java.io.File
import java.lang.String
class TrackedBrowser(browser: Browser, exampleId: Long) extends Browser {
def assert(condition: Condition, message: String) = { track("assert" + condition.expectation, Nil, message); browser.assert(condition, message)}
def click(by: By) { track("click", List(by.toString)); browser.click(by)}
def close() { browser.close() }
def enter(by: By, value: String) { track("enter", List(by.toString, value)); browser.enter(by, value) }
def goto(url: String) { track("goto", List(url)); browser.goto(url)}
def html = browser.html
def id = browser.id
def refresh() { track("refresh", Nil); browser.refresh() }
def select(by: By, value: String) { track("select", List(by.toString, value)); browser.select(by, value) }
def screenshot(file: File) { browser.screenshot(file) }
private def track(command: String, args: List[String], message: String = "") {
val comment = if (message.isEmpty) "" else " #" + message
val argList = args.filterNot(_.isEmpty).map("\"" + _ + "\"")
val entry = if (argList.isEmpty) command else command + "(" + argList.mkString(", ") + ")"
Tracker.add(BrowserCommand(entry + comment, exampleId))
}
}