本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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()));
}
}
示例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;
}
示例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();
}
示例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;
}
示例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
);
}
示例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 )
);
}
示例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);
}
示例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());
}
示例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]);
}