Last active
September 3, 2017 15:47
-
-
Save justintuchek/29d6c8a0c4e7b8a8237c426739fc9634 to your computer and use it in GitHub Desktop.
Expressive Espresso
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
import com.botlink.app.R; | |
import com.botlink.app.util.widget.ImageViewTest; | |
import com.botlink.app.util.widget.TextViewTest; | |
public class PlugInRadioPage { | |
public PlugInRadioPage checkImage(@DrawableRes int id) { | |
ImageViewTest.withId(R.id.iv_plug_in_radio_image) | |
.displayed() | |
.src(id); | |
return this; | |
} | |
public PlugInRadioPage checkTitle(@StringRes int id) { | |
TextViewTest.withId(R.id.tv_plug_in_radio_title) | |
.withText("Plug in USB radio") | |
.withColor(R.color.botlink_white) | |
.displayed(); | |
return this; | |
} | |
public PlugInRadioPage checkBody(@StringRes int id) { | |
TextViewTest.withId(R.id.tv_plug_in_radio_body) | |
.withText("Connect a USB cable from the 915 Mhz USB radio to your device. Make sure the colored end is inserted into the device") | |
.withColor(R.color.botlink_white) | |
.displayed(); | |
return this; | |
} | |
} |
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
import android.support.annotation.ColorRes; | |
import android.support.annotation.IdRes; | |
import android.support.annotation.StringRes; | |
import android.support.test.espresso.matcher.ViewMatchers; | |
import android.view.View; | |
import com.botlink.app.util.matchers.TextColorMatcher; | |
import org.hamcrest.Matcher; | |
public class TextViewTest { | |
private final ViewInteractor view; | |
public TextViewTest(Matcher<View> view) { | |
this.view = new ViewInteractor(view); | |
} | |
public TextViewTest withText(String value) { | |
view.checkAssertion(ViewMatchers.withText(value)); | |
return this; | |
} | |
public TextViewTest withText(@StringRes int stringResId) { | |
view.checkAssertion(ViewMatchers.withText(stringResId)); | |
return this; | |
} | |
public TextViewTest withColor(@ColorRes int colorResId) { | |
view.checkAssertion(new TextColorMatcher(colorResId)); | |
return this; | |
} | |
public TextViewTest displayed() { | |
view.checkAssertion(ViewMatchers.isDisplayed()); | |
return this; | |
} | |
public TextViewTest enabled() { | |
view.checkAssertion(ViewMatchers.isEnabled()); | |
return this; | |
} | |
public static TextViewTest withId(@IdRes int idRes) { | |
return new TextViewTest(ViewMatchers.withId(idRes)); | |
} | |
} |
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
import android.support.test.espresso.Espresso; | |
import android.support.test.espresso.ViewAction; | |
import android.support.test.espresso.ViewInteraction; | |
import android.support.test.espresso.assertion.ViewAssertions; | |
import android.view.View; | |
import org.hamcrest.Matcher; | |
public class ViewInteractor { | |
private final ViewInteraction interaction; | |
public ViewInteractor(Matcher<View> view) { | |
interaction = Espresso.onView(view); | |
} | |
public ViewInteraction interaction() { | |
return interaction; | |
} | |
public ViewInteraction checkAssertion(Matcher<View> matcher) { | |
return interaction().check(ViewAssertions.matches(matcher)); | |
} | |
public ViewInteraction perform(ViewAction action) { | |
return interaction().perform(action); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment