/robotium-solo/src/main/java/com/robotium/solo/Solo.java
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
- package com.robotium.solo;
- import java.lang.reflect.Method;
- import java.util.ArrayList;
- import junit.framework.Assert;
- import android.app.Activity;
- import android.app.Instrumentation;
- import android.content.pm.ActivityInfo;
- import android.graphics.PointF;
- import android.os.Environment;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.WindowManager;
- import android.webkit.WebView;
- import android.widget.AbsListView;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.CheckedTextView;
- import android.widget.CompoundButton;
- import android.widget.DatePicker;
- import android.widget.EditText;
- import android.widget.ImageButton;
- import android.widget.ImageView;
- import android.widget.ProgressBar;
- import android.widget.RadioButton;
- import android.widget.ScrollView;
- import android.widget.SlidingDrawer;
- import android.widget.Spinner;
- import android.widget.TextView;
- import android.widget.ListView;
- import android.widget.TimePicker;
- import android.widget.ToggleButton;
- import android.app.Instrumentation.ActivityMonitor;
- /**
- * Main class for development of Robotium tests.
- * Robotium has full support for Views, WebViews, Activities, Dialogs, Menus and Context Menus.
- * <br>
- * Robotium can be used in conjunction with Android test classes like
- * ActivityInstrumentationTestCase2 and SingleLaunchActivityTestCase.
- *
- *
- *
- *
- * @author Renas Reda, renas.reda@robotium.com
- */
- public class Solo {
- protected final Asserter asserter;
- protected final ViewFetcher viewFetcher;
- protected final Checker checker;
- protected final Clicker clicker;
- protected final Presser presser;
- protected final Searcher searcher;
- protected final ActivityUtils activityUtils;
- protected final DialogUtils dialogUtils;
- protected final TextEnterer textEnterer;
- protected final Rotator rotator;
- protected final Scroller scroller;
- protected final Sleeper sleeper;
- protected final Swiper swiper;
- protected final Tapper tapper;
- protected final Waiter waiter;
- protected final Setter setter;
- protected final Getter getter;
- protected final WebUtils webUtils;
- protected final Sender sender;
- protected final ScreenshotTaker screenshotTaker;
- protected final Instrumentation instrumentation;
- protected final Zoomer zoomer;
- protected String webUrl = null;
- private final Config config;
- public final static int LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // 0
- public final static int PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; // 1
- public final static int RIGHT = KeyEvent.KEYCODE_DPAD_RIGHT;
- public final static int LEFT = KeyEvent.KEYCODE_DPAD_LEFT;
- public final static int UP = KeyEvent.KEYCODE_DPAD_UP;
- public final static int DOWN = KeyEvent.KEYCODE_DPAD_DOWN;
- public final static int ENTER = KeyEvent.KEYCODE_ENTER;
- public final static int MENU = KeyEvent.KEYCODE_MENU;
- public final static int DELETE = KeyEvent.KEYCODE_DEL;
- public final static int CLOSED = 0;
- public final static int OPENED = 1;
- /**
- * Constructor that takes the Instrumentation object and the start Activity.
- *
- * @param instrumentation the {@link Instrumentation} instance
- * @param activity the start {@link Activity} or {@code null}
- * if no Activity is specified
- */
- public Solo(Instrumentation instrumentation, Activity activity) {
- this(new Config(), instrumentation, activity);
- }
- /**
- * Constructor that takes the Instrumentation and Config objects.
- *
- * @param instrumentation the {@link Instrumentation} instance
- * @param config the {@link Config} instance
- */
- public Solo(Instrumentation instrumentation, Config config) {
- this(config, instrumentation, null);
- }
-
- /**
- * Constructor that takes the Instrumentation, Config and Activity objects.
- *
- * @param instrumentation the {@link Instrumentation} instance
- * @param config the {@link Config} instance
- * @param activity the start {@link Activity} or {@code null}
- * if no Activity is specified
- */
- public Solo(Instrumentation instrumentation, Config config, Activity activity) {
- this(config, instrumentation, activity);
- }
- /**
- * Private constructor.
- *
- * @param config the {@link Config} instance. If {@code null} one will be created.
- * @param instrumentation the {@link Instrumentation} instance
- * @param activity the start {@link Activity} or {@code null}
- * if no Activity is specified
- */
- private Solo(Config config, Instrumentation instrumentation, Activity activity) {
- this.config = (config == null) ? new Config(): config;
- this.instrumentation = instrumentation;
- this.sleeper = new Sleeper();
- this.sender = new Sender(instrumentation, sleeper);
- this.activityUtils = new ActivityUtils(instrumentation, activity, sleeper);
- this.viewFetcher = new ViewFetcher(activityUtils);
- this.screenshotTaker = new ScreenshotTaker(config, activityUtils, viewFetcher, sleeper);
- this.dialogUtils = new DialogUtils(activityUtils, viewFetcher, sleeper);
- this.webUtils = new WebUtils(config, instrumentation,activityUtils,viewFetcher, sleeper);
- this.scroller = new Scroller(config, instrumentation, activityUtils, viewFetcher, sleeper);
- this.searcher = new Searcher(viewFetcher, webUtils, scroller, sleeper);
- this.waiter = new Waiter(activityUtils, viewFetcher, searcher,scroller, sleeper);
- this.getter = new Getter(instrumentation, activityUtils, waiter);
- this.clicker = new Clicker(activityUtils, viewFetcher,sender, instrumentation, sleeper, waiter, webUtils, dialogUtils);
- this.setter = new Setter(activityUtils, getter, clicker, waiter);
- this.asserter = new Asserter(activityUtils, waiter);
- this.checker = new Checker(viewFetcher, waiter);
- this.zoomer = new Zoomer(instrumentation);
- this.swiper = new Swiper(instrumentation);
- this.tapper = new Tapper(instrumentation);
- this.rotator = new Rotator(instrumentation);
- this.presser = new Presser(viewFetcher, clicker, instrumentation, sleeper, waiter, dialogUtils);
- this.textEnterer = new TextEnterer(instrumentation, clicker, dialogUtils);
- initialize();
- }
- /**
- * Config class used to set the scroll behaviour, default timeouts, screenshot filetype and screenshot save path.
- * <br> <br>
- * Example of usage:
- * <pre>
- * public void setUp() throws Exception {
- * Config config = new Config();
- * config.screenshotFileType = ScreenshotFileType.PNG;
- * config.screenshotSavePath = Environment.getExternalStorageDirectory() + "/Robotium/";
- * config.shouldScroll = false;
- * solo = new Solo(getInstrumentation(), config);
- * getActivity();
- * }
- * </pre>
- *
- * @author Renas Reda, renas.reda@robotium.com
- */
- public static class Config {
- /**
- * The timeout length of the get, is, set, assert, enter and click methods. Default length is 10 000 milliseconds.
- */
- public int timeout_small = 10000;
- /**
- * The timeout length of the waitFor methods. Default length is 20 000 milliseconds.
- */
- public int timeout_large = 20000;
- /**
- * The screenshot save path. Default save path is /sdcard/Robotium-Screenshots/.
- */
- public String screenshotSavePath = Environment.getExternalStorageDirectory() + "/Robotium-Screenshots/";
- /**
- * The screenshot file type, JPEG or PNG. Use ScreenshotFileType.JPEG or ScreenshotFileType.PNG. Default file type is JPEG.
- */
- public ScreenshotFileType screenshotFileType = ScreenshotFileType.JPEG;
- /**
- * Set to true if the get, is, set, enter, type and click methods should scroll. Default value is true.
- */
- public boolean shouldScroll = true;
- /**
- * Set to true if JavaScript should be used to click WebElements. Default value is false.
- */
- public boolean useJavaScriptToClickWebElements = false;
- /**
- * The screenshot file type, JPEG or PNG.
- *
- * @author Renas Reda, renas.reda@robotium.com
- *
- */
- public enum ScreenshotFileType {
- JPEG, PNG
- }
- }
- /**
- * Constructor that takes the instrumentation object.
- *
- * @param instrumentation the {@link Instrumentation} instance
- */
- public Solo(Instrumentation instrumentation) {
- this(new Config(), instrumentation, null);
- }
- /**
- * Returns the ActivityMonitor used by Robotium.
- *
- * @return the ActivityMonitor used by Robotium
- */
- public ActivityMonitor getActivityMonitor(){
- return activityUtils.getActivityMonitor();
- }
- /**
- * Returns the Config used by Robotium.
- *
- * @return the Config used by Robotium
- */
- public Config getConfig(){
- return config;
- }
-
- /**
- * Returns an ArrayList of all the View objects located in the focused
- * Activity or Dialog.
- *
- * @return an {@code ArrayList} of the {@link View} objects located in the focused window
- */
- public ArrayList<View> getViews() {
- try {
- return viewFetcher.getViews(null, false);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- /**
- * Returns an ArrayList of the View objects contained in the parent View.
- *
- * @param parent the parent view from which to return the views
- * @return an {@code ArrayList} of the {@link View} objects contained in the specified {@code View}
- */
- public ArrayList<View> getViews(View parent) {
- try {
- return viewFetcher.getViews(parent, false);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
- /**
- * Returns the absolute top parent View of the specified View.
- *
- * @param view the {@link View} whose top parent is requested
- * @return the top parent {@link View}
- */
- public View getTopParent(View view) {
- View topParent = viewFetcher.getTopParent(view);
- return topParent;
- }
- /**
- * Waits for the specified text to appear. Default timeout is 20 seconds.
- *
- * @param text the text to wait for, specified as a regular expression
- * @return {@code true} if text is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForText(String text) {
- return (waiter.waitForText(text) != null);
- }
- /**
- * Waits for the specified text to appear.
- *
- * @param text the text to wait for, specified as a regular expression
- * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
- * @param timeout the the amount of time in milliseconds to wait
- * @return {@code true} if text is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForText(String text, int minimumNumberOfMatches, long timeout) {
- return (waiter.waitForText(text, minimumNumberOfMatches, timeout) != null);
- }
- /**
- * Waits for the specified text to appear.
- *
- * @param text the text to wait for, specified as a regular expression
- * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
- * @param timeout the the amount of time in milliseconds to wait
- * @param scroll {@code true} if scrolling should be performed
- * @return {@code true} if text is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForText(String text, int minimumNumberOfMatches, long timeout, boolean scroll) {
- return (waiter.waitForText(text, minimumNumberOfMatches, timeout, scroll) != null);
- }
- /**
- * Waits for the specified text to appear.
- *
- * @param text the text to wait for, specified as a regular expression
- * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
- * @param timeout the the amount of time in milliseconds to wait
- * @param scroll {@code true} if scrolling should be performed
- * @param onlyVisible {@code true} if only visible text views should be waited for
- * @return {@code true} if text is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForText(String text, int minimumNumberOfMatches, long timeout, boolean scroll, boolean onlyVisible) {
- return (waiter.waitForText(text, minimumNumberOfMatches, timeout, scroll, onlyVisible, true) != null);
- }
- /**
- * Waits for a View matching the specified resource id. Default timeout is 20 seconds.
- *
- * @param id the R.id of the {@link View} to wait for
- * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForView(int id){
- return waitForView(id, 0, Timeout.getLargeTimeout(), true);
- }
- /**
- * Waits for a View matching the specified resource id.
- *
- * @param id the R.id of the {@link View} to wait for
- * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
- * @param timeout the amount of time in milliseconds to wait
- * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForView(int id, int minimumNumberOfMatches, int timeout){
- return waitForView(id, minimumNumberOfMatches, timeout, true);
- }
- /**
- * Waits for a View matching the specified resource id.
- *
- * @param id the R.id of the {@link View} to wait for
- * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
- * @param timeout the amount of time in milliseconds to wait
- * @param scroll {@code true} if scrolling should be performed
- * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForView(int id, int minimumNumberOfMatches, int timeout, boolean scroll){
- int index = minimumNumberOfMatches-1;
- if(index < 1)
- index = 0;
- return (waiter.waitForView(id, index, timeout, scroll) != null);
- }
- /**
- * Waits for a View matching the specified class. Default timeout is 20 seconds.
- *
- * @param viewClass the {@link View} class to wait for
- * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
- */
- public <T extends View> boolean waitForView(final Class<T> viewClass){
- return waiter.waitForView(viewClass, 0, Timeout.getLargeTimeout(), true);
- }
- /**
- * Waits for the specified View. Default timeout is 20 seconds.
- *
- * @param view the {@link View} object to wait for
- * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
- */
- public <T extends View> boolean waitForView(View view){
- return waiter.waitForView(view);
- }
- /**
- * Waits for the specified View.
- *
- * @param view the {@link View} object to wait for
- * @param timeout the amount of time in milliseconds to wait
- * @param scroll {@code true} if scrolling should be performed
- * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
- */
- public <T extends View> boolean waitForView(View view, int timeout, boolean scroll){
- boolean checkIsShown = false;
- if(!scroll){
- checkIsShown = true;
- }
-
- View viewToWaitFor = waiter.waitForView(view, timeout, scroll, checkIsShown);
-
- if(viewToWaitFor != null)
- return true;
-
- return false;
- }
- /**
- * Waits for a View matching the specified class.
- *
- * @param viewClass the {@link View} class to wait for
- * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
- * @param timeout the amount of time in milliseconds to wait
- * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
- */
- public <T extends View> boolean waitForView(final Class<T> viewClass, final int minimumNumberOfMatches, final int timeout){
- int index = minimumNumberOfMatches-1;
- if(index < 1)
- index = 0;
- return waiter.waitForView(viewClass, index, timeout, true);
- }
- /**
- * Waits for a View matching the specified class.
- *
- * @param viewClass the {@link View} class to wait for
- * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
- * @param timeout the amount of time in milliseconds to wait
- * @param scroll {@code true} if scrolling should be performed
- * @return {@code true} if the {@link View} is displayed and {@code false} if it is not displayed before the timeout
- */
- public <T extends View> boolean waitForView(final Class<T> viewClass, final int minimumNumberOfMatches, final int timeout,final boolean scroll){
- int index = minimumNumberOfMatches-1;
- if(index < 1)
- index = 0;
- return waiter.waitForView(viewClass, index, timeout, scroll);
- }
- /**
- * Waits for a WebElement matching the specified By object. Default timeout is 20 seconds.
- *
- * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
- * @return {@code true} if the {@link WebElement} is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForWebElement(By by){
- return (waiter.waitForWebElement(by, 0, Timeout.getLargeTimeout(), true) != null);
- }
- /**
- * Waits for a WebElement matching the specified By object.
- *
- * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
- * @param timeout the the amount of time in milliseconds to wait
- * @param scroll {@code true} if scrolling should be performed
- * @return {@code true} if the {@link WebElement} is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForWebElement(By by, int timeout, boolean scroll){
- return (waiter.waitForWebElement(by, 0, timeout, scroll) != null);
- }
- /**
- * Waits for a WebElement matching the specified By object.
- *
- * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
- * @param minimumNumberOfMatches the minimum number of matches that are expected to be found. {@code 0} means any number of matches
- * @param timeout the the amount of time in milliseconds to wait
- * @param scroll {@code true} if scrolling should be performed
- * @return {@code true} if the {@link WebElement} is displayed and {@code false} if it is not displayed before the timeout
- */
- public boolean waitForWebElement(By by, int minimumNumberOfMatches, int timeout, boolean scroll){
- return (waiter.waitForWebElement(by, minimumNumberOfMatches, timeout, scroll) != null);
- }
- /**
- * Waits for a condition to be satisfied.
- *
- * @param condition the condition to wait for
- * @param timeout the amount of time in milliseconds to wait
- * @return {@code true} if condition is satisfied and {@code false} if it is not satisfied before the timeout
- */
- public boolean waitForCondition(Condition condition, final int timeout){
- return waiter.waitForCondition(condition, timeout);
- }
- /**
- * Searches for a text in the EditText objects currently displayed and returns true if found. Will automatically scroll when needed.
- *
- * @param text the text to search for
- * @return {@code true} if an {@link EditText} displaying the specified text is found or {@code false} if it is not found
- */
- public boolean searchEditText(String text) {
- return searcher.searchWithTimeoutFor(EditText.class, text, 1, true, false);
- }
- /**
- * Searches for a Button displaying the specified text and returns {@code true} if at least one Button
- * is found. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @return {@code true} if a {@link Button} displaying the specified text is found and {@code false} if it is not found
- */
- public boolean searchButton(String text) {
- return searcher.searchWithTimeoutFor(Button.class, text, 0, true, false);
- }
- /**
- * Searches for a Button displaying the specified text and returns {@code true} if at least one Button
- * is found. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @param onlyVisible {@code true} if only {@link Button} visible on the screen should be searched
- * @return {@code true} if a {@link Button} displaying the specified text is found and {@code false} if it is not found
- */
- public boolean searchButton(String text, boolean onlyVisible) {
- return searcher.searchWithTimeoutFor(Button.class, text, 0, true, onlyVisible);
- }
- /**
- * Searches for a ToggleButton displaying the specified text and returns {@code true} if at least one ToggleButton
- * is found. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @return {@code true} if a {@link ToggleButton} displaying the specified text is found and {@code false} if it is not found
- */
- public boolean searchToggleButton(String text) {
- return searcher.searchWithTimeoutFor(ToggleButton.class, text, 0, true, false);
- }
- /**
- * Searches for a Button displaying the specified text and returns {@code true} if the
- * searched Button is found a specified number of times. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
- * matches are expected to be found
- * @return {@code true} if a {@link Button} displaying the specified text is found a specified number of times and {@code false}
- * if it is not found
- */
- public boolean searchButton(String text, int minimumNumberOfMatches) {
- return searcher.searchWithTimeoutFor(Button.class, text, minimumNumberOfMatches, true, false);
- }
- /**
- * Searches for a Button displaying the specified text and returns {@code true} if the
- * searched Button is found a specified number of times. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
- * matches are expected to be found
- * @param onlyVisible {@code true} if only {@link Button} visible on the screen should be searched
- * @return {@code true} if a {@link Button} displaying the specified text is found a specified number of times and {@code false}
- * if it is not found
- */
- public boolean searchButton(String text, int minimumNumberOfMatches, boolean onlyVisible) {
- return searcher.searchWithTimeoutFor(Button.class, text, minimumNumberOfMatches, true, onlyVisible);
- }
- /**
- * Searches for a ToggleButton displaying the specified text and returns {@code true} if the
- * searched ToggleButton is found a specified number of times. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
- * matches are expected to be found
- * @return {@code true} if a {@link ToggleButton} displaying the specified text is found a specified number of times and {@code false}
- * if it is not found
- */
- public boolean searchToggleButton(String text, int minimumNumberOfMatches) {
- return searcher.searchWithTimeoutFor(ToggleButton.class, text, minimumNumberOfMatches, true, false);
- }
- /**
- * Searches for the specified text and returns {@code true} if at least one item
- * is found displaying the expected text. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @return {@code true} if the search string is found and {@code false} if it is not found
- */
- public boolean searchText(String text) {
- return searcher.searchWithTimeoutFor(TextView.class, text, 0, true, false);
- }
- /**
- * Searches for the specified text and returns {@code true} if at least one item
- * is found displaying the expected text. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @param onlyVisible {@code true} if only texts visible on the screen should be searched
- * @return {@code true} if the search string is found and {@code false} if it is not found
- */
- public boolean searchText(String text, boolean onlyVisible) {
- return searcher.searchWithTimeoutFor(TextView.class, text, 0, true, onlyVisible);
- }
- /**
- * Searches for the specified text and returns {@code true} if the searched text is found a specified
- * number of times. Will automatically scroll when needed.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression
- * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
- * matches are expected to be found
- * @return {@code true} if text is found a specified number of times and {@code false} if the text
- * is not found
- */
- public boolean searchText(String text, int minimumNumberOfMatches) {
- return searcher.searchWithTimeoutFor(TextView.class, text, minimumNumberOfMatches, true, false);
- }
- /**
- * Searches for the specified text and returns {@code true} if the searched text is found a specified
- * number of times.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression.
- * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
- * matches are expected to be found
- * @param scroll {@code true} if scrolling should be performed
- * @return {@code true} if text is found a specified number of times and {@code false} if the text
- * is not found
- */
- public boolean searchText(String text, int minimumNumberOfMatches, boolean scroll) {
- return searcher.searchWithTimeoutFor(TextView.class, text, minimumNumberOfMatches, scroll, false);
- }
- /**
- * Searches for the specified text and returns {@code true} if the searched text is found a specified
- * number of times.
- *
- * @param text the text to search for. The parameter will be interpreted as a regular expression.
- * @param minimumNumberOfMatches the minimum number of matches expected to be found. {@code 0} matches means that one or more
- * matches are expected to be found
- * @param scroll {@code true} if scrolling should be performed
- * @param onlyVisible {@code true} if only texts visible on the screen should be searched
- * @return {@code true} if text is found a specified number of times and {@code false} if the text
- * is not found
- */
- public boolean searchText(String text, int minimumNumberOfMatches, boolean scroll, boolean onlyVisible) {
- return searcher.searchWithTimeoutFor(TextView.class, text, minimumNumberOfMatches, scroll, onlyVisible);
- }
- /**
- * Sets the Orientation (Landscape/Portrait) for the current Activity.
- *
- * @param orientation the orientation to set. <code>Solo.</code>{@link #LANDSCAPE} for landscape or
- * <code>Solo.</code>{@link #PORTRAIT} for portrait.
- */
- public void setActivityOrientation(int orientation)
- {
- activityUtils.setActivityOrientation(orientation);
- }
- /**
- * Returns the current Activity.
- *
- * @return the current Activity
- */
- public Activity getCurrentActivity() {
- return activityUtils.getCurrentActivity(false);
- }
- /**
- * Asserts that the Activity matching the specified name is active.
- *
- * @param message the message to display if the assert fails
- * @param name the name of the {@link Activity} that is expected to be active. Example is: {@code "MyActivity"}
- */
- public void assertCurrentActivity(String message, String name)
- {
- asserter.assertCurrentActivity(message, name);
- }
- /**
- * Asserts that the Activity matching the specified class is active.
- *
- * @param message the message to display if the assert fails
- * @param activityClass the class of the Activity that is expected to be active. Example is: {@code MyActivity.class}
- */
- @SuppressWarnings("unchecked")
- public void assertCurrentActivity(String message, @SuppressWarnings("rawtypes") Class activityClass)
- {
- asserter.assertCurrentActivity(message, activityClass);
- }
- /**
- * Asserts that the Activity matching the specified name is active, with the possibility to
- * verify that the expected Activity is a new instance of the Activity.
- *
- * @param message the message to display if the assert fails
- * @param name the name of the Activity that is expected to be active. Example is: {@code "MyActivity"}
- * @param isNewInstance {@code true} if the expected {@link Activity} is a new instance of the {@link Activity}
- */
- public void assertCurrentActivity(String message, String name, boolean isNewInstance)
- {
- asserter.assertCurrentActivity(message, name, isNewInstance);
- }
- /**
- * Asserts that the Activity matching the specified class is active, with the possibility to
- * verify that the expected Activity is a new instance of the Activity.
- *
- * @param message the message to display if the assert fails
- * @param activityClass the class of the Activity that is expected to be active. Example is: {@code MyActivity.class}
- * @param isNewInstance {@code true} if the expected {@link Activity} is a new instance of the {@link Activity}
- */
- @SuppressWarnings("unchecked")
- public void assertCurrentActivity(String message, @SuppressWarnings("rawtypes") Class activityClass,
- boolean isNewInstance) {
- asserter.assertCurrentActivity(message, activityClass, isNewInstance);
- }
- /**
- * Asserts that the available memory is not considered low by the system.
- */
- public void assertMemoryNotLow()
- {
- asserter.assertMemoryNotLow();
- }
- /**
- * Waits for a Dialog to open. Default timeout is 20 seconds.
- *
- * @return {@code true} if the {@link android.app.Dialog} is opened before the timeout and {@code false} if it is not opened
- */
- public boolean waitForDialogToOpen() {
- return dialogUtils.waitForDialogToOpen(Timeout.getLargeTimeout(), true);
- }
- /**
- * Waits for a Dialog to close. Default timeout is 20 seconds.
- *
- * @return {@code true} if the {@link android.app.Dialog} is closed before the timeout and {@code false} if it is not closed
- */
- public boolean waitForDialogToClose() {
- return dialogUtils.waitForDialogToClose(Timeout.getLargeTimeout());
- }
- /**
- * Waits for a Dialog to open.
- *
- * @param timeout the amount of time in milliseconds to wait
- * @return {@code true} if the {@link android.app.Dialog} is opened before the timeout and {@code false} if it is not opened
- */
- public boolean waitForDialogToOpen(long timeout) {
- return dialogUtils.waitForDialogToOpen(timeout, true);
- }
- /**
- * Waits for a Dialog to close.
- *
- * @param timeout the amount of time in milliseconds to wait
- * @return {@code true} if the {@link android.app.Dialog} is closed before the timeout and {@code false} if it is not closed
- */
- public boolean waitForDialogToClose(long timeout) {
- return dialogUtils.waitForDialogToClose(timeout);
- }
- /**
- * Simulates pressing the hardware back key.
- */
- public void goBack()
- {
- hideSoftKeyboard();
- sender.goBack();
- }
- /**
- * Clicks the specified coordinates.
- *
- * @param x the x coordinate
- * @param y the y coordinate
- */
- public void clickOnScreen(float x, float y) {
- sleeper.sleep();
- clicker.clickOnScreen(x, y, null);
- }
- /**
- * Clicks the specified coordinates rapidly a specified number of times. Requires API level >= 14.
- *
- * @param x the x coordinate
- * @param y the y coordinate
- * @param numberOfClicks the number of clicks to perform
- */
- public void clickOnScreen(float x, float y, int numberOfClicks) {
- if (android.os.Build.VERSION.SDK_INT < 14){
- throw new RuntimeException("clickOnScreen(float x, float y, int numberOfClicks) requires API level >= 14");
- }
- tapper.generateTapGesture(numberOfClicks, new PointF(x, y));
- }
- /**
- * Long clicks the specified coordinates.
- *
- * @param x the x coordinate
- * @param y the y coordinate
- */
- public void clickLongOnScreen(float x, float y) {
- clicker.clickLongOnScreen(x, y, 0, null);
- }
- /**
- * Long clicks the specified coordinates for a specified amount of time.
- *
- * @param x the x coordinate
- * @param y the y coordinate
- * @param time the amount of time to long click
- */
- public void clickLongOnScreen(float x, float y, int time) {
- clicker.clickLongOnScreen(x, y, time, null);
- }
- /**
- * Clicks a Button displaying the specified text. Will automatically scroll when needed.
- *
- * @param text the text displayed by the {@link Button}. The parameter will be interpreted as a regular expression
- */
- public void clickOnButton(String text) {
- clicker.clickOn(Button.class, text);
- }
- /**
- * Clicks an ImageButton matching the specified index.
- *
- * @param index the index of the {@link ImageButton} to click. 0 if only one is available
- */
- public void clickOnImageButton(int index) {
- clicker.clickOn(ImageButton.class, index);
- }
- /**
- * Clicks a ToggleButton displaying the specified text.
- *
- * @param text the text displayed by the {@link ToggleButton}. The parameter will be interpreted as a regular expression
- */
- public void clickOnToggleButton(String text) {
- clicker.clickOn(ToggleButton.class, text);
- }
- /**
- * Clicks a MenuItem displaying the specified text.
- *
- * @param text the text displayed by the MenuItem. The parameter will be interpreted as a regular expression
- */
- public void clickOnMenuItem(String text)
- {
- clicker.clickOnMenuItem(text);
- }
- /**
- * Clicks a MenuItem displaying the specified text.
- *
- * @param text the text displayed by the MenuItem. The parameter will be interpreted as a regular expression
- * @param subMenu {@code true} if the menu item could be located in a sub menu
- */
- public void clickOnMenuItem(String text, boolean subMenu)
- {
- clicker.clickOnMenuItem(text, subMenu);
- }
- /**
- * Clicks the specified WebElement.
- *
- * @param webElement the WebElement to click
- */
- public void clickOnWebElement(WebElement webElement){
- if(webElement == null)
- Assert.fail("WebElement is null and can therefore not be clicked!");
- clicker.clickOnScreen(webElement.getLocationX(), webElement.getLocationY(), null);
- }
- /**
- * Clicks a WebElement matching the specified By object.
- *
- * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
- */
- public void clickOnWebElement(By by){
- clickOnWebElement(by, 0, true);
- }
- /**
- * Clicks a WebElement matching the specified By object.
- *
- * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
- * @param match if multiple objects match, this determines which one to click
- */
- public void clickOnWebElement(By by, int match){
- clickOnWebElement(by, match, true);
- }
- /**
- * Clicks a WebElement matching the specified By object.
- *
- * @param by the By object. Examples are: {@code By.id("id")} and {@code By.name("name")}
- * @param match if multiple objects match, this determines which one to click
- * @param scroll {@code true} if scrolling should be performed
- */
- public void clickOnWebElement(By by, int match, boolean scroll){
- clicker.clickOnWebElement(by, match, scroll, config.useJavaScriptToClickWebElements);
- }
- /**
- * Presses a MenuItem matching the specified index. Index {@code 0} is the first item in the
- * first row, Index {@code 3} is the first item in the second row and
- * index {@code 6} is the first item in the third row.
- *
- * @param index the index of the {@link android.view.MenuItem} to press
- */
- public void pressMenuItem(int index) {
- presser.pressMenuItem(index);
- }
- /**
- * Presses a MenuItem matching the specified index. Supports three rows with a specified amount
- * of items. If itemsPerRow equals 5 then index 0 is the first item in the first row,
- * index 5 is the first item in the second row and index 10 is the first item in the third row.
- *
- * @param index the index of the {@link android.view.MenuItem} to press
- * @param itemsPerRow the amount of menu items there are per row
- */
- public void pressMenuItem(int index, int itemsPerRow) {
- presser.pressMenuItem(index, itemsPerRow);
- }
- /**
- * Presses the soft keyboard next button.
- */
- public void pressSoftKeyboardNextButton(){
- presser.pressSoftKeyboardSearchOrNextButton(false);
- }
-
- /**
- * Presses the soft keyboard search button.
- */
- public void pressSoftKeyboardSearchButton(){
- presser.pressSoftKeyboardSearchOrNextButton(true);
- }
- /**
- * Presses a Spinner (drop-down menu) item.
- *
- * @param spinnerIndex the index of the {@link Spinner} menu to use
- * @param itemIndex the index of the {@link Spinner} item to press relative to the currently selected item.
- * A Negative number moves up on the {@link Spinner}, positive moves down
- */
- public void pressSpinnerItem(int spinnerIndex, int itemIndex)
- {
- presser.pressSpinnerItem(spinnerIndex, itemIndex);
- }
- /**
- * Clicks the specified View.
- *
- * @param view the {@link View} to click
- */
- public void clickOnView(View view) {
- view = waiter.waitForView(view, Timeout.getSmallTimeout());
- clicker.clickOnScreen(view);
- }
- /**
- * Clicks the specified View.
- *
- * @param view the {@link View} to click
- * @param immediately {@code true} if View should be clicked without any wait
- */
- public void clickOnView(View view, boolean immediately){
- if(immediately)
- clicker.clickOnScreen(view);
- else{
- view = waiter.waitForView(view, Timeout.getSmallTimeout());
- clicker.clickOnScreen(view);
- }
- }
- /**
- * Long clicks the specified View.
- *
- * @param view the {@link View} to long click
- */
- public void clickLongOnView(View view) {
- view = waiter.waitForView(view, Timeout.getSmallTimeout());
- clicker.clickOnScreen(view, true, 0);
- }
- /**
- * Long clicks the specified View for a specified amount of time.
- *
- * @param view the {@link View} to long click
- * @param time the amount of time to long click
- */
- public void clickLongOnView(View view, int time) {
- clicker.clickOnScreen(view, true, time);
- }
- /**
- * Clicks a View or WebElement displaying the specified
- * text. Will automatically scroll when needed.
- *
- * @param text the text to click. The parameter will be interpreted as a regular expression
- */
- public void clickOnText(String text) {
- clicker.clickOnText(text, false, 1, true, 0);
- }
- /**
- * Clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.
- *
- * @param text the text to click. The parameter will be interpreted as a regular expression
- * @param match if multiple objects match the text, this determines which one to click
- */
- public void clickOnText(String text, int match) {
- clicker.clickOnText(text, false, match, true, 0);
- }
- /**
- * Clicks a View or WebElement displaying the specified text.
- *
- * @param text the text to click. The parameter will be interpreted as a regular expression
- * @param match if multiple objects match the text, this determines which one to click
- * @param scroll {@code true} if scrolling should be performed
- */
- public void clickOnText(String text, int match, boolean scroll) {
- clicker.clickOnText(text, false, match, scroll, 0);
- }
- /**
- * Long clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.
- *
- * @param text the text to click. The parameter will be interpreted as a regular expression
- */
- public void clickLongOnText(String text)
- {
- clicker.clickOnText(text, true, 1, true, 0);
- }
- /**
- * Long clicks a View or WebElement displaying the specified text. Will automatically scroll when needed.
- *
- * @param text the text to click. The parameter will be interpreted as a regular expression
- * @param match if multiple objects match the text, this determines which one to click
- */
- public void clickLongOnText(String text, int match)
- {
- clicker.clickOnText(text, true, match, true, 0);
- }
- /**
- * Long clicks a View or WebElement displaying the specified text.
- *
- * @param text the text to click. The parameter will be interpreted as a regular expression
- * @param match if multiple objects match the text, this determines which one to click
- * @param scroll {@code true} if scrolling should be performed
- */
- public void clickLongOnText(String text, int match, boolean scroll)
- {
- clicker.clickOnText(text, true, match, scroll, 0);
- }
- /**
- * Long clicks a View or WebElement displaying the specified text.
- *
- * @param text the text to click. The parameter will be interpreted as a regular expression
- * @param match if multiple objects match the text, this determines which one to click
- * @param time the amount of time to long click
- */
- public void clickLongOnText(String text, int match, int time)
- {
- clicker.clickOnText(text, true, match, true, time);
- }
- /**
- * Long clicks a View displaying the specified text and then selects
- * an item from the context menu that appears. Will automatically scroll when needed.
- *
- * @param text the text to click. The parameter will be interpreted as a regular expression
- * @param index the index of the menu item to press. {@code 0} if only one is available
- */
- public void clickLongOnTextAndPress(String text, int index) {
- clicker.clickLongOnTextAndPress(text, index);
- }
- /**
- * Clicks a Button matching the specified index.
- *
- * @param index the index of the {@link Button} to click. {@code 0} if only one is available
- */
- public void clickOnButton(int index) {
- clicker.clickOn(Button.class, index);
- }
- /**
- * Clicks a RadioButton matching the specified index.
- *
- * @param index the index of the {@link RadioButton} to click. {@code 0} if only one is available
- */
- public void clickOnRadioButton(int index) {
- clicker.clickOn(RadioButton.class, index);
- }
- /**
- * Clicks a CheckBox matching the specified index.
- *
- * @param index the index of the {@link CheckBox} to click. {@code 0} if only one is available
- */
- public void clickOnCheckBox(int index) {
- clicker.clickOn(CheckBox.class, index);
- }
- /**
- * Clicks an EditText matching the specified index.
- *
- * @param index the index of the {@link EditText} to click. {@code 0} if only one is available
- */
- public void clickOnEditText(int index) {
- clicker.clickOn(EditText.class, index);
- }
- /**
- * Clicks the specified list line and returns an ArrayList of the TextView objects that
- * the list line is displaying. Will use the first ListView it finds.
- *
- * @param line the line to click
- * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
- */
- public ArrayList<TextView> clickInList(int line) {
- return clicker.clickInList(line);
- }
- /**
- * Clicks the specified list line in the ListView matching the specified index and
- * returns an ArrayList of the TextView objects that the list line is displaying.
- *
- * @param line the line to click
- * @param index the index of the list. {@code 0} if only one is available
- * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
- */
- public ArrayList<TextView> clickInList(int line, int index) {
- return clicker.clickInList(line, index, false, 0);
- }
- /**
- * Long clicks the specified list line and returns an ArrayList of the TextView objects that
- * the list line is displaying. Will use the first ListView it finds.
- *
- * @param line the line to click
- * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
- */
- public ArrayList<TextView> clickLongInList(int line){
- return clicker.clickInList(line, 0, true, 0);
- }
- /**
- * Long clicks the specified list line in the ListView matching the specified index and
- * returns an ArrayList of the TextView objects that the list line is displaying.
- *
- * @param line the line to click
- * @param index the index of the list. {@code 0} if only one is available
- * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
- */
- public ArrayList<TextView> clickLongInList(int line, int index){
- return clicker.clickInList(line, index, true, 0);
- }
- /**
- * Long clicks the specified list line in the ListView matching the specified index and
- * returns an ArrayList of the TextView objects that the list line is displaying.
- *
- * @param line the line to click
- * @param index the index of the list. {@code 0} if only one is available
- * @param time the amount of time to long click
- * @return an {@code ArrayList} of the {@link TextView} objects located in the list line
- */
- public ArrayList<TextView> clickLongInList(int line, int index, int time){
- return clicker.clickInList(line, index, true, time);
- }
- /**
- * Clicks an ActionBarItem matching the specified resource id.
- *
- * @param id the R.id of the ActionBar item to click
- */
- public void clickOnActionBarItem(int id){
- clicker.clickOnActionBarItem(id);
- }
- /**
- * Clicks an ActionBar Home/Up button.
- */
- public void clickOnActionBarHomeButton() {
- clicker.clickOnActionBarHomeButton();
- }
- /**
- * Simulate touching the specified location and dragging it to a new location.
- *
- *
- * @param fromX X coordinate of the initial touch, in screen coordinates
- * @param toX X coordinate of the drag destination, in screen coordinates
- * @param fromY Y coordinate of the initial touch, in screen coordinates
- * @param toY Y coordinate of the drag destination, in screen coordinates
- * @param stepCount how many move steps to include in the drag. Less steps results in a faster drag
- */
- public void drag(float fromX, float toX, float fromY, float toY,
- int stepCount) {
- dialogUtils.hideSoftKeyboard(null, false, true);
- scroller.drag(fromX, toX, fromY, toY, stepCount);
- }
- /**
- * Scrolls down the screen.
- *
- * @return {@code true} if more scrolling can be performed and {@code false} if it is at the end of
- * the screen
- */
- @SuppressWarnings("unchecked")
- public boolean scrollDown() {
- waiter.waitForViews(true, AbsListView.class, ScrollView.class, WebView.class);
- return scroller.scroll(Scroller.DOWN);
- }
- /**
- * Scrolls to the bottom of the screen.
- */
- @SuppressWarnings("unchecked")
- public void scrollToBottom() {
- waiter.waitForViews(true, AbsListView.class, ScrollView.class, WebView.class);
- scroller.scroll(Scroller.DOWN, true);
- }
- /**
- * Scrolls up the screen.
- *
- * @return {@code true} if more scrolling can be performed and {@code false} if it is at the top of
- * the screen
- */
- @SuppressWarnings("unchecked")
- public boolean scrollUp(){
- waiter.waitForViews(true, AbsListView.class, ScrollView.class, WebView.class);
- return scroller.scroll(Scroller.UP);
- }
- /**
- * Scrolls to the top of the screen.
- */
- @SuppressWarnings("unchecked")
- public void scrollToTop() {
- waiter.waitForViews(true, AbsListView.class, ScrollView.class, WebView.class);
- scroller.scroll(Scroller.UP, true);
- }
- /**
- * Scrolls down the specified AbsListView.
- *
- * @param list the {@link AbsListView} to scroll
- * @return {@code true} if more scrolling can be performed
- */
- public boolean scrollDownList(AbsListView list) {
- return scroller.scrollList(list, Scroller.DOWN, false);
- }
- /**
- * Scrolls to the bottom of the specified AbsListView.
- *
- * @param list the {@link AbsListView} to scroll
- * @return {@code true} if more scrolling can be performed
- */
- public boolean scrollListToBottom(AbsListView list) {
- return scroller.scrollList(list, Scroller.DOWN, true);
- }
- /**
- * Scrolls up the specified AbsListView.
- *
- * @param list the {@link AbsListView} to scroll
- * @return {@code true} if more scrolling can be performed
- */
- public boolean scrollUpList(AbsListView list) {
- return scroller.scrollList(list, Scroller.UP, false);
- }
- /**
- * Scrolls to the top of the specified AbsListView.
- *
- * @param list the {@link AbsListView} to scroll
- * @return {@code true} if more scrolling can be performed
- */
- public boolean scrollListToTop(AbsListView list) {
- return scroller.scrollList(list, Scroller.UP, true);
- }
- /**
- * Scrolls down a ListView matching the specified index.
- *
- * @param index the index of the {@link ListView} to scroll. {@code 0} if only one list is available
- * @return {@code true} if more scrolling can be performed
- */
- public boolean scrollDownList(int index) {
- return scroller.scrollList(waiter.waitForAndGetView(index, ListView.class), Scroller.DOWN, false);
- }
- /**
- * Scrolls a ListView matching the specified index to the bottom.
- *
- * @param index the index of the {@link ListView} to scroll. {@code 0} if only one list is available
- * @return {@code true} if more scrolling can be performed
- */
- public boolean scrollListToBottom(int index) {
- return scroller.scrollList(waiter.waitForAndGetView(index, ListView.class), Scroller.DOWN, true);
- }
- /**
- * Scrolls up a ListView matching the specified index.
- *
- * @param index the index of the {@link ListView} to scroll. {@code 0} if only one list is available
- * @return {@code true} if more scrolling can be performed
- */
- public boolean scrollUpList(int index) {
- return scroller.scrollList(waiter.waitForAndGetView(index, ListView.class), Scroller.UP, false);
- }
- /**
- * Scrolls a ListView matching the specified index to the top.
- *
- * @param index the index of the {@link ListView} to scroll. {@code 0} if only one list is available
- * @return {@code true} if more scrolling can be performed
- */
- public boolean scrollListToTop(int index) {
- return scroller.scrollList(waiter.waitForAndGetView(index, ListView.class), Scroller.UP, true);
- }
- /**
- * Scroll the specified AbsListView to the specified line.
- *
- * @param absListView the {@link AbsListVi…
Large files files are truncated, but you can click here to view the full file