Ejemplo n.º 1
0
  protected Object getDocumentCreationDate(int position) throws Exception {
    ArrayList<ListView> listViews = solo.getCurrentListViews();
    if (listViews == null || listViews.size() == 0) {
      return null;
    }
    ListView listview = listViews.get(0);
    ListAdapter adapter = listview.getAdapter();

    Method method = null;

    try {
      method = adapter.getClass().getMethod("getDocumentAttribute", Integer.class, String.class);
    } catch (NoSuchMethodException e) {
      Log.e(
          this.getClass().getSimpleName(),
          "Unable to find test method getDocumentAttribute on adapter "
              + adapter.getClass().getName());
    }

    if (method != null) {
      return method.invoke(adapter, position, "dc:created");
    } else {
      return null;
    }
  }
Ejemplo n.º 2
0
  protected String getDocumentTitle(int position) throws Exception {
    ArrayList<ListView> listViews = solo.getCurrentListViews();
    if (listViews == null || listViews.size() == 0) {
      return "No List View";
    }
    ListView listview = listViews.get(0);
    ListAdapter adapter = listview.getAdapter();

    Method method = null;

    try {
      method = adapter.getClass().getMethod("getDocumentAttribute", Integer.class, String.class);
    } catch (NoSuchMethodException e) {
      throw new RuntimeException(
          "Unable to find test method getDocumentAttribute on adapter "
              + adapter.getClass().getName());
      // Log.e(this.getClass().getSimpleName(),
      // "Unable to find test method getDocumentAttribute on adapter " +
      // adapter.getClass().getName());
    }

    if (method != null) {
      String value = (String) method.invoke(adapter, position, "dc:title");
      if (value == null) {
        throw new RuntimeException("Null title returned");
      }
      return value;
    } else {
      return null;
    }
  }
Ejemplo n.º 3
0
  public void home() {

    // Scroll listviews up
    final ArrayList<ListView> viewList = solo.getCurrentListViews();
    if (viewList.size() > 0) {
      getActivity()
          .runOnUiThread(
              new Runnable() {
                public void run() {
                  viewList.get(0).setSelection(0);
                }
              });
    }

    // Scroll scrollviews up
    final ArrayList<ScrollView> viewScroll = solo.getCurrentScrollViews();
    if (viewScroll.size() > 0) {
      getActivity()
          .runOnUiThread(
              new Runnable() {
                public void run() {
                  viewScroll.get(0).fullScroll(ScrollView.FOCUS_UP);
                }
              });
    }
    sync();
  }
Ejemplo n.º 4
0
 private void selectSpinnerItem(final Spinner s, int num) {
   assertNotNull(s, "Cannon press spinner item: the spinner does not exist");
   Log.i("nofatclips", "Clicking the spinner view");
   click(s);
   sync();
   selectListItem(solo.getCurrentListViews().get(0), num, false);
 }
Ejemplo n.º 5
0
 public void fireEvent(
     int widgetIndex, String widgetName, String widgetType, String eventType, String value) {
   View v = null;
   if (eventType.equals(BACK) || eventType.equals(SCROLL_DOWN)) {
     fireEventOnView(null, eventType, null);
     return;
   } else if (eventType.equals(CLICK_ON_TEXT)) {
     Log.d("nofatclips", "Firing event: type= " + eventType + " value= " + value);
     fireEventOnView(null, eventType, value);
   }
   if (widgetType.equals(BUTTON)) {
     v = solo.getButton(widgetName);
   } else if (widgetType.equals(MENU_ITEM)) {
     v = solo.getText(widgetName);
   } else if (widgetType.equals(LIST_VIEW)) {
     v = solo.getCurrentListViews().get(0);
   }
   if (v == null) {
     for (View w : getAllWidgets()) {
       if (w instanceof Button) {
         Button candidate = (Button) w;
         if (candidate.getText().equals(widgetName)) {
           v = candidate;
         }
       }
       if (v != null) break;
     }
   }
   fireEventOnView(v, eventType, value);
 }
Ejemplo n.º 6
0
  protected String getDocumentStatus(int position) throws Exception {
    ArrayList<ListView> listViews = solo.getCurrentListViews();
    if (listViews == null || listViews.size() == 0) {
      return null;
    }
    ListView listview = listViews.get(0);
    ListAdapter adapter = listview.getAdapter();

    Method method = adapter.getClass().getMethod("getDocumentStatus", Integer.class);
    if (method != null) {
      return (String) method.invoke(adapter, position);
    } else {

      return null;
    }
  }
Ejemplo n.º 7
0
  @Smoke
  public void testNXTMotorActionBrick() {
    ScriptTabActivity activity = (ScriptTabActivity) solo.getCurrentActivity();
    ScriptFragment fragment =
        (ScriptFragment) activity.getTabFragment(ScriptTabActivity.INDEX_TAB_SCRIPTS);
    BrickAdapter adapter = fragment.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals(
        "Incorrect number of bricks.",
        2 + 1,
        solo.getCurrentListViews().get(0).getChildCount()); // don't forget the footer
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull(
        "TextView does not exist.",
        solo.getText(getActivity().getString(R.string.brick_motor_action)));
    assertNotNull(
        "TextView does not exist.", solo.getText(getActivity().getString(R.string.motor_speed)));

    String buttonOkText = solo.getString(R.string.ok);
    solo.clickOnEditText(0);
    solo.waitForText(buttonOkText);
    solo.clearEditText(0);
    solo.enterText(0, SET_SPEED + "");
    solo.clickOnButton(buttonOkText);

    int speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", SET_SPEED, speed);
    assertEquals(
        "Value in Brick is not updated.", SET_SPEED + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        SET_SPEED + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(
        0,
        SET_SPEED_INITIALLY
            + 100); // robotium doesnt go through proper function onProgressChanged() to change
                    // value on progress bar!
    solo.sleep(200);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", SET_SPEED_INITIALLY, speed);
    assertEquals(
        "Value in Brick is not updated.",
        SET_SPEED_INITIALLY + "",
        solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        SET_SPEED_INITIALLY + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.clickOnButton(0);
    int speedCounter = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speedCounter, speed - 1);
    assertEquals(
        "Value in Brick is not updated.", speed - 1 + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed - 1 + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.clickOnButton(1);
    speedCounter = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speedCounter, speed);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(0, 1);
    solo.clickOnButton(0);
    solo.clickOnButton(0);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speed, MIN_SPEED);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    solo.setProgressBar(0, MAX_SPEED + 100);
    solo.clickOnButton(1);
    solo.clickOnButton(1);
    speed = (Integer) UiTestUtils.getPrivateField("speed", motorBrick);
    assertEquals("Wrong text in field.", speed, MAX_SPEED);
    assertEquals(
        "Value in Brick is not updated.", speed + "", solo.getEditText(0).getText().toString());
    assertEquals(
        "SeekBar is at wrong position",
        speed + 100,
        solo.getCurrentProgressBars().get(0).getProgress());

    String[] motors = getActivity().getResources().getStringArray(R.array.nxt_motor_chooser);
    assertTrue("Spinner items list too short!", motors.length == 4);

    Spinner currentSpinner = solo.getCurrentSpinners().get(0);
    solo.pressSpinnerItem(0, 0);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[0], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[1], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[2], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(0, 1);
    solo.waitForActivity(ScriptTabActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[3], currentSpinner.getSelectedItem());
  }