Java 类android.support.test.espresso.intent.Intents 实例源码

项目:GitHub    文件:StartupTest.java   
private void startNewLocalConnection(String name) {
    onView(withId(R.id.add_host_button)).perform(click());
    onView(withId(R.id.protocol_text)).perform(click());
    onView(withText("local")).perform(click());
    onView(withId(R.id.quickconnect_field)).perform(typeText(name));
    onView(withId(R.id.save)).perform(click());

    Intents.init();
    try {
        onView(withId(R.id.list)).perform(actionOnHolderItem(
                withHostNickname(name), click()));
        intended(hasComponent(ConsoleActivity.class.getName()));
    } finally {
        Intents.release();
    }

    onView(withId(R.id.console_flip)).check(matches(
            hasDescendant(allOf(isDisplayed(), withId(R.id.terminal_view)))));
}
项目:polling-station-app    文件:ElectionChoiceActivityTest.java   
@Before
public void setUp() {
    Intents.init();

    // Wait till the splashactivity is closed, indicating blockchain was instantiated has started
    Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    mActivityRule.launchActivity(new Intent(targetContext, ElectionChoiceActivity.class));
    while (!mActivityRule.getActivity().isFinishing()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    activity = (ElectionChoiceActivity) mElectionActivityRule.launchActivity(new Intent(targetContext, ElectionChoiceActivity.class));
}
项目:polling-station-app    文件:TestResultActivity.java   
@Before
public void setUp() {
    Intents.init();

    // Wait till the splashactivity is closed, indicating blockchain was instantiated has started
    Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    splashActivityRule.launchActivity(new Intent(targetContext, SplashActivity.class));
    while (!splashActivityRule.getActivity().isFinishing()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    Context targetContext2 = InstrumentationRegistry.getInstrumentation()
            .getTargetContext();
    Intent intent = new Intent(targetContext2, ResultActivity.class);
    intent.putExtra("pubKey", pubKey);
    intent.putExtra("voter", voter);
    resultActivity = (ResultActivity) activityRule.launchActivity(intent);
}
项目:polling-station-app    文件:TestElectionChoice.java   
@Before
public void setUp() {
    Intents.init();

    // Wait till the splashactivity is closed, indicating blockchain was instantiated has started
    Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    mActivityRule.launchActivity(new Intent(targetContext, SplashActivity.class));
    while (!mActivityRule.getActivity().isFinishing()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    electionActivity = (ElectionChoiceActivity) mElectionActivityRule.launchActivity(new Intent(targetContext, ElectionChoiceActivity.class));
}
项目:smart-lens    文件:IntentTestUtils.java   
/**
 * Check if the activity is changed when any view is clicked.
 *
 * @param context          instance of the caller.
 * @param viewId           id of the view.
 * @param nextActivityName Name of the next activity.
 */
public static void checkActivityOnViewClicked(Context context,
                                              int viewId,
                                              String nextActivityName) {
    Intents.init();

    //set intent package
    intending(toPackage(context.getString(R.string.package_name)));

    // Perform click operation on FAB
    onView(withId(viewId)).perform(click());

    // Assert that if the opened activity is Quiz activity.
    intended(hasComponent(nextActivityName));

    Intents.release();
}
项目:AndroidTestingTutorial    文件:GalleryPickerTesting.java   
@Test
public void checkTextOnScreen() {
    //to check view on screen

    Intent resultData = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    resultData.setData(Uri.parse(("content://media/external/images/media/337663")));
    Matcher<Intent> MediaPickIntent = allOf(hasAction(Intent.ACTION_PICK), hasData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
    Intents.init();
    intending(MediaPickIntent).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData));

    onView(withText("Gallery")).perform(click());
    onView(withId(R.id.btnGalleryPick)).perform(click());
    intended(MediaPickIntent);
    //To check the image pick works or not
    try{
        Thread.sleep(4500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
项目:android-keep-testing    文件:HomeActivityTest.java   
@Test
public void shouldLoadUsersAndTriggerIntent() {
    serverRule
            .enqueueGET(200, "users.json")
            .assertPathIs("/2.2/users")
            .assertHasQuery("order", "desc")
            .assertHasQuery("sort", "reputation")
            .assertHasQuery("site", "stackoverflow");

    Intents.init();
    activityRule.launchActivity(new Intent(Intent.ACTION_MAIN));

    onView(withId(R.id.recyclerView))
            .perform(scrollToPosition(3));

    TestUtils.rotateScreen(activityRule);

    onView(withId(R.id.recyclerView))
            .perform(actionOnItemAtPosition(2, click()));

    intended(allOf(
            hasAction(Intent.ACTION_VIEW),
            hasData(Uri.parse("http://stackoverflow.com/users/157882/balusc"))
    ));
    Intents.release();
}
项目:android-keep-testing    文件:HomeActivityMockTest.java   
@Test
public void shouldLoadUsersAndTriggerIntent() {
    when(mockApi.getUsers(anyInt())).thenReturn(successResult());

    Intents.init();
    activityRule.launchActivity(new Intent(Intent.ACTION_MAIN));

    onView(withId(R.id.recyclerView))
            .perform(scrollToPosition(3));

    TestUtils.rotateScreen(activityRule);

    onView(withId(R.id.recyclerView))
            .perform(actionOnItemAtPosition(2, click()));

    intended(allOf(
            hasAction(Intent.ACTION_VIEW),
            hasData(Uri.parse("http://stackoverflow.com/users/157882/balusc"))
    ));
    Intents.release();
}
项目:android-keep-testing    文件:HomeActivityReflectionTest.java   
@Test
public void shouldLoadUsersAndTriggerIntent() {
    serverRule
            .enqueueGET(200, "users.json")
            .assertPathIs("/2.2/users")
            .assertHasQuery("order", "desc")
            .assertHasQuery("sort", "reputation")
            .assertHasQuery("site", "stackoverflow");

    Intents.init();
    activityRule.launchActivity(new Intent(Intent.ACTION_MAIN));

    onView(withId(R.id.recyclerView))
            .perform(scrollToPosition(3));

    TestUtils.rotateScreen(activityRule);

    onView(withId(R.id.recyclerView))
            .perform(actionOnItemAtPosition(2, click()));

    intended(allOf(
            hasAction(Intent.ACTION_VIEW),
            hasData(Uri.parse("http://stackoverflow.com/users/157882/balusc"))
    ));
    Intents.release();
}
项目:todos    文件:MainActivityTest.java   
public void testTapItem() {
    Intents.init();
    addInitialData();

    pause();

    // DO UI INTERACTION
    onView(withId(R.id.recycler)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click
            ()));

    pause();

    // Confirm that the TodoListActivity was started!
    intended(hasComponent(TodoListActivity.class.getName()));
    Intents.release();
}
项目:iosched    文件:SessionDetailActivity_InScheduleStarredSessionTest.java   
@Test
public void speakerImage_WhenClicked_IntentFired() {
    Intent resultData = new Intent();
    resultData.putExtras(new Bundle());

    // Create the ActivityResult with the Intent.
    Intents.intending(CoreMatchers.not(IntentMatchers.isInternal())).respondWith(
            new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData));

    // When clicking on speaker image
    onView(withId(R.id.session_detail_frag)).perform(swipeUp());
    onView(withId(R.id.speaker_image)).perform(click());

    // Then the intent to display the speaker url is fired
    Uri expectedSpeakerUri = Uri.parse(SpeakersMockCursor.FAKE_SPEAKER_URL);
    intended(CoreMatchers.allOf(
            hasAction(IsEqual.equalTo(Intent.ACTION_VIEW)),
            hasData(expectedSpeakerUri)));
}
项目:iosched    文件:SessionDetailActivity_EndedLiveStarredSessionTest.java   
@Test
public void youTubeVideo_WhenClicked_IntentFired() {
    Intent resultData = new Intent();
    resultData.putExtras(new Bundle());

    // Create the ActivityResult with the Intent.
    Intents.intending(CoreMatchers.not(IntentMatchers.isInternal())).respondWith(
            new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData));

    // When clicking on video
    onView(withId(R.id.watch)).perform(click());

    // Then the intent to play the video is fired
    IntentUtils.checkVideoIntentIsFired(SessionsMockCursor.FAKE_YOUTUBE_URL,
            mActivityRule.getActivity(), false);
}
项目:polling-station-app    文件:ElectionChoiceActivityTest.java   
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    activity.finish();
}
项目:polling-station-app    文件:TestResultActivity.java   
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    resultActivity.finish();
}
项目:polling-station-app    文件:TestElectionChoice.java   
@After
public void destroy() {
    Intents.release();
    try {
        BlockChain.getInstance(null).disconnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
    electionActivity.finish();
}
项目:cat-is-a-dog    文件:AuthTest.java   
@Before
public void setUp() throws Exception {
    Intents.init();

    mIdlingResource = mActivityRule.getActivity().getIdlingResource();
    IdlingRegistry.getInstance().register(mIdlingResource);
}
项目:cat-is-a-dog    文件:AuthTest.java   
@After
public void tearDown() {
    Intents.release();

    if (mIdlingResource != null) {
        IdlingRegistry.getInstance().unregister(mIdlingResource);
    }
}
项目:kheera-testrunner-android    文件:LoginPageFeatureFile.java   
@OnStartTest()
public void onStartTest(String featureName, String scenarioName) {

    IdlingPolicies.setMasterPolicyTimeout(30, TimeUnit.SECONDS);

    Log.v(runnerConfig.LogTag, "Starting Test: " + featureName + " - " + scenarioName);
    Intents.init();
}
项目:kheera-testrunner-android    文件:LoginPageFeatureFile.java   
@OnFinishTest()
public void onFinishTest(String featureName, String scenarioName) {
    getInstrumentation().waitForIdleSync();

    if (LoginScreen.ActivityInstance != null) {

        if (Build.VERSION.SDK_INT > 20) {
            LoginScreen.ActivityInstance.finishAndRemoveTask();
        }
    }

    Intents.release();
}
项目:Spork    文件:ImmediateIntentsTestRule.java   
@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            try {
                Intents.init();
                base.evaluate();
            } catch (Exception e) {
                Intents.release();
            }
        }
    };
}
项目:AndroidArchitecture    文件:RepositoriesActivityTest.java   
@Before
public void setUp() throws Exception {
    mContext = InstrumentationRegistry.getContext();
    ApiFactory.setProvider(new IntegrationProviderImpl(new TestServerImpl()));
    Intents.init();
    clearRepositories();
}
项目:AndroidArchitecture    文件:WalkthroughActivityTest.java   
@Test
public void testStartsLogInActivity() throws Exception {
    onView(withId(R.id.pager)).perform(swipeLeft());
    onView(withId(R.id.pager)).perform(swipeLeft());
    onView(withId(R.id.btn_walkthrough)).perform(click());

    Intents.intended(hasComponent(LogInActivity.class.getName()));
}
项目:AndroidArchitecture    文件:LogInActivityTest.java   
@Test
public void testErrorThenCorrect() throws Exception {
    errorInputAndClick();

    onView(LOGIN_INPUT_LAYOUT).check(matches(withInputError(R.string.error)));

    clearInputs();

    correctInputAndClick();
    Intents.intended(hasComponent(RepositoriesActivity.class.getName()));
}
项目:quickstart-android    文件:MainActivityTest.java   
@Before
public void before() {
    // Initialize intents
    Intents.init();

    // Idling resource
    mUploadIdlingResource = new ServiceIdlingResource(mActivityTestRule.getActivity(),
            MyUploadService.class);
    Espresso.registerIdlingResources(mUploadIdlingResource);
}
项目:quickstart-android    文件:MainActivityTest.java   
@After
public void after() {
    // Release intents
    Intents.release();

    // Idling resource
    if (mUploadIdlingResource != null) {
        Espresso.unregisterIdlingResources(mUploadIdlingResource);
    }
}
项目:2016.2-MissaoNascente    文件:MainScreenAcceptanceTest.java   
private void createCameraMockup(String qrCode){
    //mockup camera result
    Intent resultData = new Intent();
    resultData.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT, qrCode);
    Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
    Matcher<Intent> matcher  = hasAction(com.google.zxing.client.android.Intents.Scan.ACTION);

    OngoingStubbing ongoingStubbing  = intending(matcher);
    ongoingStubbing.respondWith(result);
    //end mockup camera result
}
项目:RecipeFinderJavaVersion    文件:RecipeAnalysisFragmentTest.java   
@Test
public void testRecipeAnalysis() {
    when(repository.getRecipeAnalysisData(ArgumentMatchers.<RecipeAnalysisParams>any()))
            .thenReturn(Single.just(AssetUtils.getRecipeAnalysisResult(context)));

    rule.launchActivity(new Intent());

    selectTab();
    inputFields();

    onView(withId(R.id.btn_analyze)).perform(click());
    Intents.intended(IntentMatchers.hasComponent(RecipeAnalysisDetailsActivity.class.getName()));
}
项目:material-activity-chooser    文件:SampleListStepDefinitions.java   
@SuppressWarnings("UnusedParameters")
@After
public static void after(Scenario scenario) {
    ActivityUtils.finishOpenActivities();
    Intents.release();
}
项目:AndroidSchool    文件:RepositoriesActivityTest.java   
@Test
public void testClickOnItem() throws Exception {
    onView(withId(R.id.recyclerView))
            .perform(actionOnItemAtPosition(14, click()));

    Intents.intended(hasComponent(CommitsActivity.class.getName()));
}
项目:AndroidSchool    文件:RepositoriesActivityTest.java   
@After
public void tearDown() throws Exception {
    Intents.release();
    if (idlingResource != null) {
        Espresso.unregisterIdlingResources(idlingResource);
    }
    RepositoryProvider.provideKeyValueStorage().clear();
    Realm.getDefaultInstance().executeTransaction(realm -> realm.deleteAll());
}
项目:AndroidSchool    文件:AuthActivityTest.java   
@Test
public void testSuccessAuth() throws Exception {
    onView(withId(R.id.loginEdit)).perform(typeText("login"));
    closeSoftKeyboard();
    onView(withId(R.id.passwordEdit)).perform(typeText("pass"));
    closeSoftKeyboard();
    onView(withId(R.id.logInButton)).perform(click());

    IdlingResource idlingResource = TimeIdlingResource.timeout(4000);
    Intents.intended(hasComponent(RepositoriesActivity.class.getName()));
    Espresso.unregisterIdlingResources(idlingResource);

}
项目:EDSApp    文件:WipeDataOnLogout.java   
@Test
public void wipeDataOnLogout(){
    //Given
    Intents.init();

    onView(withId(org.hisp.dhis.android.sdk.R.id.server_url)).perform(replaceText(SDKTestUtils.HNQIS_DEV_CI));
    onView(withId(org.hisp.dhis.android.sdk.R.id.username)).perform(replaceText(SDKTestUtils.TEST_USERNAME_WITH_PERMISSION));
    onView(withId(org.hisp.dhis.android.sdk.R.id.password)).perform(replaceText(SDKTestUtils.TEST_PASSWORD_WITH_PERMISSION));
    onView(withId(org.hisp.dhis.android.sdk.R.id.login_button)).perform(click());

    intended(hasComponent(ProgressActivity.class.getName()));

    //Waiting for pull to finish in order to clear the state of the app
    waitForPull(DEFAULT_WAIT_FOR_PULL);

    //When
    SDKTestUtils.goToLogin();

    //Then

    //Removed sdk data
    assertTrue(EventExtended.count() == 0);
    assertTrue(DataValueExtended.count() == 0);


    //removed app data
    assertTrue(Survey.count() == 0);
    assertTrue(Value.count() == 0);

    Intents.release();
}
项目:EDSApp    文件:LoginTest.java   
@Test
public void loginWithRightCredentials(){
    Intents.init();

    onView(withId(org.hisp.dhis.android.sdk.R.id.server_url)).perform(replaceText(SDKTestUtils.HNQIS_DEV_CI));
    onView(withId(org.hisp.dhis.android.sdk.R.id.username)).perform(replaceText(SDKTestUtils.TEST_USERNAME_WITH_PERMISSION));
    onView(withId(org.hisp.dhis.android.sdk.R.id.password)).perform(replaceText(SDKTestUtils.TEST_PASSWORD_WITH_PERMISSION));
    onView(withId(org.hisp.dhis.android.sdk.R.id.login_button)).perform(click());

    intended(hasComponent(ProgressActivity.class.getName()));

    //Waiting for pull to finish in order to clear the state of the app
    waitForPull(DEFAULT_WAIT_FOR_PULL);
    Intents.release();
}
项目:MicroPinner    文件:MainDialogParentPinTest.java   
@Before
public void setUp() {

    final Intent testIntent =
            new Intent(activityTestRule.getActivity(), MainDialog.class).putExtra(
                    NotificationTools.EXTRA_INTENT, Constants.testPin);

    Intents.init();
    activityTestRule.launchActivity(testIntent);
}
项目:kaif-android    文件:HomeActivityTest.java   
@Before
public void setUp() {
  Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
  KaifApplication app = (KaifApplication) instrumentation.getTargetContext()
      .getApplicationContext();
  TestBeans beans = DaggerTestBeans.builder().build();
  app.setBeans(beans);
  beans.inject(this);
  Intents.init();
}
项目:kaif-android    文件:LoginActivityTest.java   
@Before
public void setUp() {
  Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
  KaifApplication app = (KaifApplication) instrumentation.getTargetContext()
      .getApplicationContext();
  TestBeans beans = DaggerTestBeans.builder().build();
  app.setBeans(beans);
  beans.inject(this);
  Intents.init();
}
项目:malariapp    文件:WipeDataOnLogout.java   
@Test
public void wipeDataOnLogout(){
    //Given
    Intents.init();

    onView(withId(org.hisp.dhis.android.sdk.R.id.server_url)).perform(replaceText(SDKTestUtils.HNQIS_DEV_CI));
    onView(withId(org.hisp.dhis.android.sdk.R.id.username)).perform(replaceText(SDKTestUtils.TEST_USERNAME_WITH_PERMISSION));
    onView(withId(org.hisp.dhis.android.sdk.R.id.password)).perform(replaceText(SDKTestUtils.TEST_PASSWORD_WITH_PERMISSION));
    onView(withId(org.hisp.dhis.android.sdk.R.id.login_button)).perform(click());

    intended(hasComponent(ProgressActivity.class.getName()));

    //Waiting for pull to finish in order to clear the state of the app
    waitForPull(DEFAULT_WAIT_FOR_PULL);

    //When
    SDKTestUtils.goToLogin();

    //Then

    //Removed sdk data
    assertTrue(EventExtended.count() == 0);
    assertTrue(DataValueExtended.count() == 0);


    //removed app data
    assertTrue(Survey.count() == 0);
    assertTrue(Value.count() == 0);

    Intents.release();
}
项目:malariapp    文件:LoginTest.java   
@Test
public void loginWithRightCredentials(){
    Intents.init();

    onView(withId(org.hisp.dhis.android.sdk.R.id.server_url)).perform(replaceText(SDKTestUtils.HNQIS_DEV_CI));
    onView(withId(org.hisp.dhis.android.sdk.R.id.username)).perform(replaceText(SDKTestUtils.TEST_USERNAME_WITH_PERMISSION));
    onView(withId(org.hisp.dhis.android.sdk.R.id.password)).perform(replaceText(SDKTestUtils.TEST_PASSWORD_WITH_PERMISSION));
    onView(withId(org.hisp.dhis.android.sdk.R.id.login_button)).perform(click());

    intended(hasComponent(ProgressActivity.class.getName()));

    //Waiting for pull to finish in order to clear the state of the app
    waitForPull(DEFAULT_WAIT_FOR_PULL);
    Intents.release();
}
项目:espresso-samples    文件:MainActivityTest.java   
@Test
public void scan() {
  Context context = InstrumentationRegistry.getTargetContext();
  Assume.assumeTrue(MainActivity.isZXingSupported(context));

  final String format = "EAN_13";
  final String result = "9781449328214";

  Intents.init();

  activityRule.launchActivity(null);

  Intent data = new Intent();

  data.putExtra(MainActivity.KEY_SCAN_RESULT_FORMAT, format);
  data.putExtra(MainActivity.KEY_SCAN_RESULT, result);
  Instrumentation.ActivityResult activityResult = new Instrumentation.ActivityResult(
      Activity.RESULT_OK, data);

  intending(hasAction(MainActivity.ACTION_ZXING_SCAN))
      .respondWith(activityResult);

  onView(withId(R.id.scan_button))
      .check(matches(isDisplayed()))
      .perform(click());

  onView(withId(R.id.format))
      .check(matches(withText(format)));
  onView(withId(R.id.result))
      .check(matches(withText(result)));

  Intents.release();
}
项目:vb-android-app-quality    文件:TestMainActivityWithEspresso.java   
@Override
public void testThatDefaultBehaviorIsWorking() throws Exception {
    Instrumentation.ActivityResult dummyResult = new Instrumentation.ActivityResult(0, null);
    Intents.intending(allOf(
            hasAction(Intent.ACTION_SEND),
            IntentMatchers.hasExtra(Intent.EXTRA_SUBJECT, mActivityRule.getActivity().getString(R.string.share_title))))
            .respondWith(dummyResult);
    super.testThatDefaultBehaviorIsWorking();
}