im.yagni.driveby.browser.ProbingBrowser.scala Maven / Gradle / Ivy
The newest version!
package im.yagni.driveby.browser
import im.yagni.common.Wait._
import im.yagni.driveby.{By, Condition}
import im.yagni.driveby.driver.NakedDriver
import java.io.File
case class ProbingBrowser(driver: NakedDriver, id: Long) extends Browser {
private val unsafe = new UnSafeBrowser(driver)
def goto(url: String) { driver.goto(url) }
def click(by: By) { unsafe.findUniqueInteractableElement(by).click() }
def enter(by: By, value: String) { unsafe.findUniqueInteractableElement(by).enter(value) }
def select(by: By, value: String) {
waitUpTo().forCondition(
unsafe.findOption(by, value) match {
case Some(option) => {
option.click(); true
}
case _ => false
}, "select '" + by + "' option '" + value + "'"
)
}
def close() { driver.close() }
def html = driver.html
def screenshot(file: File) { driver.screenshot(file) }
def assert(condition: Condition, additionalMessage: String = "") = {
waitUpTo().forCondition(
condition.isSatisfied(unsafe),
try {
"Assert " + condition.describeFailure(unsafe) + " " + additionalMessage
}
catch {
case e: Exception => e.getMessage
}
)
true
}
def refresh() { driver.refresh() }
def maximise() { driver.maximise() }
}