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)); }
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; }
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; }
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; }
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); }
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); }
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())); } }
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; }
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(); }
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; }
public AndroidUiDriver( ActivityInstrumentationTestCase2<AndroidMenuActivity> testCase ) { monitor( testCase, AndroidMenuActivity.class ); monitor( testCase, AndroidGameActivity.class ); monitor( testCase, AndroidAboutActivity.class ); testCase.launchActivity( APPLICATION_ID, AndroidMenuActivity.class, null ); }
public void monitor( ActivityInstrumentationTestCase2<AndroidMenuActivity> testCase, Class<? extends Activity> activityClass ) { monitors.put( activityClass, testCase.getInstrumentation().addMonitor( activityClass.getName(), null, false ) ); }
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); }
/** * 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()); }
/** * 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]); }
/** * 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]); }
public AutomatorSolo(final Solo solo, Instrumentation mInstrumentation, ActivityInstrumentationTestCase2<?> testCase2) { this.solo = solo; this.mInstrumentation = mInstrumentation; this.testCase2 = testCase2; }
public static Automator getAutomator(Solo solo, Instrumentation instrumentation, ActivityInstrumentationTestCase2<?> testCase2) { // TODO Auto-generated method stub return new AutomatorSolo(solo, instrumentation, testCase2); }
public UniqueIDTest() { super(ActivityInstrumentationTestCase2.class); }
public static void click(View view, ActivityInstrumentationTestCase2 testCase){ int[] viewPosition = new int[2]; view.getLocationOnScreen(viewPosition); click(viewPosition[0], viewPosition[1], testCase); }
public RecorderWindowMenuPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); }
public static RecorderWindowMenuPage launch(ActivityInstrumentationTestCase2 testCase){ return new RecorderWindowMenuPage(testCase); }
public Page(ActivityInstrumentationTestCase2 testCase){ this.testCase = testCase; TestUtils.pauseTest(750); }
protected ActivityInstrumentationTestCase2 getTestCase(){ return testCase; }
public ActEditorPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); }
public ColorSelectorPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); }
public static ColorSelectorPage launch(ActivityInstrumentationTestCase2 testCase){ return new ColorSelectorPage(testCase); }
public StarterWindowPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); // check if this is the right page onLimeLightView(R.id.starter_menu_container).check(matches(isDisplayed())); }
public static StarterWindowPage launch(ActivityInstrumentationTestCase2 testCase) { return new StarterWindowPage(testCase); }
public TextActEditorPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); }
public static TextActEditorPage launch(ActivityInstrumentationTestCase2 testCase){ return new TextActEditorPage(testCase); }
public FontDialogPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); }
public static FontDialogPage launch(ActivityInstrumentationTestCase2 testCase){ return new FontDialogPage(testCase); }
public static RecorderWindowPage launch(ActivityInstrumentationTestCase2 testCase){ return new RecorderWindowPage(testCase); }
public AnimationActEditorPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); }
public static AnimationActEditorPage launch(ActivityInstrumentationTestCase2 testCase){ return new AnimationActEditorPage(testCase); }
public MessageActEditorPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); }
public static MessageActEditorPage launch(ActivityInstrumentationTestCase2 testCase){ return new MessageActEditorPage(testCase); }
public SaveDialogPage(ActivityInstrumentationTestCase2 testCase) { super(testCase); }
public static SaveDialogPage launch(ActivityInstrumentationTestCase2 testCase){ return new SaveDialogPage(testCase); }