Java Code Examples for androidx.test.InstrumentationRegistry#getInstrumentation()
The following examples show how to use
androidx.test.InstrumentationRegistry#getInstrumentation() .
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: ScreenshotTest.java From firefox-echo-show with Mozilla Public License 2.0 | 5 votes |
@Before public void setUpScreenshots() { Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); targetContext = instrumentation.getTargetContext(); device = UiDevice.getInstance(instrumentation); // Use this to switch between default strategy and HostScreencap strategy Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); //Screengrab.setDefaultScreenshotStrategy(new HostScreencapScreenshotStrategy(device)); device.waitForIdle(); }
Example 2
Source File: InteractionUtil.java From litho with Apache License 2.0 | 5 votes |
public static void click(Point location) { final long time = SystemClock.uptimeMillis(); final MotionEvent actionDownEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, location.x, location.y, 0); final MotionEvent actionUpEvent = MotionEvent.obtain( time + 100, time + 100, MotionEvent.ACTION_UP, location.x, location.y, 0); final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); instrumentation.sendPointerSync(actionDownEvent); instrumentation.sendPointerSync(actionUpEvent); instrumentation.waitForIdleSync(); }
Example 3
Source File: ComponentActivityTestRule.java From litho with Apache License 2.0 | 5 votes |
/** Set the Component for the Activity to display. */ public void setComponent(final Component component) { final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); instrumentation.runOnMainSync( new Runnable() { @Override public void run() { getActivity().setComponent(component); } }); instrumentation.waitForIdleSync(); }
Example 4
Source File: ComponentActivityTestRule.java From litho with Apache License 2.0 | 5 votes |
/** Set ComponentTree for the Activity to display. */ public void setComponentTree(final ComponentTree componentTree) { final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); instrumentation.runOnMainSync( new Runnable() { @Override public void run() { getActivity().setComponentTree(componentTree); } }); instrumentation.waitForIdleSync(); }
Example 5
Source File: ScreenshotTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Before public void setUpScreenshots() { Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); targetContext = instrumentation.getTargetContext(); device = UiDevice.getInstance(instrumentation); // Use this to switch between default strategy and HostScreencap strategy Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy()); //Screengrab.setDefaultScreenshotStrategy(new HostScreencapScreenshotStrategy(device)); device.waitForIdle(); }
Example 6
Source File: AppBarHorizontalScrollingTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testScrollAndClick() throws Throwable { final Activity activity = activityTestRule.getActivity(); final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); final Button button = activity.findViewById(R.id.button); final View.OnClickListener mockClickListener = mock(View.OnClickListener.class); button.setOnClickListener(mockClickListener); // Emulate a click on the button to verify that the registered listener is invoked // prior to performing a horizontal swipe across the app ba final int[] buttonXY = new int[2]; button.getLocationOnScreen(buttonXY); final int buttonWidth = button.getWidth(); final int buttonHeight = button.getHeight(); final float emulatedTapX = buttonXY[0] + buttonWidth / 2.0f; final float emulatedTapY = buttonXY[1] + buttonHeight / 2.0f; emulateButtonClick(instrumentation, emulatedTapX, emulatedTapY); verify(mockClickListener).onClick(button); reset(mockClickListener); final HorizontalScrollView hsv = activity.findViewById(R.id.hsv); final int scrollXBefore = hsv.getScrollX(); // Now scroll / swipe horizontally across our scrollable content in the app bar onView(withId(R.id.app_bar)).perform(swipeLeft()); assertTrue("Horizontal scroll performed", hsv.getScrollX() > scrollXBefore); // And emulate another click on the button to verify that the registered listener is still // invoked immediately after performing the horizontal swipe across the app bar emulateButtonClick(instrumentation, emulatedTapX, emulatedTapY); verify(mockClickListener).onClick(button); }
Example 7
Source File: WebpBitmapFactoryTest.java From fresco with MIT License | 5 votes |
@Override @Before public void setUp() { mInstrumentation = InstrumentationRegistry.getInstrumentation(); mWebpBitmapFactory = new WebpBitmapFactoryImpl(); ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(mInstrumentation.getContext()) .experiment() .setWebpBitmapFactory(mWebpBitmapFactory); ImagePipelineFactory.initialize(configBuilder.build()); }
Example 8
Source File: WebpDecodingTest.java From fresco with MIT License | 5 votes |
@Override @Before public void setUp() { mInstrumentation = InstrumentationRegistry.getInstrumentation(); mWebpBitmapFactory = new WebpBitmapFactoryImpl(); ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(mInstrumentation.getContext()) .experiment() .setWebpBitmapFactory(mWebpBitmapFactory); ImagePipelineFactory.initialize(configBuilder.build()); }
Example 9
Source File: AppInteractor.java From edx-app-android with Apache License 2.0 | 5 votes |
public AppLaunchInteractor launchApp() { final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); final Intent launchIntent = instrumentation.getTargetContext().getPackageManager() .getLaunchIntentForPackage(instrumentation.getTargetContext().getPackageName()) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); instrumentation.startActivitySync(launchIntent); instrumentation.waitForIdleSync(); return new AppLaunchInteractor(); }
Example 10
Source File: ScreenshotImplTest.java From screenshot-tests-for-android with Apache License 2.0 | 4 votes |
private Instrumentation getInstrumentation() { return InstrumentationRegistry.getInstrumentation(); }