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); }
// Used to perform clicks on pop-up buttons without having to close the virtual keyboard public void clickOnButton(String label) { final Button button = mSolo.getButton(label); try { runTestOnUiThread( new Runnable() { @Override public void run() { button.performClick(); } }); } catch (Throwable throwable) { mAsserter.ok(false, "Unable to click the button", "Was unable to click button "); } }