public void test060101() {
    activity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            // click user button
            assertTrue(UserButton.performClick());
          }
        });
    // click "Claimant" button and create next activity
    ActivityMonitor activityMonitor =
        getInstrumentation().addMonitor(ClaimantClaimListActivity.class.getName(), null, false);
    // get current activity
    MainActivity myActivity = getActivity();
    final Button button =
        (Button) myActivity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimantButton);
    // run main activity
    myActivity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            // click button and open next activity.
            button.performClick();
          }
        });
    // start next activity
    final ClaimantClaimListActivity nextActivity =
        (ClaimantClaimListActivity)
            getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 10000);
    // next activity is opened and captured.
    assertNotNull(nextActivity);

    // view which is expected to be present on the screen
    final View decorView1 = nextActivity.getWindow().getDecorView();
    // layout of claim list
    listView = (ListView) nextActivity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimListView);
    // check if it is on screen
    ViewAsserts.assertOnScreen(decorView1, listView);
    // check whether the Button object's width and height attributes match
    // the expected values
    final ViewGroup.LayoutParams layoutParams11 = listView.getLayoutParams();
    assertEquals(layoutParams11.width, WindowManager.LayoutParams.MATCH_PARENT);
    assertEquals(layoutParams11.height, WindowManager.LayoutParams.WRAP_CONTENT);
    final ListView claimList =
        (ListView) nextActivity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimListView);

    // get next activity
    nextActivity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            // click the list open next activity.
            ActivityMonitor am =
                getInstrumentation()
                    .addMonitor(ClaimantItemListActivity.class.getName(), null, false);
            // perform click on claim
            claimList.getChildAt(0).performClick();
            // start claimant item list activity
            ClaimantItemListActivity thirdActivity =
                (ClaimantItemListActivity)
                    getInstrumentation().waitForMonitorWithTimeout(am, 10000);
            // check if the activity is started
            assertNotNull(thirdActivity);

            /*
             * Test for US 06.01.01 Basic Flow 1
             */
            // get decorview
            final View decorView2 = nextActivity.getWindow().getDecorView();
            // get item list view
            ListView ilv =
                (ListView) thirdActivity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.itemListView);
            // check if it is on screen
            ViewAsserts.assertOnScreen(decorView2, ilv);

            /*
             * Test for US 06.01.01 Basic Flow 2
             */
            final ListView itemlist =
                (ListView) thirdActivity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.itemListView);
            // perform click on item
            thirdActivity.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    itemlist.getChildAt(0).performClick();
                  }
                });

            /*
             * Test for US 06.01.01 Basic Flow 3,4
             */
            // check dialogue
            AlertDialog d = (AlertDialog) thirdActivity.getDialog();
            // check if dialogue is returned by activity
            assertNotNull(d);

            // check option list
            ListView choose =
                (ListView) ilv.findViewById(ca.ualberta.CMPUT301W15T06.R.array.item_dialog_array);
            assertNotNull(choose);

            // perform click on option in array list
            choose.getChildAt(1).performClick();

            // start claimant receipt activity
            ActivityMonitor activityMonitor =
                getInstrumentation()
                    .addMonitor(ClaimantReceiptActivity.class.getName(), null, false);
            ClaimantReceiptActivity ccc =
                (ClaimantReceiptActivity)
                    getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 10000);
            // check if the activity is started
            assertNotNull(ccc);

            /*
             * Test for US 06.01.01 Basic Flow 5
             */
            ImageView iv =
                (ImageView) ccc.findViewById(ca.ualberta.CMPUT301W15T06.R.id.photoReciptImageView);
            // check if the view is shown on screen
            assertNotNull(iv);

            /*
             * Test for US 06.01.01 Basic Flow 6,7,8,9
             */
            // take photographic receipt
            ActivityMonitor mmm =
                getInstrumentation()
                    .addMonitor(ClaimantReceiptActivity.class.getName(), null, false);
            // Click the menu option
            getInstrumentation()
                .invokeMenuActionSync(nextActivity, ca.ualberta.CMPUT301W15T06.R.id.takephoto, 1);
            // start activity
            Activity a = getInstrumentation().waitForMonitorWithTimeout(am, 10000);
            assertNotNull(a);
            /*
             * Test for US 06.01.01 Basic Flow 10,11
             */
            a.finish();

            ImageView i1 =
                (ImageView) ccc.findViewById(ca.ualberta.CMPUT301W15T06.R.id.photoReciptImageView);
            assertNotNull(i1);
            ccc.finish();
          }
        });
    nextActivity.finish();
    activity.finish();
  }
  // test button exists
  public void test020201() {
    /*
     * Test for US02.01.01 Basic Flow 1
     */
    // test button exists
    assertNotNull(activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimantButton));
    assertNotNull(activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.approverButton));
    assertNotNull(activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.userButton));

    // test "Approver" button layout
    final View decorView = activity.getWindow().getDecorView();
    ViewAsserts.assertOnScreen(decorView, ApproverButton);
    final ViewGroup.LayoutParams layoutParams = ApproverButton.getLayoutParams();
    assertNotNull(layoutParams);
    assertEquals(layoutParams.width, WindowManager.LayoutParams.WRAP_CONTENT);
    assertEquals(layoutParams.height, WindowManager.LayoutParams.WRAP_CONTENT);
    Button view = (Button) activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.approverButton);
    assertEquals("Incorrect label of the button", "Approver", view.getText());

    // test "Claimant" button layout
    ViewAsserts.assertOnScreen(decorView, ClaimantButton);
    final ViewGroup.LayoutParams layoutParams1 = ClaimantButton.getLayoutParams();
    assertNotNull(layoutParams1);
    assertEquals(layoutParams1.width, WindowManager.LayoutParams.WRAP_CONTENT);
    assertEquals(layoutParams1.height, WindowManager.LayoutParams.WRAP_CONTENT);
    Button view1 = (Button) activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimantButton);
    assertEquals("Incorrect label of the button", "Claimant", view1.getText());

    // test "Change User" button layout
    ViewAsserts.assertOnScreen(decorView, ClaimantButton);
    final ViewGroup.LayoutParams layoutParams2 = UserButton.getLayoutParams();
    assertNotNull(layoutParams1);
    assertEquals(layoutParams2.width, WindowManager.LayoutParams.WRAP_CONTENT);
    assertEquals(layoutParams2.height, WindowManager.LayoutParams.WRAP_CONTENT);
    Button view2 = (Button) activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.userButton);
    assertEquals("Incorrect label of the button", "Change User", view2.getText());

    /*
     * Test for US02.02.01 Basic Flow 2
     */
    // User click "Change User"

    activity.runOnUiThread(
        new Runnable() {

          @Override
          public void run() {
            // open the dialog
            UserButton.performClick();
          }
        });

    /*
     * Test for US 02.02.01 Basic Flow 3
     */
    // click "Claimant" button and create next activity
    ActivityMonitor activityMonitor =
        getInstrumentation().addMonitor(ClaimantClaimListActivity.class.getName(), null, false);
    // open current activity
    MainActivity myActivity = getActivity();
    final Button button =
        (Button) myActivity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimantButton);

    myActivity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            // click button and open next activity.
            button.performClick();
          }
        });

    ClaimantClaimListActivity nextActivity =
        (ClaimantClaimListActivity)
            getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 10000);
    // next activity is opened and captured.
    assertNotNull(nextActivity);

    /*
     * Test for US 02.02.01 Basic Flow 4
     */
    // view which is expected to be present on the screen
    final View decorView1 = nextActivity.getWindow().getDecorView();
    listView = (ListView) nextActivity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimListView);
    // check if it is on screen
    ViewAsserts.assertOnScreen(decorView1, listView);
    // check whether the Button object's width and height attributes match
    // the expected values
    final ViewGroup.LayoutParams layoutParams11 = listView.getLayoutParams();
    /* assertNotNull(layoutParams); */
    assertEquals(layoutParams11.width, WindowManager.LayoutParams.MATCH_PARENT);
    assertEquals(layoutParams11.height, WindowManager.LayoutParams.WRAP_CONTENT);

    nextActivity.finish();
    activity.finish();
  }
示例#3
0
 @MediumTest
 public void testChildrenAligned() throws Exception {
   ViewAsserts.assertBaselineAligned(mSpinner, mButton);
 }