當前位置: 首頁>>代碼示例>>Java>>正文


Java ActivityInstrumentationTestCase2類代碼示例

本文整理匯總了Java中android.test.ActivityInstrumentationTestCase2的典型用法代碼示例。如果您正苦於以下問題:Java ActivityInstrumentationTestCase2類的具體用法?Java ActivityInstrumentationTestCase2怎麽用?Java ActivityInstrumentationTestCase2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ActivityInstrumentationTestCase2類屬於android.test包,在下文中一共展示了ActivityInstrumentationTestCase2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: click

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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));
}
 
開發者ID:fuzz-productions,項目名稱:LimeLight,代碼行數:20,代碼來源:TestUtils.java

示例2: launchCreateExperimentActivity

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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;
}
 
開發者ID:sysnetlab,項目名稱:SensorDataCollector,代碼行數:22,代碼來源:TestHelper.java

示例3: viewMostRecentExperiment

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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;
}
 
開發者ID:sysnetlab,項目名稱:SensorDataCollector,代碼行數:26,代碼來源:TestHelper.java

示例4: cloneExperiment

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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;
}
 
開發者ID:sysnetlab,項目名稱:SensorDataCollector,代碼行數:20,代碼來源:TestHelper.java

示例5: drag

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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);
}
 
開發者ID:fuzz-productions,項目名稱:LimeLight,代碼行數:10,代碼來源:TestUtils.java

示例6: clickRandomSpotInView

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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);
}
 
開發者ID:fuzz-productions,項目名稱:LimeLight,代碼行數:10,代碼來源:TestUtils.java

示例7: RecorderWindowPage

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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()));
    }
}
 
開發者ID:fuzz-productions,項目名稱:LimeLight,代碼行數:13,代碼來源:RecorderWindowPage.java

示例8: launchSensorDataCollectorActivity

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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;
}
 
開發者ID:sysnetlab,項目名稱:SensorDataCollector,代碼行數:13,代碼來源:TestHelper.java

示例9: startExperiment

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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();
}
 
開發者ID:sysnetlab,項目名稱:SensorDataCollector,代碼行數:12,代碼來源:TestHelper.java

示例10: stopExperiment

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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;
}
 
開發者ID:sysnetlab,項目名稱:SensorDataCollector,代碼行數:37,代碼來源:TestHelper.java

示例11: AndroidUiDriver

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
public AndroidUiDriver( ActivityInstrumentationTestCase2<AndroidMenuActivity> testCase )
{
    monitor( testCase, AndroidMenuActivity.class );
    monitor( testCase, AndroidGameActivity.class );
    monitor( testCase, AndroidAboutActivity.class );

    testCase.launchActivity(
        APPLICATION_ID, AndroidMenuActivity.class, null
    );
}
 
開發者ID:andybalaam,項目名稱:rabbit-escape,代碼行數:11,代碼來源:AndroidUiDriver.java

示例12: monitor

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
public void monitor(
    ActivityInstrumentationTestCase2<AndroidMenuActivity> testCase,
    Class<? extends Activity> activityClass
)
{
    monitors.put(
        activityClass,
        testCase.getInstrumentation().addMonitor( activityClass.getName(), null, false )
    );
}
 
開發者ID:andybalaam,項目名稱:rabbit-escape,代碼行數:11,代碼來源:AndroidUiDriver.java

示例13: swipeToRight

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
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);
}
 
開發者ID:TeamWhat,項目名稱:what-stored-in-a-mobile-device-android,代碼行數:9,代碼來源:MockUserActions.java

示例14: focusNode

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
/**
 * 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());
}
 
開發者ID:mogoweb,項目名稱:chromium_webview,代碼行數:15,代碼來源:DOMUtils.java

示例15: clickNode

import android.test.ActivityInstrumentationTestCase2; //導入依賴的package包/類
/**
 * 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]);
}
 
開發者ID:mogoweb,項目名稱:chromium_webview,代碼行數:11,代碼來源:DOMUtils.java


注:本文中的android.test.ActivityInstrumentationTestCase2類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。