Java 类android.test.ActivityInstrumentationTestCase2 实例源码

项目:LimeLight    文件:TestUtils.java   
public static void click(int x, int y, ActivityInstrumentationTestCase2 testCase){
    Instrumentation instrumentation = testCase.getInstrumentation();
    Point size = new Point();
    testCase.getActivity().getWindowManager().getDefaultDisplay().getSize(size);
    int width = size.x;
    int height = size.y;

    long downTime = SystemClock.uptimeMillis();

    if (x < 0 || y < 0 || x > width || y > height){
        String error = String.format("The start coordinates (%1$d, %2$d) are not on the screen! | Max width: %3$d, Max height: %4$d", x, y, size.x, size.y);
        Assert.fail(error);
    }

    instrumentation.sendPointerSync(MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
            MotionEvent.ACTION_DOWN, x, y, 0));
    instrumentation.sendPointerSync(MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
            MotionEvent.ACTION_UP, x, y, 0));
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity launchCreateExperimentActivity(
        ActivityInstrumentationTestCase2<?> testCase, Activity activity) {

    // click the Create-New-Experiment button
    ActivityMonitor activityMonitor = testCase.getInstrumentation().addMonitor(
            CreateExperimentActivity.class.getName(), null, false);

    Button buttonCreateExperiment = (Button) activity
            .findViewById(R.id.button_create_experiment);
    Assert.assertNotNull("The Create-Experiment Button should not be null",
            buttonCreateExperiment);

    TouchUtils.clickView(testCase, buttonCreateExperiment);

    testCase.getInstrumentation().waitForIdleSync();

    activity = testCase.getInstrumentation().waitForMonitor(activityMonitor);

    testCase.getInstrumentation().removeMonitor(activityMonitor);
    return activity;
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity viewMostRecentExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {
    // view the most recent experiment
    Fragment fragment = ((SensorDataCollectorActivity) activity).getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The Sensor List Fragment should not be null.", fragment);

    ListView listView = ((ListFragment) fragment).getListView();
    Assert.assertNotNull("ListView should not be null.", listView);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(
            ViewExperimentActivity.class.getName(), null, false);
    TouchUtils.clickView(testCase, listView.getChildAt(listView.getHeaderViewsCount()));
    testCase.getInstrumentation().waitForIdleSync();

    ViewExperimentActivity viewExperimentActivity = (ViewExperimentActivity) testCase
            .getInstrumentation().waitForMonitor(monitor);
    Assert.assertTrue("activity should be a ViewExperimentActivity.",
            viewExperimentActivity instanceof ViewExperimentActivity);
    testCase.getInstrumentation().removeMonitor(monitor);

    // clone the experiment
    testCase.getInstrumentation().waitForIdleSync();
    return viewExperimentActivity;
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity cloneExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {
    Assert.assertTrue("The acitivty must be a ViewExperimentActivity.",
            activity instanceof ViewExperimentActivity);

    Button buttonCloneExperiment = (Button) activity
            .findViewById(R.id.button_experiment_view_clone);
    Assert.assertNotNull("Button should not be null.", buttonCloneExperiment);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(
            CreateExperimentActivity.class.getName(), null, false);
    TouchUtils.clickView(testCase, buttonCloneExperiment);
    activity = testCase.getInstrumentation().waitForMonitorWithTimeout(monitor, 5000);
    Assert.assertTrue("activity should be CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);
    testCase.getInstrumentation().removeMonitor(monitor);

    return activity;
}
项目:LimeLight    文件:TestUtils.java   
public static void drag(View view, Point end, int dragTime, ActivityInstrumentationTestCase2 testCase){
    int[] viewPosition = new int[2];
    view.getLocationOnScreen(viewPosition);

    Point size = new Point();
    testCase.getActivity().getWindowManager().getDefaultDisplay().getSize(size);

    drag(new Point(viewPosition[0], viewPosition[1]), end, dragTime, testCase);
}
项目:LimeLight    文件:TestUtils.java   
public static void clickRandomSpotInView(View view, ActivityInstrumentationTestCase2 testCase){
    int[] viewPosition = new int[2];
    view.getLocationOnScreen(viewPosition);
    click(viewPosition[0], viewPosition[1], testCase);
    Rect rect = new Rect();
    view.getHitRect(rect);

    click(viewPosition[0] + random.nextInt(rect.width()), viewPosition[1] + random.nextInt(rect.height()), testCase);
}
项目:LimeLight    文件:RecorderWindowPage.java   
public RecorderWindowPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
    try {
        onLimeLightView(withText(R.string.empty_book_warning)) // Toast after saving an empty book
            .check(matches(isDisplayed()));
        TestUtils.pauseTest(TOAST_LONG_MILLISECONDS + 500);
    } catch (Throwable thr) {}
    finally {
        // check if this is the right page
        onLimeLightView(R.id.recorder_content_view).check(matches(isDisplayed()));
    }
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity launchSensorDataCollectorActivity(
        ActivityInstrumentationTestCase2<?> testCase) {
    Activity activity;

    testCase.setActivityInitialTouchMode(true);
    activity = testCase.getActivity();
    testCase.getInstrumentation().waitForIdleSync();

    Assert.assertTrue("The activity must be a SensorDataCollectorActivity.",
            activity instanceof SensorDataCollectorActivity);
    return activity;
}
项目:SensorDataCollector    文件:TestHelper.java   
public static void startExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {
    Assert.assertTrue("The activity must be a CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);

    Button buttonRunExperiment = (Button) activity.findViewById(R.id.button_experiment_run);
    Assert.assertNotNull("The Run-Experiment button should not be null.", buttonRunExperiment);

    TouchUtils.clickView(testCase, buttonRunExperiment);
    testCase.getInstrumentation().waitForIdleSync();
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity stopExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {
    Assert.assertTrue("The activity must be a CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);

    Fragment fragment = ((CreateExperimentActivity) activity).getSupportFragmentManager()
            .findFragmentById(
                    R.id.fragment_container);
    Assert.assertNotNull("The ExperimentRunFragment should not be null.", fragment);
    Assert.assertTrue("The fragment should be an ExperimentRunFragment.",
            fragment instanceof ExperimentRunFragment);

    Button buttonExperimentDone = (Button) fragment.getView().findViewById(
            R.id.button_experiment_done);
    Assert.assertNotNull("The Experiment-Done button shoud not be null.", buttonExperimentDone);

    TouchUtils.clickView(testCase, buttonExperimentDone);
    testCase.getInstrumentation().waitForIdleSync();

    AlertDialog dialog = ((CreateExperimentActivity) activity).getAlertDialog();
    Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(
            SensorDataCollectorActivity.class.getName(), null, false);

    TouchUtils.clickView(testCase, positiveButton);
    testCase.getInstrumentation().waitForIdleSync();

    SensorDataCollectorActivity sensorDataCollectorActivity =
            (SensorDataCollectorActivity) testCase.getInstrumentation().waitForMonitor(monitor);
    testCase.getInstrumentation().removeMonitor(monitor);
    Assert.assertNotNull("SensorDataCollector Activity was not loaded",
            sensorDataCollectorActivity);

    return sensorDataCollectorActivity;
}
项目:rabbit-escape    文件:AndroidUiDriver.java   
public AndroidUiDriver( ActivityInstrumentationTestCase2<AndroidMenuActivity> testCase )
{
    monitor( testCase, AndroidMenuActivity.class );
    monitor( testCase, AndroidGameActivity.class );
    monitor( testCase, AndroidAboutActivity.class );

    testCase.launchActivity(
        APPLICATION_ID, AndroidMenuActivity.class, null
    );
}
项目:rabbit-escape    文件:AndroidUiDriver.java   
public void monitor(
    ActivityInstrumentationTestCase2<AndroidMenuActivity> testCase,
    Class<? extends Activity> activityClass
)
{
    monitors.put(
        activityClass,
        testCase.getInstrumentation().addMonitor( activityClass.getName(), null, false )
    );
}
项目:what-stored-in-a-mobile-device-android    文件:MockUserActions.java   
public void swipeToRight(ActivityInstrumentationTestCase2 aitc2){
    DisplayMetrics dm = new DisplayMetrics();
    testActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;

    TouchUtils.drag(aitc2, width - 30, 30, height / 2, height / 2, 5);
}
项目:chromium_webview    文件:DOMUtils.java   
/**
 * Focus a DOM node by its id.
 */
public static void focusNode(ActivityInstrumentationTestCase2 activityTestCase,
        final ContentView view, TestCallbackHelperContainer viewClient, String nodeId)
        throws InterruptedException, TimeoutException {
    StringBuilder sb = new StringBuilder();
    sb.append("(function() {");
    sb.append("  var node = document.getElementById('" + nodeId + "');");
    sb.append("  if (node) node.focus();");
    sb.append("})();");

    JavaScriptUtils.executeJavaScriptAndWaitForResult(view, viewClient, sb.toString());
}
项目:chromium_webview    文件:DOMUtils.java   
/**
 * Click a DOM node by its id.
 */
public static void clickNode(ActivityInstrumentationTestCase2 activityTestCase,
        final ContentView view, TestCallbackHelperContainer viewClient, String nodeId)
        throws InterruptedException, TimeoutException {
    int[] clickTarget = getClickTargetForNode(view, viewClient, nodeId);
    TouchCommon touchCommon = new TouchCommon(activityTestCase);
    touchCommon.singleClickView(view, clickTarget[0], clickTarget[1]);
}
项目:chromium_webview    文件:DOMUtils.java   
/**
 * Long-press a DOM node by its id.
 */
public static void longPressNode(ActivityInstrumentationTestCase2 activityTestCase,
        final ContentView view, TestCallbackHelperContainer viewClient, String nodeId)
        throws InterruptedException, TimeoutException {
    int[] clickTarget = getClickTargetForNode(view, viewClient, nodeId);
    TouchCommon touchCommon = new TouchCommon(activityTestCase);
    touchCommon.longPressView(view, clickTarget[0], clickTarget[1]);
}
项目:Brazilian-Commons    文件:AutomatorSolo.java   
public AutomatorSolo(final Solo solo, Instrumentation mInstrumentation, ActivityInstrumentationTestCase2<?> testCase2) {
    this.solo = solo;
    this.mInstrumentation = mInstrumentation;
    this.testCase2 = testCase2;
}
项目:Brazilian-Commons    文件:AutomatorFactory.java   
public static Automator getAutomator(Solo solo, Instrumentation instrumentation, ActivityInstrumentationTestCase2<?> testCase2) {
    // TODO Auto-generated method stub
    return new AutomatorSolo(solo, instrumentation, testCase2);
}
项目:cuddly-quack    文件:UniqueIDTest.java   
public UniqueIDTest() {
    super(ActivityInstrumentationTestCase2.class);
}
项目:LimeLight    文件:TestUtils.java   
public static void click(View view, ActivityInstrumentationTestCase2 testCase){
    int[] viewPosition = new int[2];
    view.getLocationOnScreen(viewPosition);
    click(viewPosition[0], viewPosition[1], testCase);
}
项目:LimeLight    文件:RecorderWindowMenuPage.java   
public RecorderWindowMenuPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
}
项目:LimeLight    文件:RecorderWindowMenuPage.java   
public static RecorderWindowMenuPage launch(ActivityInstrumentationTestCase2 testCase){
    return new RecorderWindowMenuPage(testCase);
}
项目:LimeLight    文件:Page.java   
public Page(ActivityInstrumentationTestCase2 testCase){
    this.testCase = testCase;
    TestUtils.pauseTest(750);
}
项目:LimeLight    文件:Page.java   
protected ActivityInstrumentationTestCase2 getTestCase(){
    return testCase;
}
项目:LimeLight    文件:ActEditorPage.java   
public ActEditorPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
}
项目:LimeLight    文件:ColorSelectorPage.java   
public ColorSelectorPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
}
项目:LimeLight    文件:ColorSelectorPage.java   
public static ColorSelectorPage launch(ActivityInstrumentationTestCase2 testCase){
    return new ColorSelectorPage(testCase);
}
项目:LimeLight    文件:StarterWindowPage.java   
public StarterWindowPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
    // check if this is the right page
    onLimeLightView(R.id.starter_menu_container).check(matches(isDisplayed()));
}
项目:LimeLight    文件:StarterWindowPage.java   
public static StarterWindowPage launch(ActivityInstrumentationTestCase2 testCase) {
    return new StarterWindowPage(testCase);
}
项目:LimeLight    文件:TextActEditorPage.java   
public TextActEditorPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
}
项目:LimeLight    文件:TextActEditorPage.java   
public static TextActEditorPage launch(ActivityInstrumentationTestCase2 testCase){
    return new TextActEditorPage(testCase);
}
项目:LimeLight    文件:FontDialogPage.java   
public FontDialogPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
}
项目:LimeLight    文件:FontDialogPage.java   
public static FontDialogPage launch(ActivityInstrumentationTestCase2 testCase){
    return new FontDialogPage(testCase);
}
项目:LimeLight    文件:RecorderWindowPage.java   
public static RecorderWindowPage launch(ActivityInstrumentationTestCase2 testCase){
    return new RecorderWindowPage(testCase);
}
项目:LimeLight    文件:AnimationActEditorPage.java   
public AnimationActEditorPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
}
项目:LimeLight    文件:AnimationActEditorPage.java   
public static AnimationActEditorPage launch(ActivityInstrumentationTestCase2 testCase){
    return new AnimationActEditorPage(testCase);
}
项目:LimeLight    文件:MessageActEditorPage.java   
public MessageActEditorPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
}
项目:LimeLight    文件:MessageActEditorPage.java   
public static MessageActEditorPage launch(ActivityInstrumentationTestCase2 testCase){
    return new MessageActEditorPage(testCase);
}
项目:LimeLight    文件:SaveDialogPage.java   
public SaveDialogPage(ActivityInstrumentationTestCase2 testCase) {
    super(testCase);
}
项目:LimeLight    文件:SaveDialogPage.java   
public static SaveDialogPage launch(ActivityInstrumentationTestCase2 testCase){
    return new SaveDialogPage(testCase);
}