Java源码示例:com.squareup.spoon.Spoon
示例1
@Test
public void
show_characters_name() throws Exception {
Observable<List<GoTCharacter>> charactersObservable = TestUtils.getCharacters(NUMBER_OF_CHARACTERS);
List<GoTCharacter> characterList = charactersObservable.toBlocking().first();
given(remote.getAll()).willReturn(charactersObservable);
given(local.getAll()).willReturn(charactersObservable);
activityTestRule.launchActivity(null);
Spoon.screenshot(activityTestRule.getActivity(), "Character_list");
RecyclerViewInteraction.<GoTCharacter>onRecyclerView(allOf(withId(R.id.recycler_view), isDisplayed()))
.withItems(characterList)
.check((character, view, e) -> matches(hasDescendant(withText(character.getName()))).check(view, e));
}
示例2
@Test
public void
show_conversation_users_in_toolbar_subtitle_when_init_activity() throws Exception {
given(conversationRepository.get(any(Conversation.class))).willReturn(getConversationObservable());
initActivity();
Spoon.screenshot(activityTestRule.getActivity(), "init_state_conversation");
onView(withId(R.id.toolbar))
.check(withSubtitle(getUserListSubtitle()));
}
示例3
@Test
public void
show_my_message_when_send_a_message() throws Exception {
given(conversationRepository.get(any(Conversation.class))).willReturn(getConversationObservable());
MockMessageRepository messageRepository = daggerMockRule.getMockMessageRepository();
messageRepository.disableMessages();
initActivity();
WaitForHasClick waitForHasClick = registerKeyboardIdlingResource();
onView(withId(R.id.message_edit_text))
.perform(typeText(MESSAGE_TEXT));
onView(withId(R.id.attach))
.perform(click());
Spoon.screenshot(activityTestRule.getActivity(), "after_type_a_message");
RecyclerViewInteraction.<Message>onRecyclerView(withId(R.id.recycler_view))
.withItems(Arrays.asList(new Message("1", null, 2, true, new TextPayLoad(MESSAGE_TEXT))))
.check((item, view, e) -> {
String message = ((TextPayLoad) item.getPayload()).getTextMessage().toString();
matches(hasDescendant(withText(message))).check(view, e);
});
unregisterIdlingResources(waitForHasClick);
}
示例4
@Test
public void
show_messages_in_order_from_others_when_there_are_messages() throws Exception {
given(conversationRepository.get(any(Conversation.class))).willReturn(getConversationObservable());
MockMessageRepository messageRepository = daggerMockRule.getMockMessageRepository();
messageRepository.enableMessages();
initActivity();
Spoon.screenshot(activityTestRule.getActivity(), "after_show_message_from_others");
onView(withId(R.id.recycler_view))
.check(RecyclerSortedViewAssertion.isSorted(this::getAdapterMessages));
}
示例5
@Test
public void
show_messages_in_order_from_others_and_me_when_send_messages_and_receive_messages() throws Exception {
given(conversationRepository.get(any(Conversation.class))).willReturn(getConversationObservable());
MockMessageRepository messageRepository = daggerMockRule.getMockMessageRepository();
messageRepository.enableMessages();
Conversation conversation = getConversation();
initActivity();
WaitForHasClick waitForHasClick = registerKeyboardIdlingResource();
onView(withId(R.id.message_edit_text))
.perform(typeText(MESSAGE_TEXT));
onView(withId(R.id.attach))
.perform(click());
messageRepository.sendMessage(conversation);
onView(withId(R.id.message_edit_text))
.perform(typeText(MESSAGE_TEXT + " Other message"));
onView(withId(R.id.attach))
.perform(click());
messageRepository.sendMessage(conversation);
Spoon.screenshot(activityTestRule.getActivity(), "show_messages_and_type_text");
onView(withId(R.id.recycler_view))
.check(RecyclerSortedViewAssertion.isSorted(this::getAdapterMessages));
unregisterIdlingResources(waitForHasClick);
}
示例6
@Test
public void
should_character_name_as_toolbar_tittle() throws Exception {
GoTCharacter character = TestUtils.defaultGotCharacter(0);
startActivity(character);
Spoon.screenshot(activityTestRule.getActivity(), "init_state_character_detail");
onView(withId(R.id.toolbar))
.check(ToolbarTitleViewAssertion.withTitle(character.getName()));
}
示例7
@Test
public void
should_does_not_show_loading_view_once_character_are_shown() throws Exception {
GoTHouse house = TestUtils.defaultGotHouse();
Observable<List<GoTCharacter>> characters = TestUtils.getCharacters(NUMBER_OF_CHARACTERS);
given(repository.read(house)).willReturn(characters);
startActivity(house);
Spoon.screenshot(activityTestRule.getActivity(), "init_state_house_detail");
onView(withId(R.id.content_loading_progress_bar)).check(matches(not(isDisplayed())));
}
示例8
/**
* Test okhttp mockwebserver Dispatcher
*/
@Test
public void testMockWebServerDispatcher() {
activity = activityRule.getActivity();
logger.debug("testMockWebServerDispatcher");
//Use a dispatcher
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().equals("/api/840dbdf2737a7ff9/conditions/q/CA/atlanta.json")) {
String jsonBody = asset(activity, "atlanta-conditions.json");
return new MockResponse().setResponseCode(200).setBody(jsonBody);
}
return new MockResponse().setResponseCode(404);
}
};
mMockWebServer.setDispatcher(dispatcher);
String okhttpMockWebServerUrl = mMockWebServer.url("/").toString();
logger.debug("okhttp mockserver URL: " + okhttpMockWebServerUrl);
activity.setWeatherServiceManager(new WeatherServiceManager(okhttpMockWebServerUrl));
Spoon.screenshot(activity, "one");
onView(ViewMatchers.withId(R.id.editText)).perform(replaceText("atlanta"));
onView(withId(R.id.button)).perform(click());
Spoon.screenshot(activity, "two");
onView(withId(R.id.textView)).check(matches(withText(containsString("GA"))));
}
示例9
public void testTweetView() throws Exception {
onView(withId(R.id.jack_regular_tweet)).perform(scrollTo());
TweetAsserts.assertTweetText(R.id.jack_regular_tweet, EXPECTED_TEXT);
TweetAsserts.assertTweetTimestamp(R.id.jack_regular_tweet, EXPECTED_TIMESTAMP);
TweetAsserts.assertVerifiedUser(R.id.jack_regular_tweet);
TweetAsserts.assertActionsEnabled(R.id.jack_regular_tweet);
onView(withId(R.id.bike_regular_tweet)).perform(scrollTo());
TweetAsserts.assertNonVerifiedUser(R.id.bike_regular_tweet);
Spoon.screenshot(activity, TAG);
}
示例10
public void testCompactTweetView() throws Exception {
onView(withId(R.id.jack_compact_tweet)).perform(scrollTo());
TweetAsserts.assertTweetText(R.id.jack_compact_tweet, EXPECTED_TEXT);
TweetAsserts.assertTweetTimestamp(R.id.jack_compact_tweet, EXPECTED_TIMESTAMP);
TweetAsserts.assertNonVerifiedUser(R.id.jack_compact_tweet);
TweetAsserts.assertActionsEnabled(R.id.jack_compact_tweet);
Spoon.screenshot(activity, TAG);
}
示例11
public void testTweetView() throws Exception {
onView(withId(R.id.jack_regular_tweet)).perform(scrollTo());
TweetAsserts.assertTweetText(R.id.jack_regular_tweet, EXPECTED_TEXT);
TweetAsserts.assertTweetTimestamp(R.id.jack_regular_tweet, EXPECTED_TIMESTAMP);
TweetAsserts.assertVerifiedUser(R.id.jack_regular_tweet);
TweetAsserts.assertActionsDisabled(R.id.jack_regular_tweet);
onView(withId(R.id.bike_regular_tweet)).perform(scrollTo());
TweetAsserts.assertNonVerifiedUser(R.id.bike_regular_tweet);
Spoon.screenshot(activity, TAG);
}
示例12
public void testCompactTweetView() throws Exception {
onView(withId(R.id.jack_compact_tweet)).perform(scrollTo());
TweetAsserts.assertTweetText(R.id.jack_compact_tweet, EXPECTED_TEXT);
TweetAsserts.assertTweetTimestamp(R.id.jack_compact_tweet, EXPECTED_TIMESTAMP);
TweetAsserts.assertNonVerifiedUser(R.id.jack_compact_tweet);
TweetAsserts.assertActionsDisabled(R.id.jack_compact_tweet);
Spoon.screenshot(activity, TAG);
}
示例13
@Test
public void testThatDefaultBehaviorIsWorking() throws Exception {
mMockWebServer.enqueue(new MockResponse().setBody(AssetsHelper.getStringFromAsset("stubs/rank_ok.json")));
userAskPIComputation();
assertTrue("After a Pi computation, user is able to send its result.", checkPIComputationWentOK());
Spoon.screenshot(mActivityRule.getActivity(), "checkPIComputationWentOK");
userAskSendPIOnlineForRank();
assertTrue("After ranking his result online, the user should be able to share his rank.", checkSendPIWentOK());
Spoon.screenshot(mActivityRule.getActivity(), "checkSendPIWentOK");
userAskShare();
assertTrue("After asking for share, the user should be able to choose how he wants to share", checkShareWentOK());
Spoon.screenshot(mActivityRule.getActivity(), "checkShareWentOK");
}
示例14
@Test
public void testThatServerIssueDisplayToast() {
mMockWebServer.enqueue(new MockResponse().setResponseCode(500));
userAskPIComputation();
assertTrue("After a Pi computation, user is able to send its result.", checkPIComputationWentOK());
Spoon.screenshot(mActivityRule.getActivity(), "checkPIComputationWentOK");
userAskSendPIOnlineForRank();
assertTrue("A Toast message should be displayed.", checkSendPIWentWrong());
Spoon.screenshot(mActivityRule.getActivity(), "checkSendPIWentWrong");
}
示例15
public void testStartSecondActivity() throws Exception {
final String fieldValue = "Droidcon Workshop";
Spoon.screenshot(getActivity(), "initial_state");
// Set a value into the text field
EditText editText = (EditText) solo.getView(R.id.etResult);
solo.waitForView(editText);
solo.enterText(editText, fieldValue);
// Spoon.screenshot(getActivity(), "before_button_clicked");
// find button and click it
Button button = (Button) solo.getView(R.id.btnLaunch);
solo.waitForView(button);
solo.clickOnView(button);
// Wait 2 seconds for the start of the activity
solo.waitForActivity(SecondActivity.class, 2000);
solo.assertCurrentActivity("Should be second activity", SecondActivity.class);
// Spoon.screenshot(solo.getCurrentActivity(), "second_state");
// Search for the textView
TextView textView = (TextView) solo.getView(R.id.tvResult);
// Validate the text on the TextView
assertEquals("Text should be the field value", fieldValue,
textView.getText().toString());
}
示例16
@Override
public void perform(final UiController uiController, final View view) {
lastScreenshot = Spoon.screenshot(getActivity(view), mTag, mTestClass, mTestMethod);
}
示例17
@Override
public void perform(final UiController uiController, final View view) {
sLastScreenshot = Spoon.screenshot(getActivity(view), mTag, mTestClass, mTestMethod);
}
示例18
protected void takeScreenShot(String name) {
try {
Spoon.screenshot(getCurrentActivity(), name);
} catch (Exception ignore){}
}
示例19
private void makeScreenshot(String tag) {
Spoon.screenshot(getActivity(), tag);
}
示例20
private void makeScreenshot(final String tag) {
Spoon.screenshot(getActivity(),tag);
}
示例21
public void testInputIsThere() {
Spoon.screenshot(getActivity(), "main");
onView(withId(R.id.codeInput)).check(matches(isDisplayed()));
}
示例22
@Test public void noneOfTheThings() {
Spoon.screenshot(main.getActivity(), "initial_state");
sleep(SECONDS.toMillis(5)); // Long enough to see some data from mock mode.
assertTrue(true);
Spoon.screenshot(main.getActivity(), "displayed_data");
}
示例23
@Test
public void checkPing() {
Spoon.screenshot(mActivityRule.getActivity(), "ping");
setUpText("google.com");
// Click ping button
onView(withId(R.id.pingButton)).perform(click());
sleep();
Spoon.screenshot(mActivityRule.getActivity(), "ping");
}
示例24
@Test
public void checkWOL() {
Spoon.screenshot(mActivityRule.getActivity(), "wake-on-lan");
setUpText("localhost");
// Click ping button
onView(withId(R.id.wolButton)).perform(click());
sleep();
Spoon.screenshot(mActivityRule.getActivity(), "wake-on-lan");
}
示例25
@Test
public void checkPortScan() {
Spoon.screenshot(mActivityRule.getActivity(), "port_scan");
setUpText("localhost");
// Click ping button
onView(withId(R.id.portScanButton)).perform(click());
sleep();
Spoon.screenshot(mActivityRule.getActivity(), "port_scan");
}
示例26
public void testOnePlusOneIsTwo() {
inputAndEvaluateCode("1+1");
onView(withId(R.id.obj_tostring)).check(matches(withText("2")));
Spoon.screenshot(getActivity(), "one_plus_one");
}
示例27
public void testAndroidIsResolved() {
inputAndEvaluateCode("import android.os.*;Build");
Spoon.screenshot(getActivity(), "eval_build");
onView(withId(R.id.obj_tostring)).check(matches(withText(endsWith("android.os.Build"))));
onView(withId(R.id.obj_classinfo)).check(matches(withText(endsWith("android.os.Build"))));
}
示例28
public void testExceptionsAreCaredOf() {
inputAndEvaluateCode("1/0");
onView(withId(R.id.exception_out)).check(matches(withText(containsString("Exception"))));
Spoon.screenshot(getActivity(), "exception");
}
示例29
public void testContextIsThere() {
inputAndEvaluateCode("ctx");
onView(withId(R.id.obj_classinfo)).check(matches(withText(endsWith("Activity"))));
Spoon.screenshot(getActivity(), "ctx");
}
示例30
public void testContainerWorks() {
loadAndEvaluateCode("examples/","views");
onView(withId(R.id.linearLayout)).check(matches(withChild(withText(containsString("check")))));
Spoon.screenshot(getActivity(), "checkbox");
}