Java Code Examples for androidx.test.core.app.ActivityScenario#onActivity()
The following examples show how to use
androidx.test.core.app.ActivityScenario#onActivity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdvancedSynchronizationTest.java From android-test with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { ActivityScenario<SyncActivity> activityScenario = ActivityScenario.launch(SyncActivity.class); activityScenario.onActivity( activity -> { HelloWorldServer realServer = activity.getHelloWorldServer(); // Here, we use CountingIdlingResource - a common convenience class - to track the idle // state of // the server. You could also do this yourself, by implementing the IdlingResource // interface. countingResource = new CountingIdlingResource("HelloWorldServerCalls"); activity.setHelloWorldServer(new DecoratedHelloWorldServer(realServer, countingResource)); assertTrue(registerIdlingResources(countingResource)); }); }
Example 2
Source File: EventInjectorTest.java From android-test with Apache License 2.0 | 6 votes |
@Test public void injectKeyEventUpWithNoDown() throws Exception { ActivityScenario<SendActivity> scenario = ActivityScenario.launch(SendActivity.class); scenario.onActivity( sendActivity -> { View view = sendActivity.findViewById(R.id.send_data_edit_text); assertTrue(view.requestFocus()); latch.countDown(); }); assertTrue("Timed out!", latch.await(10, TimeUnit.SECONDS)); KeyCharacterMap keyCharacterMap = UiControllerImpl.getKeyCharacterMap(); KeyEvent[] events = keyCharacterMap.getEvents("a".toCharArray()); assertTrue(injector.injectKeyEvent(events[1])); }
Example 3
Source File: EventInjectorTest.java From android-test with Apache License 2.0 | 6 votes |
@Test public void injectStaleKeyEvent() throws Exception { ActivityScenario<SendActivity> scenario = ActivityScenario.launch(SendActivity.class); scenario.onActivity( sendActivity -> { View view = sendActivity.findViewById(R.id.send_data_edit_text); assertTrue(view.requestFocus()); latch.countDown(); }); assertTrue("Timed out!", latch.await(10, TimeUnit.SECONDS)); assertFalse("SecurityException exception was thrown.", injectEventThrewSecurityException.get()); KeyCharacterMap keyCharacterMap = UiControllerImpl.getKeyCharacterMap(); KeyEvent[] events = keyCharacterMap.getEvents("a".toCharArray()); KeyEvent event = KeyEvent.changeTimeRepeat(events[0], 1, 0); // Stale event does not fail for API < 13. if (Build.VERSION.SDK_INT < 13) { assertTrue(injector.injectKeyEvent(event)); } else { assertFalse(injector.injectKeyEvent(event)); } }
Example 4
Source File: MediathekPlayerActivityTest.java From zapp with MIT License | 5 votes |
@Test public void testRecreation() { Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); Intent intent = MediathekPlayerActivity.getStartIntent(context, MediathekData.getTestShow()); ActivityScenario scenario = ActivityScenario.launch(intent); scenario.recreate(); scenario.onActivity(activity -> activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)); scenario.recreate(); }
Example 5
Source File: MediathekDetailActivityTest.java From zapp with MIT License | 5 votes |
@Test public void testRecreation() { Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); Intent intent = MediathekDetailActivity.getStartIntent(context, MediathekData.getTestShow()); ActivityScenario scenario = ActivityScenario.launch(intent); scenario.recreate(); scenario.onActivity(activity -> activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)); scenario.recreate(); }
Example 6
Source File: ChannelDetailActivityTest.java From zapp with MIT License | 5 votes |
@Test public void testRecreation() { Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); Intent intent = ChannelDetailActivity.getStartIntent(context, "das_erste"); ActivityScenario scenario = ActivityScenario.launch(intent); scenario.recreate(); scenario.onActivity(activity -> activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)); scenario.recreate(); }
Example 7
Source File: ChannelSelectionActivityTest.java From zapp with MIT License | 5 votes |
@Test public void testRecreation() { Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); Intent intent = new Intent(context, ChannelSelectionActivity.class); ActivityScenario scenario = ActivityScenario.launch(intent); scenario.recreate(); scenario.onActivity(activity -> activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)); scenario.recreate(); }
Example 8
Source File: BuilderUnitTest.java From MaterialTapTargetPrompt with Apache License 2.0 | 5 votes |
@Test public void testBuilder_Activity_Resource() { ActivityScenario<EmptyTestActivity> scenario = ActivityScenario.launch(EmptyTestActivity.class); scenario.onActivity(activity -> { final MaterialTapTargetPrompt.Builder builder = new MaterialTapTargetPrompt.Builder(activity, 0); assertTrue(builder.getResourceFinder() instanceof ActivityResourceFinder); }); }
Example 9
Source File: BuilderUnitTest.java From MaterialTapTargetPrompt with Apache License 2.0 | 5 votes |
@Test public void testBuilder_Activity() { ActivityScenario<EmptyTestActivity> scenario = ActivityScenario.launch(EmptyTestActivity.class); scenario.onActivity(activity -> { final MaterialTapTargetPrompt.Builder builder = new MaterialTapTargetPrompt.Builder(activity); assertTrue(builder.getResourceFinder() instanceof ActivityResourceFinder); }); }
Example 10
Source File: CoordinatesUtil.java From android-test with Apache License 2.0 | 5 votes |
static int[] getCoordinatesInMiddleOfSendButton(ActivityScenario activityScenario) { final int[] xyMiddle = new int[2]; activityScenario.onActivity( new ActivityAction() { @Override public void perform(Activity activity) { final View sendButton = activity.findViewById(R.id.send_button); final int[] xy = new int[2]; sendButton.getLocationOnScreen(xy); xyMiddle[0] = xy[0] + (sendButton.getWidth() / 2); xyMiddle[1] = xy[1] + (sendButton.getHeight() / 2); } }); return xyMiddle; }
Example 11
Source File: ChangeTextBehaviorTest.java From testing-samples with Apache License 2.0 | 5 votes |
/** * Use {@link ActivityScenario to launch and get access to the activity. * {@link ActivityScenario#onActivity(ActivityScenario.ActivityAction)} provides a thread-safe * mechanism to access the activity. */ @Before public void registerIdlingResource() { ActivityScenario activityScenario = ActivityScenario.launch(MainActivity.class); activityScenario.onActivity(new ActivityScenario.ActivityAction<MainActivity>() { @Override public void perform(MainActivity activity) { mIdlingResource = activity.getIdlingResource(); // To prove that the test fails, omit this call: IdlingRegistry.getInstance().register(mIdlingResource); } }); }