Java Code Examples for android.widget.ImageButton#performClick()

The following examples show how to use android.widget.ImageButton#performClick() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormWidgetTests.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private void navigateFormStructure(Intent formEntryIntent) {
    // launch form entry
    FormEntryActivity formEntryActivity =
            Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent)
                    .create().start().resume().get();

    //Screen 1
    ImageButton nextButton = formEntryActivity.findViewById(R.id.nav_btn_next);

    assertTrue(screenContainsText(formEntryActivity, "QUESTION1"));

    nextButton.performClick();

    assertTrue("Form failed to proceed with required <trigger> question>",
            screenContainsText(formEntryActivity, "QUESTION2"));

    nextButton.performClick();

    assertTrue("Form failed to halt at violated <trigger> constraint",
    screenContainsText(formEntryActivity, "QUESTION2"));

    assertTrue("Form failed to display <trigger> constraint",
    screenContainsText(formEntryActivity, "TESTPASS"));
}
 
Example 2
Source File: MultimediaInflaterActivityTest.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure user sees invalid path toast when the file browser doesn't return a path uri
 */
@Test
public void emptyFileSelectionTest() {
    MultimediaInflaterActivity multimediaInflaterActivity =
            Robolectric.buildActivity(MultimediaInflaterActivity.class)
                    .create().start().resume().get();

    ImageButton selectFileButton =
            multimediaInflaterActivity.findViewById(
                    R.id.screen_multimedia_inflater_filefetch);
    selectFileButton.performClick();

    Intent fileSelectIntent = new Intent(Intent.ACTION_GET_CONTENT);
    fileSelectIntent.setType("application/zip");

    Intent emptyFileSelectResult = new Intent();

    ShadowActivity shadowActivity =
            Shadows.shadowOf(multimediaInflaterActivity);
    shadowActivity.receiveResult(fileSelectIntent,
            Activity.RESULT_OK,
            emptyFileSelectResult);

    Assert.assertEquals(Localization.get("file.invalid.path"),
            ShadowToast.getTextOfLatestToast());
}
 
Example 3
Source File: RouteFragmentTest.java    From open with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void arrowButtons_ShouldPageThrough() {
    Route route = fragment.getRoute();
    ArrayList<Instruction> instructions = route.getRouteInstructions();
    fragment.setInstructions(instructions);
    TestHelper.startFragment(fragment, act);
    int firstInstruction = fragment.pager.getCurrentItem();
    ImageButton rightArrow = (ImageButton) getInstructionView(firstInstruction)
            .findViewById(R.id.right_arrow);
    rightArrow.performClick();
    assertThat(fragment.pager.getCurrentItem() - 1).isEqualTo(firstInstruction);
    ImageButton leftArrow = (ImageButton) getInstructionView(firstInstruction)
            .findViewById(R.id.left_arrow);
    leftArrow.performClick();
    assertThat(fragment.pager.getCurrentItem()).isEqualTo(firstInstruction);
}
 
Example 4
Source File: StepCreateFragmentTest.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void whenClickPlayButtonWithoutSoundChosenExpectToastToBeDisplayed() {
    ImageButton playSound = (ImageButton) activity.findViewById(R.id.id_btn_play_step_sound);
    playSound.performClick();

    String expectedMessage = activity.getResources().getString(R.string.no_file_to_play_error);
    assertThat(ShadowToast.getTextOfLatestToast(), equalTo(expectedMessage));
}
 
Example 5
Source File: FormRecordProcessingTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private ShadowActivity navigateFormEntry(Intent formEntryIntent) {
    // launch form entry
    FormEntryActivity formEntryActivity =
            Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent)
                    .create().start().resume().get();

    // enter an answer for the question
    QuestionsView questionsView = formEntryActivity.getODKView();
    IntegerWidget cohort = (IntegerWidget)questionsView.getWidgets().get(0);
    cohort.setAnswer("2");

    ImageButton nextButton = formEntryActivity.findViewById(R.id.nav_btn_next);
    nextButton.performClick();
    View finishButton = formEntryActivity.findViewById(R.id.nav_btn_finish);
    finishButton.performClick();

    ShadowActivity shadowFormEntryActivity = Shadows.shadowOf(formEntryActivity);

    long waitStartTime = new Date().getTime();
    while (!shadowFormEntryActivity.isFinishing()) {
        Log.d(TAG, "Waiting for the form to save and the form entry activity to finish");
        if ((new Date().getTime()) - waitStartTime > 5000) {
            Assert.fail("form entry activity took too long to finish");
        }
    }

    return shadowFormEntryActivity;
}
 
Example 6
Source File: IntentCalloutTests.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private FormEntryActivity navigateFormStructure(Intent formEntryIntent) {
    // launch form entry
    FormEntryActivity formEntryActivity =
            Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent)
                    .create().start().resume().get();
    StringNumberWidget favoriteNumber = (StringNumberWidget)formEntryActivity.getODKView().getWidgets().get(0);
    favoriteNumber.setAnswer("1234567890");
    ImageButton nextButton = formEntryActivity.findViewById(R.id.nav_btn_next);
    nextButton.performClick();
    return formEntryActivity;
}
 
