Skip to content

Commit

Permalink
add element unchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
alltonp committed Jul 8, 2015
1 parent 6516c2f commit 2be36b3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ case class ElementChecked(by: By) extends Condition {
import Describer._

def expectation = expect("ElementChecked", List(by.toString))
def isSatisfied(browser: UnSafeBrowser) = { !browser.attribute(by, "checked").isEmpty }
def isSatisfied(browser: UnSafeBrowser) = { browser.attribute(by, "checked") != null }
def describeFailure(browser: UnSafeBrowser) = { expectation + butWas(() => browser.attribute(by, "checked") )}
}
12 changes: 12 additions & 0 deletions src/main/scala/im/mange/driveby/conditions/ElementUnchecked.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package im.mange.driveby.conditions

import im.mange.driveby.browser.UnSafeBrowser
import im.mange.driveby.{By, Condition, Describer}

case class ElementUnchecked(by: By) extends Condition {
import Describer._

def expectation = expect("ElementUnchecked", List(by.toString))
def isSatisfied(browser: UnSafeBrowser) = { browser.attribute(by, "checked") == null }
def describeFailure(browser: UnSafeBrowser) = { expectation + butWas(() => browser.attribute(by, "checked") )}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package im.mange.acceptance.driveby.scalatest.condition

import im.mange.acceptance.driveby.scalatest.WebSpecification
import im.mange.common.ConditionNotMetException
import im.mange.driveby.Id
import im.mange.driveby.conditions._
import org.scalatest.Matchers

class ElementUncheckedSpec extends WebSpecification with Matchers {
def `pass for id when unchecked - checkbox` {
val id = Id("ElementUncheckedCheckbox")
given.page(<body><form><input type="checkbox" id={id.id}/></form></body>)
.assert(ElementUnchecked(id))
}

def `fail for id not unchecked - checkbox` {
val id = Id("ElementUncheckedWhenNotUncheckedCheckbox")
val b = given.page(<body><form><input type="checkbox" checked="checked" id={id.id}/></form></body>)

val thrown = the [ConditionNotMetException] thrownBy { b.assert(ElementUnchecked(id)) }
thrown.getMessage should equal("""> FAILED: Assert ElementUnchecked("Id(ElementUncheckedWhenNotUncheckedCheckbox)") but was "true" (not met within 2000 millis)""")
}

def `pass for id when unchecked - radio` {
val id = Id("ElementUncheckedRadio")
given.page(<body><form><input type="radio" id={id.id}/></form></body>)
.assert(ElementUnchecked(id))
}

def `fail for id not unchecked - radio` {
val id = Id("ElementUncheckedWhenNotUncheckedRadio")
val b = given.page(<body><form><input type="radio" checked="checked" id={id.id}/></form></body>)

val thrown = the [ConditionNotMetException] thrownBy { b.assert(ElementUnchecked(id)) }
thrown.getMessage should equal("""> FAILED: Assert ElementUnchecked("Id(ElementUncheckedWhenNotUncheckedRadio)") but was "true" (not met within 2000 millis)""")
}
}

0 comments on commit 2be36b3

Please sign in to comment.