private static AbstractNativeElementContext mockContext() {
        AbstractNativeElementContext context = mock(AbstractNativeElementContext.class);
        when(context.newAndroidElement(any(View.class))).then(new Answer<AndroidElement>() {
            @Override
            public AndroidElement answer(InvocationOnMock invocationOnMock) throws Throwable {
                AndroidNativeElement element = mock(AndroidNativeElement.class);

                when(element.getView()).thenReturn((ViewGroup) invocationOnMock.getArguments()[0]);

                return element;
            }

        });
        return context;
    }
Helper to do the actual searching.
selendroid-server/src/test/java/io/selendroid/server/model/internal/AbstractNativeElementContextTest.java