Example 7
Source File: CalendarLocaleTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void navigateCalendarForm(Intent formEntryIntent) {
    // launch form entry
    FormEntryActivity formEntryActivity =
            Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent)
                    .create().start().resume().get();

    ImageButton nextButton = formEntryActivity.findViewById(R.id.nav_btn_next);

    // enter an answer for the question
    TextView dayText = formEntryActivity.findViewById(R.id.daytxt);
    TextView monthText = formEntryActivity.findViewById(R.id.monthtxt);
    TextView yearText = formEntryActivity.findViewById(R.id.yeartxt);

    assertEquals(monthText.getText(), "Ashadh");
    assertEquals(dayText.getText(), "19");
    assertEquals(yearText.getText(), "2073");
    assertTrue(nextButton.getTag().equals(FormEntryConstants.NAV_STATE_NEXT));

    nextButton.performClick();

    TextView ethiopianDayText = formEntryActivity.findViewById(R.id.daytxt);
    TextView ethiopianMonthText = formEntryActivity.findViewById(R.id.monthtxt);
    TextView ethiopianYearText = formEntryActivity.findViewById(R.id.yeartxt);
    assertEquals("Säne",ethiopianMonthText.getText());
    assertEquals("26", ethiopianDayText.getText());
    assertEquals("2008", ethiopianYearText.getText());
}
 
Example 8
Source File: EntityListCalloutDataTest.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void clearCalloutResults() {
    // clear the callout data and make sure the extra column is removed and
    // all the entities are shown
    ImageButton clearSearchButton =
            entitySelectActivity.findViewById(R.id.clear_search_button);
    clearSearchButton.performClick();
}
 
Example 9
Source File: SearchViewAdapterTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldPostRoutePreviewEvent() throws Exception {
    View view = (View) adapter.instantiateItem(new FrameLayout(ACTIVITY), 0);
    ImageButton start = (ImageButton) view.findViewById(R.id.start);
    RoutePreviewSubscriber subscriber = new RoutePreviewSubscriber();
    bus.register(subscriber);
    start.performClick();
    assertThat(subscriber.getEvent().getSimpleFeature())
            .isEqualsToByComparingFields(getTestSimpleFeature());
}
 
Example 10
Source File: RouteFragmentTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onClickResume_shouldHideResumeButton() throws Exception {
    TestHelper.startFragment(fragment, act);
    View view = fragment.onCreateView(act.getLayoutInflater(), null, null);
    ImageButton resume = (ImageButton) view.findViewById(R.id.resume_button);
    simulateUserPagerTouch();
    resume.performClick();
    assertThat(resume).isNotVisible();
}
 
Example 11
Source File: RouteFragmentTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onClickResume_shouldStartAtPagerLocation() throws Exception {
    Route route = fragment.getRoute();
    ArrayList<Instruction> instructions = route.getRouteInstructions();
    fragment.setInstructions(instructions);
    TestHelper.startFragment(fragment, act);
    fragment.onLocationChanged(instructions.get(1).getLocation());
    fragment.onLocationChanged(instructions.get(2).getLocation());
    int expected = fragment.pager.getCurrentItem();
    simulateUserPagerTouch();
    fragment.pager.setCurrentItem(0);
    ImageButton resume = (ImageButton) fragment.getView().findViewById(R.id.resume_button);
    resume.performClick();
    assertThat(fragment.pager.getCurrentItem()).isEqualTo(expected);
}
 
Example 12
Source File: RoutePreviewFragmentTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void start_shouldStartRouting() throws Exception {
    fragment.createRouteToDestination();
    Route testRoute = new Route(getFixture("around_the_block"));
    fragment.success(testRoute);
    ImageButton startBtn = (ImageButton) fragment.getView().findViewById(R.id.routing_circle);
    startBtn.performClick();
    assertThat(activity.getSupportFragmentManager()).hasFragmentWithTag(RouteFragment.TAG);
}
 
Example 13
Source File: RoutePreviewFragmentTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void start_shouldNotStartRouting() throws Exception {
    fragment.createRouteToDestination();
    Route testRoute = new Route(getFixture("around_the_block"));
    fragment.success(testRoute);
    fragment.reverse();
    ImageButton startBtn = (ImageButton) fragment.getView().findViewById(R.id.routing_circle);
    startBtn.performClick();
    assertThat(activity.getSupportFragmentManager()).
            doesNotHaveFragmentWithTag(RouteFragment.TAG);
}
 
Example 14
Source File: FormIntentTests.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
private void navigateFormStructure(Intent formEntryIntent) {
    // launch form entry
    FormEntryActivity formEntryActivity =
            Robolectric.buildActivity(FormEntryActivity.class, formEntryIntent)
                    .create().start().resume().get();

    ImageButton nextButton = formEntryActivity.findViewById(R.id.nav_btn_next);

    testStandaloneIntent(formEntryActivity);

    nextButton.performClick();

    testMultipleIntent(formEntryActivity);

    nextButton.performClick();

    testMixedIntents(formEntryActivity);
}
 
Example 15
Source File: HY_Hybrid.java    From test-samples with Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hy_layout);

    inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);

    fl_urlPanel = (FrameLayout) findViewById(R.id.hy_fl_urlPanel);
    wv_webView = (WebView) findViewById(R.id.hy_wv_webview);
    pb_loading = (ProgressBar) findViewById(R.id.hy_pb_loading);
    et_url = (EditText) findViewById(R.id.hy_et_url);
    ib_loadUrl = (ImageButton) findViewById(R.id.hy_ib_loadUrl);
    ib_navigateBackward = (ImageButton) findViewById(R.id.hy_ib_navigateBack);
    ib_navigateForward = (ImageButton) findViewById(R.id.hy_ib_navigateForward);

    et_url.setOnClickListener(this);
    ib_loadUrl.setOnClickListener(this);
    ib_navigateBackward.setOnClickListener(this);
    ib_navigateForward.setOnClickListener(this);

    et_url.setOnFocusChangeListener(this.onFocusChangeListener);

    // setting WebView
    {
        WebSettings webSettings = wv_webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        wv_webView.setWebViewClient(this.webViewClient);
    }

    // enable WebView debugging - for Appium to be able to switch to WebView context
    setWebContentsDebuggingEnabled(true);

    // don't auto-pop keyboard
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // setting presets
    setNavigationButtons();

    ib_loadUrl.performClick();

}