Пример #1
0
 // set up
 protected void setUp() throws Exception {
   super.setUp();
   AppSingleton.getInstance().setTest(true);
   instrumentation = getInstrumentation();
   activity = getActivity();
   setActivityInitialTouchMode(false);
   ApproverButton = (Button) activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.approverButton);
   ClaimantButton = (Button) activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimantButton);
   UserButton = (Button) activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.userButton);
   intent = new Intent(getInstrumentation().getTargetContext(), MainActivity.class);
   u = AppSingleton.getInstance().getCurrentUser();
 }
Пример #2
0
  // 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
  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();
  }
Пример #4
0
  public void testUS100301() {

    // User click "Change User"
    activity.runOnUiThread(
        new Runnable() {

          @Override
          public void run() {

            // click button to start another activity
            assertTrue(UserButton.performClick());
          }
        });

    // click "Claimant" button and create next activity
    final Button button =
        (Button) activity.findViewById(ca.ualberta.CMPUT301W15T06.R.id.claimantButton);
    activity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {

            // click button and open next activity.
            button.performClick();
            ActivityMonitor activityMonitor =
                getInstrumentation().addMonitor(MainActivity.class.getName(), null, false);
            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
            // test claim list layout
            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);

            /*
             * Test for US10.03.01 Basic Flow 1,2
             */
            // after claimant request to add new claim, a new claim should be added into list
            int count1 = u.getClaimList().size();
            assertEquals(count1, 0);
            // Click the menu option
            // open third activity by options menu
            ActivityMonitor am =
                getInstrumentation()
                    .addMonitor(ClaimantEditClaimActivity.class.getName(), null, false);

            // Click the menu option
            // getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
            getInstrumentation()
                .invokeMenuActionSync(
                    nextActivity, ca.ualberta.CMPUT301W15T06.R.id.show_home_location, 1);
            ShowLocationActivity aaa =
                (ShowLocationActivity) getInstrumentation().waitForMonitorWithTimeout(am, 10000);
            assertNotNull(aaa);

            ImageView image =
                (ImageView) aaa.findViewById(ca.ualberta.CMPUT301W15T06.R.drawable.worldmap);
            assertNotNull(image);
            // get space for recording location
            TextView tv = (TextView) aaa.findViewById(ca.ualberta.CMPUT301W15T06.R.id.llTextView);
            assertNotNull(tv);

            getInstrumentation()
                .invokeMenuActionSync(
                    nextActivity, ca.ualberta.CMPUT301W15T06.R.id.set_home_location, 1);
            ShowLocationActivity qqq =
                (ShowLocationActivity) getInstrumentation().waitForMonitorWithTimeout(am, 10000);
            assertNotNull(qqq);

            ImageView ii =
                (ImageView) aaa.findViewById(ca.ualberta.CMPUT301W15T06.R.drawable.worldmap);
            assertNotNull(ii);
            // get space for recording location
            TextView tt = (TextView) aaa.findViewById(ca.ualberta.CMPUT301W15T06.R.id.llTextView);
            assertNotNull(tt);

            qqq.finish();
            aaa.finish();
            nextActivity.finish();
          }
        });
    activity.finish();
  }