当前位置: 首页>>代码示例>>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;未经允许,请勿转载。