Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating SeleniumDslMatcher for hamcrest based matching
- Loading branch information
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/java/br/com/caelum/seleniumdsl/hamcrest/SeleniumDslMatchers.java
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,17 @@ | ||
package br.com.caelum.seleniumdsl.hamcrest; | ||
|
||
import org.hamcrest.Matcher; | ||
|
||
import br.com.caelum.seleniumdsl.ContentTag; | ||
|
||
public class SeleniumDslMatchers { | ||
private SeleniumDslMatchers() {} | ||
|
||
public static <T extends ContentTag> Matcher<T> divExists() { | ||
return DivExistsMatcher.<T>divExists(); | ||
} | ||
|
||
public static <T extends ContentTag> Matcher<T> divContains(String text) { | ||
return DivContainsMatcher.<T>divContains(text); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/br/com/caelum/seleniumdsl/hamcrest/DivContainsMatcher.java
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,29 @@ | ||
package br.com.caelum.seleniumdsl.hamcrest; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Factory; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
|
||
import br.com.caelum.seleniumdsl.ContentTag; | ||
|
||
public class DivContainsMatcher<T extends ContentTag> extends TypeSafeMatcher<T> { | ||
private final String text; | ||
|
||
public DivContainsMatcher(String text) { | ||
this.text = text; | ||
} | ||
@Override | ||
public boolean matchesSafely(ContentTag item) { | ||
return item.contains(text); | ||
} | ||
|
||
public void describeTo(Description description) { | ||
description.appendText("a div containing " + text); | ||
} | ||
|
||
@Factory | ||
public static <T extends ContentTag> Matcher<T> divContains(String text) { | ||
return new DivContainsMatcher<T>(text); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/br/com/caelum/seleniumdsl/hamcrest/DivExistsMatcher.java
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,24 @@ | ||
package br.com.caelum.seleniumdsl.hamcrest; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Factory; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
|
||
import br.com.caelum.seleniumdsl.ContentTag; | ||
|
||
public class DivExistsMatcher<T extends ContentTag> extends TypeSafeMatcher<T> { | ||
@Override | ||
public boolean matchesSafely(ContentTag item) { | ||
return item.exists(); | ||
} | ||
|
||
public void describeTo(Description description) { | ||
description.appendText("a div that exists"); | ||
} | ||
|
||
@Factory | ||
public static <T extends ContentTag> Matcher<T> divExists() { | ||
return new DivExistsMatcher<T>(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/java/br/com/caelum/seleniumdsl/hamcrest/SeleniumDslMatchersTest.java
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,14 @@ | ||
package br.com.caelum.seleniumdsl.hamcrest; | ||
|
||
import static br.com.caelum.seleniumdsl.hamcrest.SeleniumDslMatchers.divContains; | ||
import static br.com.caelum.seleniumdsl.hamcrest.SeleniumDslMatchers.divExists; | ||
import static org.junit.Assert.assertThat; | ||
import br.com.caelum.seleniumdsl.ContentTag; | ||
public class SeleniumDslMatchersTest { | ||
|
||
public void testingCompilationOfContentTagMatchers() { | ||
ContentTag tag = null; | ||
assertThat(tag, divExists()); | ||
assertThat(tag, divContains("Anything")); | ||
} | ||
} |