Skip to content

Commit

Permalink
creating SeleniumDslMatcher for hamcrest based matching
Browse files Browse the repository at this point in the history
  • Loading branch information
lucascs committed Jul 29, 2009
1 parent df098ae commit bc624ca
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
@@ -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);
}
}
@@ -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);
}
}
@@ -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>();
}
}
@@ -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"));
}
}

0 comments on commit bc624ca

Please sign in to comment.