PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/robotium-solo/src/main/java/com/robotium/solo/Solo.java

https://github.com/andreasnilsson/robotium
Java | 2718 lines | 904 code | 448 blank | 1366 comment | 45 complexity | f39fc446cf99dba81071e8147a8719d7 MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. package com.robotium.solo;
  2. import java.lang.reflect.Method;
  3. import java.util.ArrayList;
  4. import junit.framework.Assert;
  5. import android.app.Activity;
  6. import android.app.Instrumentation;
  7. import android.content.pm.ActivityInfo;
  8. import android.graphics.PointF;
  9. import android.os.Environment;
  10. import android.view.KeyEvent;
  11. import android.view.View;
  12. import android.view.WindowManager;
  13. import android.webkit.WebView;
  14. import android.widget.AbsListView;
  15. import android.widget.Button;
  16. import android.widget.CheckBox;
  17. import android.widget.CheckedTextView;
  18. import android.widget.CompoundButton;
  19. import android.widget.DatePicker;
  20. import android.widget.EditText;
  21. import android.widget.ImageButton;
  22. import android.widget.ImageView;
  23. import android.widget.ProgressBar;
  24. import android.widget.RadioButton;
  25. import android.widget.ScrollView;
  26. import android.widget.SlidingDrawer;
  27. import android.widget.Spinner;
  28. import android.widget.TextView;
  29. import android.widget.ListView;
  30. import android.widget.TimePicker;
  31. import android.widget.ToggleButton;
  32. import android.app.Instrumentation.ActivityMonitor;
  33. /**
  34. * Main class for development of Robotium tests.
  35. * Robotium has full support for Views, WebViews, Activities, Dialogs, Menus and Context Menus.
  36. * <br>
  37. * Robotium can be used in conjunction with Android test classes like
  38. * ActivityInstrumentationTestCase2 and SingleLaunchActivityTestCase.
  39. *
  40. *
  41. *
  42. *
  43. * @author Renas Reda, renas.reda@robotium.com
  44. */
  45. public class Solo {
  46. protected final Asserter asserter;
  47. protected final ViewFetcher viewFetcher;
  48. protected final Checker checker;
  49. protected final Clicker clicker;
  50. protected final Presser presser;
  51. protected final Searcher searcher;
  52. protected final ActivityUtils activityUtils;
  53. protected final DialogUtils dialogUtils;
  54. protected final TextEnterer textEnterer;
  55. protected final Rotator rotator;
  56. protected final Scroller scroller;
  57. protected final Sleeper sleeper;
  58. protected final Swiper swiper;
  59. protected final Tapper tapper;
  60. protected final Waiter waiter;
  61. protected final Setter setter;
  62. protected final Getter getter;
  63. protected final WebUtils webUtils;
  64. protected final Sender sender;
  65. protected final ScreenshotTaker screenshotTaker;
  66. protected final Instrumentation instrumentation;
  67. protected final Zoomer zoomer;
  68. protected String webUrl = null;
  69. private final Config config;
  70. public final static int LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // 0
  71. public final static int PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 1
  72. public final static int RIGHT = KeyEvent.KEYCODE_DPAD_RIGHT;
  73. public final static int LEFT = KeyEvent.KEYCODE_DPAD_LEFT;
  74. public final static int UP = KeyEvent.KEYCODE_DPAD_UP;
  75. public final static int DOWN = KeyEvent.KEYCODE_DPAD_DOWN;
  76. public final static int ENTER = KeyEvent.KEYCODE_ENTER;
  77. public final static int MENU = KeyEvent.KEYCODE_MENU;
  78. public final static int DELETE = KeyEvent.KEYCODE_DEL;
  79. public final static int CLOSED = 0;
  80. public final static int OPENED = 1;
  81. /**
  82. * Constructor that takes the Instrumentation object and the start Activity.
  83. *
  84. * @param instrumentation the {@link Instrumentation} instance
  85. * @param activity the start {@link Activity} or {@code null}
  86. * if no Activity is specified
  87. */
  88. public Solo(Instrumentation instrumentation, Activity activity) {
  89. this(new Config(), instrumentation, activity);
  90. }
  91. /**
  92. * Constructor that takes the Instrumentation and Config objects.
  93. *
  94. * @param instrumentation the {@link Instrumentation} instance
  95. * @param config the {@link Config} instance
  96. */
  97. public Solo(Instrumentation instrumentation, Config config) {
  98. this(config, instrumentation, null);
  99. }
  100. /**
  101. * Constructor that takes the Instrumentation, Config and Activity objects.
  102. *
  103. * @param instrumentation the {@link Instrumentation} instance
  104. * @param config the {@link Config} instance
  105. * @param activity the start {@link Activity} or {@code null}
  106. * if no Activity is specified
  107. */
  108. public Solo(Instrumentation instrumentation, Config config, Activity activity) {
  109. this(config, instrumentation, activity);
  110. }
  111. /**
  112. * Private constructor.
  113. *
  114. * @param config the {@link Config} instance. If {@code null} one will be created.
  115. * @param instrumentation the {@link Instrumentation} instance
  116. * @param activity the start {@link Activity} or {@code null}
  117. * if no Activity is specified
  118. */
  119. private Solo(Config config, Instrumentation instrumentation, Activity activity) {
  120. this.config = (config == null) ? new Config(): config;
  121. this.instrumentation = instrumentation;
  122. this.sleeper = new Sleeper();
  123. this.sender = new Sender(instrumentation, sleeper);
  124. this.activityUtils = new ActivityUtils(instrumentation, activity, sleeper);
  125. this.viewFetcher = new ViewFetcher(activityUtils);
  126. this.screenshotTaker = new ScreenshotTaker(config, activityUtils, viewFetcher, sleeper);
  127. this.dialogUtils = new DialogUtils(activityUtils, viewFetcher, sleeper);
  128. this.webUtils = new WebUtils(config, instrumentation,activityUtils,viewFetcher, sleeper);
  129. this.scroller = new Scroller(config, instrumentation, activityUtils, viewFetcher, sleeper);
  130. this.searcher = new Searcher(viewFetcher, webUtils, scroller, sleeper);
  131. this.waiter = new Waiter(activityUtils, viewFetcher, searcher,scroller, sleeper);
  132. this.getter = new Getter(instrumentation, activityUtils, waiter);
  133. this.clicker = new Clicker(activityUtils, viewFetcher,sender, instrumentation, sleeper, waiter, webUtils, dialogUtils);
  134. this.setter = new Setter(activityUtils, getter, clicker, waiter);
  135. this.asserter = new Asserter(activityUtils, waiter);
  136. this.checker = new Checker(viewFetcher, waiter);
  137. this.zoomer = new Zoomer(instrumentation);
  138. this.swiper = new Swiper(instrumentation);
  139. this.tapper = new Tapper(instrumentation);
  140. this.rotator = new Rotator(instrumentation);
  141. this.presser = new Presser(viewFetcher, clicker, instrumentation, sleeper, waiter, dialogUtils);
  142. this.textEnterer = new TextEnterer(instrumentation, clicker, dialogUtils);
  143. initialize();
  144. }
  145. /**
  146. * Config class used to set the scroll behaviour, default timeouts, screenshot filetype and screenshot save path.
  147. * <br> <br>
  148. * Example of usage:
  149. * <pre>
  150. * public void setUp() throws Exception {
  151. * Config config = new Config();
  152. * config.screenshotFileType = ScreenshotFileType.PNG;
  153. * config.screenshotSavePath = Environment.getExternalStorageDirectory() + "/Robotium/";
  154. * config.shouldScroll = false;
  155. * solo = new Solo(getInstrumentation(), config);
  156. * getActivity();
  157. * }
  158. * </pre>
  159. *
  160. * @author Renas Reda, renas.reda@robotium.com
  161. */
  162. public static class Config {
  163. /**
  164. * The timeout length of the get, is, set, assert, enter and click methods. Default length is 10 000 milliseconds.
  165. */
  166. public int timeout_small = 10000;
  167. /**
  168. * The timeout length of the waitFor methods. Default length is 20 000 milliseconds.
  169. */
  170. public int timeout_large = 20000;
  171. /**
  172. * The screenshot save path. Default save path is /sdcard/Robotium-Screenshots/.
  173. */
  174. public String screenshotSavePath = Environment.getExternalStorageDirectory() + "/Robotium-Screenshots/";
  175. /**
  176. * The screenshot file type, JPEG or PNG. Use ScreenshotFileType.JPEG or ScreenshotFileType.PNG. Default file type is JPEG.
  177. */
  178. public ScreenshotFileType screenshotFileType = ScreenshotFileType.JPEG;
  179. /**
  180. * Set to true if the get, is, set, enter, type and click methods should scroll. Default value is true.
  181. */
  182. public boolean shouldScroll = true;
  183. /**
  184. * Set to true if JavaScript should be used to click WebElements. Default value is false.
  185. */
  186. public boolean useJavaScriptToClickWebElements = false;
  187. /**
  188. * The screenshot file type, JPEG or PNG.
  189. *
  190. * @author Renas Reda, renas.reda@robotium.com
  191. *
  192. */
  193. public enum ScreenshotFileType {
  194. JPEG, PNG
  195. }
  196. }
  197. /**
  198. * Constructor that takes the instrumentation object.
  199. *
  200. * @param instrumentation the {@link Instrumentation} instance
  201. */
  202. public Solo(Instrumentation instrumentation) {
  203. this(new Config(), instrumentation, null);
  204. }
  205. /**
  206. * Returns the ActivityMonitor used by Robotium.
  207. *
  208. * @return the ActivityMonitor used by Robotium
  209. */
  210. public ActivityMonitor getActivityMonitor(){
  211. return activityUtils.getActivityMonitor();
  212. }
  213. /**
  214. * Returns the Config used by Robotium.
  215. *
  216. * @return the Config used by Robotium
  217. */
  218. public Config getConfig(){
  219. return config;
  220. }
  221. /**
  222. * Returns an ArrayList of all the View objects located in the focused
  223. * Activity or Dialog.
  224. *
  225. * @return an {@code ArrayList} of the {@link View} objects located in the focused window
  226. */
  227. public ArrayList<View> getViews() {
  228. try {
  229. return viewFetcher.getViews(null, false);
  230. } catch (Exception e) {
  231. e.printStackTrace();
  232. return null;
  233. }
  234. }
  235. /**
  236. * Returns an ArrayList of the View objects contained in the parent View.
  237. *
  238. * @param parent the parent view from which to return the views
  239. * @return an {@code ArrayList} of the {@link View} objects contained in the specified {@code View}
  240. */
  241. public ArrayList<View> getViews(View parent) {
  242. try {
  243. return viewFetcher.getViews(parent, false);
  244. } catch (Exception e) {
  245. e.printStackTrace();
  246. return null;
  247. }
  248. }
  249. /**
  250. * Returns the absolute top parent View of the specified View.
  251. *
  252. * @param view the {@link View} whose top parent is requested
  253. * @return the top parent {@link View}
  254. */
  255. public View getTopParent(View view) {
  256. View topParent = viewFetcher.getTopParent(view);
  257. return topParent;
  258. }
  259. /**
  260. * Waits for the specified text to appear. Default timeout is 20 seconds.
  261. *
  262. * @param text the text to wait for, specified as a regular expression
  263. * @return {@code true} if text is displayed and {@code false} if it is not displayed before the timeout
  264. */
  265. public boolean waitForText(String text) {
  266. return (waiter.waitForText(text) != null);
  267. }
  268. /**
  269. * Waits for the specified text to appear.
  270. *
  271. * @param text the text to wait for, specified as a regular expression
  272. * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
  273. * @param timeout the the amount of time in milliseconds to wait
  274. * @return {@code true} if text is displayed and {@code false} if it is not displayed before the timeout
  275. */
  276. public boolean waitForText(String text, int minimumNumberOfMatches, long timeout) {
  277. return (waiter.waitForText(text, minimumNumberOfMatches, timeout) != null);
  278. }
  279. /**
  280. * Waits for the specified text to appear.
  281. *
  282. * @param text the text to wait for, specified as a regular expression
  283. * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
  284. * @param timeout the the amount of time in milliseconds to wait
  285. * @param scroll {@code true} if scrolling should be performed
  286. * @return {@code true} if text is displayed and {@code false} if it is not displayed before the timeout
  287. */
  288. public boolean waitForText(String text, int minimumNumberOfMatches, long timeout, boolean scroll) {
  289. return (waiter.waitForText(text, minimumNumberOfMatches, timeout, scroll) != null);
  290. }
  291. /**
  292. * Waits for the specified text to appear.
  293. *
  294. * @param text the text to wait for, specified as a regular expression
  295. * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
  296. * @param timeout the the amount of time in milliseconds to wait
  297. * @param scroll {@code true} if scrolling should be performed
  298. * @param onlyVisible {@code true} if only visible text views should be waited for
  299. * @return {@code true} if text is displayed and {@code false} if it is not displayed before the timeout
  300. */
  301. public boolean waitForText(String text, int minimumNumberOfMatches, long timeout, boolean scroll, boolean onlyVisible) {
  302. return (waiter.waitForText(text, minimumNumberOfMatches, timeout, scroll, onlyVisible, true) != null);
  303. }
  304. /**
  305. * Waits for a View matching the specified resource id. Default timeout is 20 seconds.
  306. *
  307. * @param id the R.id of the {@link View} to wait for
  308. * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
  309. */
  310. public boolean waitForView(int id){
  311. return waitForView(id, 0, Timeout.getLargeTimeout(), true);
  312. }
  313. /**
  314. * Waits for a View matching the specified resource id.
  315. *
  316. * @param id the R.id of the {@link View} to wait for
  317. * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
  318. * @param timeout the amount of time in milliseconds to wait
  319. * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
  320. */
  321. public boolean waitForView(int id, int minimumNumberOfMatches, int timeout){
  322. return waitForView(id, minimumNumberOfMatches, timeout, true);
  323. }
  324. /**
  325. * Waits for a View matching the specified resource id.
  326. *
  327. * @param id the R.id of the {@link View} to wait for
  328. * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
  329. * @param timeout the amount of time in milliseconds to wait
  330. * @param scroll {@code true} if scrolling should be performed
  331. * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
  332. */
  333. public boolean waitForView(int id, int minimumNumberOfMatches, int timeout, boolean scroll){
  334. int index = minimumNumberOfMatches-1;
  335. if(index < 1)
  336. index = 0;
  337. return (waiter.waitForView(id, index, timeout, scroll) != null);
  338. }
  339. /**
  340. * Waits for a View matching the specified class. Default timeout is 20 seconds.
  341. *
  342. * @param viewClass the {@link View} class to wait for
  343. * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
  344. */
  345. public <T extends View> boolean waitForView(final Class<T> viewClass){
  346. return waiter.waitForView(viewClass, 0, Timeout.getLargeTimeout(), true);
  347. }
  348. /**
  349. * Waits for the specified View. Default timeout is 20 seconds.
  350. *
  351. * @param view the {@link View} object to wait for
  352. * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
  353. */
  354. public <T extends View> boolean waitForView(View view){
  355. return waiter.waitForView(view);
  356. }
  357. /**
  358. * Waits for the specified View.
  359. *
  360. * @param view the {@link View} object to wait for
  361. * @param timeout the amount of time in milliseconds to wait
  362. * @param scroll {@code true} if scrolling should be performed
  363. * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
  364. */
  365. public <T extends View> boolean waitForView(View view, int timeout, boolean scroll){
  366. boolean checkIsShown = false;
  367. if(!scroll){
  368. checkIsShown = true;
  369. }
  370. View viewToWaitFor = waiter.waitForView(view, timeout, scroll, checkIsShown);
  371. if(viewToWaitFor != null)
  372. return true;
  373. return false;
  374. }
  375. /**
  376. * Waits for a View matching the specified class.
  377. *
  378. * @param viewClass the {@link View} class to wait for
  379. * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
  380. * @param timeout the amount of time in milliseconds to wait
  381. * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
  382. */
  383. public <T extends View> boolean waitForView(final Class<T> viewClass, final int minimumNumberOfMatches, final int timeout){
  384. int index = minimumNumberOfMatches-1;
  385. if(index < 1)
  386. index = 0;
  387. return waiter.waitForView(viewClass, index, timeout, true);
  388. }
  389. /**
  390. * Waits for a View matching the specified class.
  391. *
  392. * @param viewClass the {@link View} class to wait for
  393. * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
  394. * @param timeout the amount of time in milliseconds to wait
  395. * @param scroll {@code true} if scrolling should be performed
  396. * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
  397. */
  398. public <T extends View> boolean waitForView(final Class<T> viewClass, final int minimumNumberOfMatches, final int timeout,final boolean scroll){
  399. int index = minimumNumberOfMatches-1;
  400. if(index < 1)
  401. index = 0;
  402. return waiter.waitForView(viewClass, index, timeout, scroll);
  403. }
  404. /**
  405. * Waits for a WebElement matching the specified By object. Default timeout is 20 seconds.
  406. *
  407. * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
  408. * @return {@code true} if the {@link WebElement} is displayed and {@code false} if it is not displayed before the timeout
  409. */
  410. public boolean waitForWebElement(By by){
  411. return (waiter.waitForWebElement(by, 0, Timeout.getLargeTimeout(), true) != null);
  412. }
  413. /**
  414. * Waits for a WebElement matching the specified By object.
  415. *
  416. * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
  417. * @param timeout the the amount of time in milliseconds to wait
  418. * @param scroll {@code true} if scrolling should be performed
  419. * @return {@code true} if the {@link WebElement} is displayed and {@code false} if it is not displayed before the timeout
  420. */
  421. public boolean waitForWebElement(By by, int timeout, boolean scroll){
  422. return (waiter.waitForWebElement(by, 0, timeout, scroll) != null);
  423. }
  424. /**
  425. * Waits for a WebElement matching the specified By object.
  426. *
  427. * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
  428. * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
  429. * @param timeout the the amount of time in milliseconds to wait
  430. * @param scroll {@code true} if scrolling should be performed
  431. * @return {@code true} if the {@link WebElement} is displayed and {@code false} if it is not displayed before the timeout
  432. */
  433. public boolean waitForWebElement(By by, int minimumNumberOfMatches, int timeout, boolean scroll){
  434. return (waiter.waitForWebElement(by, minimumNumberOfMatches, timeout, scroll) != null);
  435. }
  436. /**
  437. * Waits for a condition to be satisfied.
  438. *
  439. * @param condition the condition to wait for
  440. * @param timeout the amount of time in milliseconds to wait
  441. * @return {@code true} if condition is satisfied and {@code false} if it is not satisfied before the timeout
  442. */
  443. public boolean waitForCondition(Condition condition, final int timeout){
  444. return waiter.waitForCondition(condition, timeout);
  445. }
  446. /**
  447. * Searches for a text in the EditText objects currently displayed and returns true if found. Will automatically scroll when needed.
  448. *
  449. * @param text the text to search for
  450. * @return {@code true} if an {@link EditText} displaying the specified text is found or {@code false} if it is not found
  451. */
  452. public boolean searchEditText(String text) {
  453. return searcher.searchWithTimeoutFor(EditText.class, text, 1, true, false);
  454. }
  455. /**
  456. * Searches for a Button displaying the specified text and returns {@code true} if at least one Button
  457. * is found. Will automatically scroll when needed.
  458. *
  459. * @param text the text to search for. The parameter will be interpreted as a regular expression
  460. * @return {@code true} if a {@link Button} displaying the specified text is found and {@code false} if it is not found
  461. */
  462. public boolean searchButton(String text) {
  463. return searcher.searchWithTimeoutFor(Button.class, text, 0, true, false);
  464. }
  465. /**
  466. * Searches for a Button displaying the specified text and returns {@code true} if at least one Button
  467. * is found. Will automatically scroll when needed.
  468. *
  469. * @param text the text to search for. The parameter will be interpreted as a regular expression
  470. * @param onlyVisible {@code true} if only {@link Button} visible on the screen should be searched
  471. * @return {@code true} if a {@link Button} displaying the specified text is found and {@code false} if it is not found
  472. */
  473. public boolean searchButton(String text, boolean onlyVisible) {
  474. return searcher.searchWithTimeoutFor(Button.class, text, 0, true, onlyVisible);
  475. }
  476. /**
  477. * Searches for a ToggleButton displaying the specified text and returns {@code true} if at least one ToggleButton
  478. * is found. Will automatically scroll when needed.
  479. *
  480. * @param text the text to search for. The parameter will be interpreted as a regular expression
  481. * @return {@code true} if a {@link ToggleButton} displaying the specified text is found and {@code false} if it is not found
  482. */
  483. public boolean searchToggleButton(String text) {
  484. return searcher.searchWithTimeoutFor(ToggleButton.class, text, 0, true, false);
  485. }
  486. /**
  487. * Searches for a Button displaying the specified text and returns {@code true} if the
  488. * searched Button is found a specified number of times. Will automatically scroll when needed.
  489. *
  490. * @param text the text to search for. The parameter will be interpreted as a regular expression
  491. * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
  492. * matches are expected to be found
  493. * @return {@code true} if a {@link Button} displaying the specified text is found a specified number of times and {@code false}
  494. * if it is not found
  495. */
  496. public boolean searchButton(String text, int minimumNumberOfMatches) {
  497. return searcher.searchWithTimeoutFor(Button.class, text, minimumNumberOfMatches, true, false);
  498. }
  499. /**
  500. * Searches for a Button displaying the specified text and returns {@code true} if the
  501. * searched Button is found a specified number of times. Will automatically scroll when needed.
  502. *
  503. * @param text the text to search for. The parameter will be interpreted as a regular expression
  504. * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
  505. * matches are expected to be found
  506. * @param onlyVisible {@code true} if only {@link Button} visible on the screen should be searched
  507. * @return {@code true} if a {@link Button} displaying the specified text is found a specified number of times and {@code false}
  508. * if it is not found
  509. */
  510. public boolean searchButton(String text, int minimumNumberOfMatches, boolean onlyVisible) {
  511. return searcher.searchWithTimeoutFor(Button.class, text, minimumNumberOfMatches, true, onlyVisible);
  512. }
  513. /**
  514. * Searches for a ToggleButton displaying the specified text and returns {@code true} if the
  515. * searched ToggleButton is found a specified number of times. Will automatically scroll when needed.
  516. *
  517. * @param text the text to search for. The parameter will be interpreted as a regular expression
  518. * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
  519. * matches are expected to be found
  520. * @return {@code true} if a {@link ToggleButton} displaying the specified text is found a specified number of times and {@code false}
  521. * if it is not found
  522. */
  523. public boolean searchToggleButton(String text, int minimumNumberOfMatches) {
  524. return searcher.searchWithTimeoutFor(ToggleButton.class, text, minimumNumberOfMatches, true, false);
  525. }
  526. /**
  527. * Searches for the specified text and returns {@code true} if at least one item
  528. * is found displaying the expected text. Will automatically scroll when needed.
  529. *
  530. * @param text the text to search for. The parameter will be interpreted as a regular expression
  531. * @return {@code true} if the search string is found and {@code false} if it is not found
  532. */
  533. public boolean searchText(String text) {
  534. return searcher.searchWithTimeoutFor(TextView.class, text, 0, true, false);
  535. }
  536. /**
  537. * Searches for the specified text and returns {@code true} if at least one item
  538. * is found displaying the expected text. Will automatically scroll when needed.
  539. *
  540. * @param text the text to search for. The parameter will be interpreted as a regular expression
  541. * @param onlyVisible {@code true} if only texts visible on the screen should be searched
  542. * @return {@code true} if the search string is found and {@code false} if it is not found
  543. */
  544. public boolean searchText(String text, boolean onlyVisible) {
  545. return searcher.searchWithTimeoutFor(TextView.class, text, 0, true, onlyVisible);
  546. }
  547. /**
  548. * Searches for the specified text and returns {@code true} if the searched text is found a specified
  549. * number of times. Will automatically scroll when needed.
  550. *
  551. * @param text the text to search for. The parameter will be interpreted as a regular expression
  552. * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
  553. * matches are expected to be found
  554. * @return {@code true} if text is found a specified number of times and {@code false} if the text
  555. * is not found
  556. */
  557. public boolean searchText(String text, int minimumNumberOfMatches) {
  558. return searcher.searchWithTimeoutFor(TextView.class, text, minimumNumberOfMatches, true, false);
  559. }
  560. /**
  561. * Searches for the specified text and returns {@code true} if the searched text is found a specified
  562. * number of times.
  563. *
  564. * @param text the text to search for. The parameter will be interpreted as a regular expression.
  565. * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
  566. * matches are expected to be found
  567. * @param scroll {@code true} if scrolling should be performed
  568. * @return {@code true} if text is found a specified number of times and {@code false} if the text
  569. * is not found
  570. */
  571. public boolean searchText(String text, int minimumNumberOfMatches, boolean scroll) {
  572. return searcher.searchWithTimeoutFor(TextView.class, text, minimumNumberOfMatches, scroll, false);
  573. }
  574. /**
  575. * Searches for the specified text and returns {@code true} if the searched text is found a specified
  576. * number of times.
  577. *
  578. * @param text the text to search for. The parameter will be interpreted as a regular expression.
  579. * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
  580. * matches are expected to be found
  581. * @param scroll {@code true} if scrolling should be performed
  582. * @param onlyVisible {@code true} if only texts visible on the screen should be searched
  583. * @return {@code true} if text is found a specified number of times and {@code false} if the text
  584. * is not found
  585. */
  586. public boolean searchText(String text, int minimumNumberOfMatches, boolean scroll, boolean onlyVisible) {
  587. return searcher.searchWithTimeoutFor(TextView.class, text, minimumNumberOfMatches, scroll, onlyVisible);
  588. }
  589. /**
  590. * Sets the Orientation (Landscape/Portrait) for the current Activity.
  591. *
  592. * @param orientation the orientation to set. <code>Solo.</code>{@link #LANDSCAPE} for landscape or
  593. * <code>Solo.</code>{@link #PORTRAIT} for portrait.
  594. */
  595. public void setActivityOrientation(int orientation)
  596. {
  597. activityUtils.setActivityOrientation(orientation);
  598. }
  599. /**
  600. * Returns the current Activity.
  601. *
  602. * @return the current Activity
  603. */
  604. public Activity getCurrentActivity() {
  605. return activityUtils.getCurrentActivity(false);
  606. }
  607. /**
  608. * Asserts that the Activity matching the specified name is active.
  609. *
  610. * @param message the message to display if the assert fails
  611. * @param name the name of the {@link Activity} that is expected to be active. Example is: {@code "MyActivity"}
  612. */
  613. public void assertCurrentActivity(String message, String name)
  614. {
  615. asserter.assertCurrentActivity(message, name);
  616. }
  617. /**
  618. * Asserts that the Activity matching the specified class is active.
  619. *
  620. * @param message the message to display if the assert fails
  621. * @param activityClass the class of the Activity that is expected to be active. Example is: {@code MyActivity.class}
  622. */
  623. @SuppressWarnings("unchecked")
  624. public void assertCurrentActivity(String message, @SuppressWarnings("rawtypes") Class activityClass)
  625. {
  626. asserter.assertCurrentActivity(message, activityClass);
  627. }
  628. /**
  629. * Asserts that the Activity matching the specified name is active, with the possibility to
  630. * verify that the expected Activity is a new instance of the Activity.
  631. *
  632. * @param message the message to display if the assert fails
  633. * @param name the name of the Activity that is expected to be active. Example is: {@code "MyActivity"}
  634. * @param isNewInstance {@code true} if the expected {@link Activity} is a new instance of the {@link Activity}
  635. */
  636. public void assertCurrentActivity(String message, String name, boolean isNewInstance)
  637. {
  638. asserter.assertCurrentActivity(message, name, isNewInstance);
  639. }
  640. /**
  641. * Asserts that the Activity matching the specified class is active, with the possibility to
  642. * verify that the expected Activity is a new instance of the Activity.
  643. *
  644. * @param message the message to display if the assert fails
  645. * @param activityClass the class of the Activity that is expected to be active. Example is: {@code MyActivity.class}
  646. * @param isNewInstance {@code true} if the expected {@link Activity} is a new instance of the {@link Activity}
  647. */
  648. @SuppressWarnings("unchecked")
  649. public void assertCurrentActivity(String message, @SuppressWarnings("rawtypes") Class activityClass,
  650. boolean isNewInstance) {
  651. asserter.assertCurrentActivity(message, activityClass, isNewInstance);
  652. }
  653. /**
  654. * Asserts that the available memory is not considered low by the system.
  655. */
  656. public void assertMemoryNotLow()
  657. {
  658. asserter.assertMemoryNotLow();
  659. }
  660. /**
  661. * Waits for a Dialog to open. Default timeout is 20 seconds.
  662. *
  663. * @return {@code true} if the {@link android.app.Dialog} is opened before the timeout and {@code false} if it is not opened
  664. */
  665. public boolean waitForDialogToOpen() {
  666. return dialogUtils.waitForDialogToOpen(Timeout.getLargeTimeout(), true);
  667. }
  668. /**
  669. * Waits for a Dialog to close. Default timeout is 20 seconds.
  670. *
  671. * @return {@code true} if the {@link android.app.Dialog} is closed before the timeout and {@code false} if it is not closed
  672. */
  673. public boolean waitForDialogToClose() {
  674. return dialogUtils.waitForDialogToClose(Timeout.getLargeTimeout());
  675. }
  676. /**
  677. * Waits for a Dialog to open.
  678. *
  679. * @param timeout the amount of time in milliseconds to wait
  680. * @return {@code true} if the {@link android.app.Dialog} is opened before the timeout and {@code false} if it is not opened
  681. */
  682. public boolean waitForDialogToOpen(long timeout) {
  683. return dialogUtils.waitForDialogToOpen(timeout, true);
  684. }
  685. /**
  686. * Waits for a Dialog to close.
  687. *
  688. * @param timeout the amount of time in milliseconds to wait
  689. * @return {@code true} if the {@link android.app.Dialog} is closed before the timeout and {@code false} if it is not closed
  690. */
  691. public boolean waitForDialogToClose(long timeout) {
  692. return dialogUtils.waitForDialogToClose(timeout);
  693. }
  694. /**
  695. * Simulates pressing the hardware back key.
  696. */
  697. public void goBack()
  698. {
  699. hideSoftKeyboard();
  700. sender.goBack();
  701. }
  702. /**
  703. * Clicks the specified coordinates.
  704. *
  705. * @param x the x coordinate
  706. * @param y the y coordinate
  707. */
  708. public void clickOnScreen(float x, float y) {
  709. sleeper.sleep();
  710. clicker.clickOnScreen(x, y, null);
  711. }
  712. /**
  713. * Clicks the specified coordinates rapidly a specified number of times. Requires API level >= 14.
  714. *
  715. * @param x the x coordinate
  716. * @param y the y coordinate
  717. * @param numberOfClicks the number of clicks to perform
  718. */
  719. public void clickOnScreen(float x, float y, int numberOfClicks) {
  720. if (android.os.Build.VERSION.SDK_INT < 14){
  721. throw new RuntimeException("clickOnScreen(float x, float y, int numberOfClicks) requires API level >= 14");
  722. }
  723. tapper.generateTapGesture(numberOfClicks, new PointF(x, y));
  724. }
  725. /**
  726. * Long clicks the specified coordinates.
  727. *
  728. * @param x the x coordinate
  729. * @param y the y coordinate
  730. */
  731. public void clickLongOnScreen(float x, float y) {
  732. clicker.clickLongOnScreen(x, y, 0, null);
  733. }
  734. /**
  735. * Long clicks the specified coordinates for a specified amount of time.
  736. *
  737. * @param x the x coordinate
  738. * @param y the y coordinate
  739. * @param time the amount of time to long click
  740. */
  741. public void clickLongOnScreen(float x, float y, int time) {
  742. clicker.clickLongOnScreen(x, y, time, null);
  743. }
  744. /**
  745. * Clicks a Button displaying the specified text. Will automatically scroll when needed.
  746. *
  747. * @param text the text displayed by the {@link Button}. The parameter will be interpreted as a regular expression
  748. */
  749. public void clickOnButton(String text) {
  750. clicker.clickOn(Button.class, text);
  751. }
  752. /**
  753. * Clicks an ImageButton matching the specified index.
  754. *
  755. * @param index the index of the {@link ImageButton} to click. 0 if only one is available
  756. */
  757. public void clickOnImageButton(int index) {
  758. clicker.clickOn(ImageButton.class, index);
  759. }
  760. /**
  761. * Clicks a ToggleButton displaying the specified text.
  762. *
  763. * @param text the text displayed by the {@link ToggleButton}. The parameter will be interpreted as a regular expression
  764. */
  765. public void clickOnToggleButton(String text) {
  766. clicker.clickOn(ToggleButton.class, text);
  767. }
  768. /**
  769. * Clicks a MenuItem displaying the specified text.
  770. *
  771. * @param text the text displayed by the MenuItem. The parameter will be interpreted as a regular expression
  772. */
  773. public void clickOnMenuItem(String text)
  774. {
  775. clicker.clickOnMenuItem(text);
  776. }
  777. /**
  778. * Clicks a MenuItem displaying the specified text.
  779. *
  780. * @param text the text displayed by the MenuItem. The parameter will be interpreted as a regular expression
  781. * @param subMenu {@code true} if the menu item could be located in a sub menu
  782. */
  783. public void clickOnMenuItem(String text, boolean subMenu)
  784. {
  785. clicker.clickOnMenuItem(text, subMenu);
  786. }
  787. /**
  788. * Clicks the specified WebElement.
  789. *
  790. * @param webElement the WebElement to click
  791. */
  792. public void clickOnWebElement(WebElement webElement){
  793. if(webElement == null)
  794. Assert.fail("WebElement is null and can therefore not be clicked!");
  795. clicker.clickOnScreen(webElement.getLocationX(), webElement.getLocationY(), null);
  796. }
  797. /**
  798. * Clicks a WebElement matching the specified By object.
  799. *
  800. * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
  801. */
  802. public void clickOnWebElement(By by){
  803. clickOnWebElement(by, 0, true);
  804. }
  805. /**
  806. * Clicks a WebElement matching the specified By object.
  807. *
  808. * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
  809. * @param match if multiple objects match, this determines which one to click
  810. */
  811. public void clickOnWebElement(By by, int match){
  812. clickOnWebElement(by, match, true);
  813. }
  814. /**
  815. * Clicks a WebElement matching the specified By object.
  816. *
  817. * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
  818. * @param match if multiple objects match, this determines which one to click
  819. * @param scroll {@code true} if scrolling should be performed
  820. */
  821. public void clickOnWebElement(By by, int match, boolean scroll){
  822. clicker.clickOnWebElement(by, match, scroll, config.useJavaScriptToClickWebElements);
  823. }
  824. /**
  825. * Presses a MenuItem matching the specified index. Index {@code 0} is the first item in the
  826. * first row, Index {@code 3} is the first item in the second row and
  827. * index {@code 6} is the first item in the third row.
  828. *
  829. * @param index the index of the {@link android.view.MenuItem} to press
  830. */
  831. public void pressMenuItem(int index) {
  832. presser.pressMenuItem(index);
  833. }
  834. /**
  835. * Presses a MenuItem matching the specified index. Supports three rows with a specified amount
  836. * of items. If itemsPerRow equals 5 then index 0 is the first item in the first row,
  837. * index 5 is the first item in the second row and index 10 is the first item in the third row.
  838. *
  839. * @param index the index of the {@link android.view.MenuItem} to press
  840. * @param itemsPerRow the amount of menu items there are per row
  841. */
  842. public void pressMenuItem(int index, int itemsPerRow) {
  843. presser.pressMenuItem(index, itemsPerRow);
  844. }
  845. /**
  846. * Presses the soft keyboard next button.
  847. */
  848. public void pressSoftKeyboardNextButton(){
  849. presser.pressSoftKeyboardSearchOrNextButton(false);
  850. }
  851. /**
  852. * Presses the soft keyboard search button.
  853. */
  854. public void pressSoftKeyboardSearchButton(){
  855. presser.pressSoftKeyboardSearchOrNextButton(true);
  856. }
  857. /**
  858. * Presses a Spinner (drop-down menu) item.
  859. *
  860. * @param spinnerIndex the index of the {@link Spinner} menu to use
  861. * @param itemIndex the index of the {@link Spinner} item to press relative to the currently selected item.
  862. * A Negative number moves up on the {@link Spinner}, positive moves down
  863. */
  864. public void pressSpinnerItem(int spinnerIndex, int itemIndex)
  865. {
  866. presser.pressSpinnerItem(spinnerIndex, itemIndex);
  867. }
  868. /**
  869. * Clicks the specified View.
  870. *
  871. * @param view the {@link View} to click
  872. */
  873. public void clickOnView(View view) {
  874. view = waiter.waitForView(view, Timeout.getSmallTimeout());
  875. clicker.clickOnScreen(view);
  876. }
  877. /**
  878. * Clicks the specified View.
  879. *
  880. * @param view the {@link View} to click
  881. * @param immediately {@code true} if View should be clicked without any wait
  882. */
  883. public void clickOnView(View view, boolean immediately){
  884. if(immediately)
  885. clicker.clickOnScreen(view);
  886. else{
  887. view = waiter.waitForView(view, Timeout.getSmallTimeout());
  888. clicker.clickOnScreen(view);
  889. }
  890. }
  891. /**
  892. * Long clicks the specified View.
  893. *
  894. * @param view the {@link View} to long click
  895. */
  896. public void clickLongOnView(View view) {
  897. view = waiter.waitForView(view, Timeout.getSmallTimeout());
  898. clicker.clickOnScreen(view, true, 0);
  899. }
  900. /**
  901. * Long clicks the specified View for a specified amount of time.
  902. *
  903. * @param view the {@link View} to long click
  904. * @param time the amount of time to long click
  905. */
  906. public void clickLongOnView(View view, int time) {
  907. clicker.clickOnScreen(view, true, time);
  908. }
  909. /**
  910. * Clicks a View or WebElement displaying the specified
  911. * text. Will automatically scroll when needed.
  912. *
  913. * @param text the text to click. The parameter will be interpreted as a regular expression
  914. */
  915. public void clickOnText(String text) {
  916. clicker.clickOnText(text, false, 1, true, 0);
  917. }
  918. /**
  919. * Clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.
  920. *
  921. * @param text the text to click. The parameter will be interpreted as a regular expression
  922. * @param match if multiple objects match the text, this determines which one to click
  923. */
  924. public void clickOnText(String text, int match) {
  925. clicker.clickOnText(text, false, match, true, 0);
  926. }
  927. /**
  928. * Clicks a View or WebElement displaying the specified text.
  929. *
  930. * @param text the text to click. The parameter will be interpreted as a regular expression
  931. * @param match if multiple objects match the text, this determines which one to click
  932. * @param scroll {@code true} if scrolling should be performed
  933. */
  934. public void clickOnText(String text, int match, boolean scroll) {
  935. clicker.clickOnText(text, false, match, scroll, 0);
  936. }
  937. /**
  938. * Long clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.
  939. *
  940. * @param text the text to click. The parameter will be interpreted as a regular expression
  941. */
  942. public void clickLongOnText(String text)
  943. {
  944. clicker.clickOnText(text, true, 1, true, 0);
  945. }
  946. /**
  947. * Long clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.
  948. *
  949. * @param text the text to click. The parameter will be interpreted as a regular expression
  950. * @param match if multiple objects match the text, this determines which one to click
  951. */
  952. public void clickLongOnText(String text, int match)
  953. {
  954. clicker.clickOnText(text, true, match, true, 0);
  955. }
  956. /**
  957. * Long clicks a View or WebElement displaying the specified text.
  958. *
  959. * @param text the text to click. The parameter will be interpreted as a regular expression
  960. * @param match if multiple objects match the text, this determines which one to click
  961. * @param scroll {@code true} if scrolling should be performed
  962. */
  963. public void clickLongOnText(String text, int match, boolean scroll)
  964. {
  965. clicker.clickOnText(text, true, match, scroll, 0);
  966. }
  967. /**
  968. * Long clicks a View or WebElement displaying the specified text.
  969. *
  970. * @param text the text to click. The parameter will be interpreted as a regular expression
  971. * @param match if multiple objects match the text, this determines which one to click
  972. * @param time the amount of time to long click
  973. */
  974. public void clickLongOnText(String text, int match, int time)
  975. {
  976. clicker.clickOnText(text, true, match, true, time);
  977. }
  978. /**
  979. * Long clicks a View displaying the specified text and then selects
  980. * an item from the context menu that appears. Will automatically scroll when needed.
  981. *
  982. * @param text the text to click. The parameter will be interpreted as a regular expression
  983. * @param index the index of the menu item to press. {@code 0} if only one is available
  984. */
  985. public void clickLongOnTextAndPress(String text, int index) {
  986. clicker.clickLongOnTextAndPress(text, index);
  987. }
  988. /**
  989. * Clicks a Button matching the specified index.
  990. *
  991. * @param index the index of the {@link Button} to click. {@code 0} if only one is available
  992. */
  993. public void clickOnButton(int index) {
  994. clicker.clickOn(Button.class, index);
  995. }
  996. /**
  997. * Clicks a RadioButton matching the specified index.
  998. *
  999. * @param index the index of the {@link RadioButton} to click. {@code 0} if only one is available
  1000. */
  1001. public void clickOnRadioButton(int index) {
  1002. clicker.clickOn(RadioButton.class, index);
  1003. }
  1004. /**
  1005. * Clicks a CheckBox matching the specified index.
  1006. *
  1007. * @param index the index of the {@link CheckBox} to click. {@code 0} if only one is available
  1008. */
  1009. public void clickOnCheckBox(int index) {
  1010. clicker.clickOn(CheckBox.class, index);
  1011. }
  1012. /**
  1013. * Clicks an EditText matching the specified index.
  1014. *
  1015. * @param index the index of the {@link EditText} to click. {@code 0} if only one is available
  1016. */
  1017. public void clickOnEditText(int index) {
  1018. clicker.clickOn(EditText.class, index);
  1019. }
  1020. /**
  1021. * Clicks the specified list line and returns an ArrayList of the TextView objects that
  1022. * the list line is displaying. Will use the first ListView it finds.
  1023. *
  1024. * @param line the line to click
  1025. * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
  1026. */
  1027. public ArrayList<TextView> clickInList(int line) {
  1028. return clicker.clickInList(line);
  1029. }
  1030. /**
  1031. * Clicks the specified list line in the ListView matching the specified index and
  1032. * returns an ArrayList of the TextView objects that the list line is displaying.
  1033. *
  1034. * @param line the line to click
  1035. * @param index the index of the list. {@code 0} if only one is available
  1036. * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
  1037. */
  1038. public ArrayList<TextView> clickInList(int line, int index) {
  1039. return clicker.clickInList(line, index, false, 0);
  1040. }
  1041. /**
  1042. * Long clicks the specified list line and returns an ArrayList of the TextView objects that
  1043. * the list line is displaying. Will use the first ListView it finds.
  1044. *
  1045. * @param line the line to click
  1046. * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
  1047. */
  1048. public ArrayList<TextView> clickLongInList(int line){
  1049. return clicker.clickInList(line, 0, true, 0);
  1050. }
  1051. /**
  1052. * Long clicks the specified list line in the ListView matching the specified index and
  1053. * returns an ArrayList of the TextView objects that the list line is displaying.
  1054. *
  1055. * @param line the line to click
  1056. * @param index the index of the list. {@code 0} if only one is available
  1057. * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
  1058. */
  1059. public ArrayList<TextView> clickLongInList(int line, int index){
  1060. return clicker.clickInList(line, index, true, 0);
  1061. }
  1062. /**
  1063. * Long clicks the specified list line in the ListView matching the specified index and
  1064. * returns an ArrayList of the TextView objects that the list line is displaying.
  1065. *
  1066. * @param line the line to click
  1067. * @param index the index of the list. {@code 0} if only one is available
  1068. * @param time the amount of time to long click
  1069. * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
  1070. */
  1071. public ArrayList<TextView> clickLongInList(int line, int index, int time){
  1072. return clicker.clickInList(line, index, true, time);
  1073. }
  1074. /**
  1075. * Clicks an ActionBarItem matching the specified resource id.
  1076. *
  1077. * @param id the R.id of the ActionBar item to click
  1078. */
  1079. public void clickOnActionBarItem(int id){
  1080. clicker.clickOnActionBarItem(id);
  1081. }
  1082. /**
  1083. * Clicks an ActionBar Home/Up button.
  1084. */
  1085. public void clickOnActionBarHomeButton() {
  1086. clicker.clickOnActionBarHomeButton();
  1087. }
  1088. /**
  1089. * Simulate touching the specified location and dragging it to a new location.
  1090. *
  1091. *
  1092. * @param fromX X coordinate of the initial touch, in screen coordinates
  1093. * @param toX X coordinate of the drag destination, in screen coordinates
  1094. * @param fromY Y coordinate of the initial touch, in screen coordinates
  1095. * @param toY Y coordinate of the drag destination, in screen coordinates
  1096. * @param stepCount how many move steps to include in the drag. Less steps results in a faster drag
  1097. */
  1098. public void drag(float fromX, float toX, float fromY, float toY,
  1099. int stepCount) {
  1100. dialogUtils.hideSoftKeyboard(null, false, true);
  1101. scroller.drag(fromX, toX, fromY, toY, stepCount);
  1102. }
  1103. /**
  1104. * Scrolls down the screen.
  1105. *
  1106. * @return {@code true} if more scrolling can be performed and {@code false} if it is at the end of
  1107. * the screen
  1108. */
  1109. @SuppressWarnings("unchecked")
  1110. public boolean scrollDown() {
  1111. waiter.waitForViews(true, AbsListView.class, ScrollView.class, WebView.class);
  1112. return scroller.scroll(Scroller.DOWN);
  1113. }
  1114. /**
  1115. * Scrolls to the bottom of the screen.
  1116. */
  1117. @SuppressWarnings("unchecked")
  1118. public void scrollToBottom() {
  1119. waiter.waitForViews(true, AbsListView.class, ScrollView.class, WebView.class);
  1120. scroller.scroll(Scroller.DOWN, true);
  1121. }
  1122. /**
  1123. * Scrolls up the screen.
  1124. *
  1125. * @return {@code true} if more scrolling can be performed and {@code false} if it is at the top of
  1126. * the screen
  1127. */
  1128. @SuppressWarnings("unchecked")
  1129. public boolean scrollUp(){
  1130. waiter.waitForViews(true, AbsListView.class, ScrollView.class, WebView.class);
  1131. return scroller.scroll(Scroller.UP);
  1132. }
  1133. /**
  1134. * Scrolls to the top of the screen.
  1135. */
  1136. @SuppressWarnings("unchecked")
  1137. public void scrollToTop() {
  1138. waiter.waitForViews(true, AbsListView.class, ScrollView.class, WebView.class);
  1139. scroller.scroll(Scroller.UP, true);
  1140. }
  1141. /**
  1142. * Scrolls down the specified AbsListView.
  1143. *
  1144. * @param list the {@link AbsListView} to scroll
  1145. * @return {@code true} if more scrolling can be performed
  1146. */
  1147. public boolean scrollDownList(AbsListView list) {
  1148. return scroller.scrollList(list, Scroller.DOWN, false);
  1149. }
  1150. /**
  1151. * Scrolls to the bottom of the specified AbsListView.
  1152. *
  1153. * @param list the {@link AbsListView} to scroll
  1154. * @return {@code true} if more scrolling can be performed
  1155. */
  1156. public boolean scrollListToBottom(AbsListView list) {
  1157. return scroller.scrollList(list, Scroller.DOWN, true);
  1158. }
  1159. /**
  1160. * Scrolls up the specified AbsListView.
  1161. *
  1162. * @param list the {@link AbsListView} to scroll
  1163. * @return {@code true} if more scrolling can be performed
  1164. */
  1165. public boolean scrollUpList(AbsListView list) {
  1166. return scroller.scrollList(list, Scroller.UP, false);
  1167. }
  1168. /**
  1169. * Scrolls to the top of the specified AbsListView.
  1170. *
  1171. * @param list the {@link AbsListView} to scroll
  1172. * @return {@code true} if more scrolling can be performed
  1173. */
  1174. public boolean scrollListToTop(AbsListView list) {
  1175. return scroller.scrollList(list, Scroller.UP, true);
  1176. }
  1177. /**
  1178. * Scrolls down a ListView matching the specified index.
  1179. *
  1180. * @param index the index of the {@link ListView} to scroll. {@code 0} if only one list is available
  1181. * @return {@code true} if more scrolling can be performed
  1182. */
  1183. public boolean scrollDownList(int index) {
  1184. return scroller.scrollList(waiter.waitForAndGetView(index, ListView.class), Scroller.DOWN, false);
  1185. }
  1186. /**
  1187. * Scrolls a ListView matching the specified index to the bottom.
  1188. *
  1189. * @param index the index of the {@link ListView} to scroll. {@code 0} if only one list is available
  1190. * @return {@code true} if more scrolling can be performed
  1191. */
  1192. public boolean scrollListToBottom(int index) {
  1193. return scroller.scrollList(waiter.waitForAndGetView(index, ListView.class), Scroller.DOWN, true);
  1194. }
  1195. /**
  1196. * Scrolls up a ListView matching the specified index.
  1197. *
  1198. * @param index the index of the {@link ListView} to scroll. {@code 0} if only one list is available
  1199. * @return {@code true} if more scrolling can be performed
  1200. */
  1201. public boolean scrollUpList(int index) {
  1202. return scroller.scrollList(waiter.waitForAndGetView(index, ListView.class), Scroller.UP, false);
  1203. }
  1204. /**
  1205. * Scrolls a ListView matching the specified index to the top.
  1206. *
  1207. * @param index the index of the {@link ListView} to scroll. {@code 0} if only one list is available
  1208. * @return {@code true} if more scrolling can be performed
  1209. */
  1210. public boolean scrollListToTop(int index) {
  1211. return scroller.scrollList(waiter.waitForAndGetView(index, ListView.class), Scroller.UP, true);
  1212. }
  1213. /**
  1214. * Scroll the specified AbsListView to the specified line.
  1215. *
  1216. * @param absListView the {@link AbsListVi…

Large files files are truncated, but you can click here to view the full file