public void assertMatches(String value, String regex, String name) { if (value == null) { mAsserter.ok(false, name, "Expected /" + regex + "/, got null"); return; } mAsserter.ok(value.matches(regex), name, "Expected /" + regex + "/, got \"" + 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 "); } }
@Override protected void runTest() throws Throwable { try { super.runTest(); } catch (Throwable t) { // save screenshot -- written to /mnt/sdcard/Robotium-Screenshots // as <filename>.jpg mSolo.takeScreenshot("robocop-screenshot"); if (mAsserter != null) { mAsserter.dumpLog("Exception caught during test!", t); mAsserter.ok(false, "Exception caught", t.toString()); } // re-throw to continue bail-out throw t; } }
public final void verifyHomePagerHidden() { final View homePagerContainer = mSolo.getView(R.id.home_pager_container); boolean rc = waitForCondition( new Condition() { @Override public boolean isSatisfied() { return homePagerContainer.getVisibility() != View.VISIBLE; } }, MAX_WAIT_HOME_PAGER_HIDDEN_MS); if (!rc) { mAsserter.ok(rc, "Verify HomePager is hidden", "HomePager is hidden"); } }
public void addTab() { mSolo.clickOnView(mSolo.getView(R.id.tabs)); // wait for addTab to appear (this is usually immediate) boolean success = waitForCondition( new Condition() { @Override public boolean isSatisfied() { View addTabView = mSolo.getView(R.id.add_tab); if (addTabView == null) { return false; } return true; } }, MAX_WAIT_MS); mAsserter.ok(success, "waiting for add tab view", "add tab view available"); mSolo.clickOnView(mSolo.getView(R.id.add_tab)); }
/** * Gets the view in the tabs tray at the specified index. * * @return View at index */ private View getTabViewAt(final int index) { final View[] childView = {null}; final AdapterView<ListAdapter> view = getTabsList(); runOnUiThreadSync( new Runnable() { @Override public void run() { view.setSelection(index); // The selection isn't updated synchronously; posting a // runnable to the view's queue guarantees we'll run after the // layout pass. view.post( new Runnable() { @Override public void run() { // getChildAt() is relative to the list of visible // views, but our index is relative to all views in the // list. Subtract the first visible list position for // the correct offset. childView[0] = view.getChildAt(index - view.getFirstVisiblePosition()); } }); } }); boolean result = waitForCondition( new Condition() { @Override public boolean isSatisfied() { return childView[0] != null; } }, MAX_WAIT_MS); mAsserter.ok(result, "list item at index " + index + " exists", null); return childView[0]; }
/** Click on the URL bar to focus it and enter editing mode. */ protected final void focusUrlBar() { // Click on the browser toolbar to enter editing mode final View toolbarView = mSolo.getView(R.id.browser_toolbar); mSolo.clickOnView(toolbarView); // Wait for highlighed text to gain focus boolean success = waitForCondition( new Condition() { @Override public boolean isSatisfied() { EditText urlEditText = mSolo.getEditText(0); if (urlEditText.isInputMethodTarget()) { return true; } else { mSolo.clickOnEditText(0); return false; } } }, MAX_WAIT_ENABLED_TEXT_MS); mAsserter.ok(success, "waiting for urlbar text to gain focus", "urlbar text gained focus"); }