-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/scala/im/mange/driveby/conditions/ElementUnchecked.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") )} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/scala/im/mange/acceptance/driveby/scalatest/condition/ElementUncheckedSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)""") | ||
} | ||
} |