com.facebook.testing.screenshot.ViewHelpers Java Examples

The following examples show how to use com.facebook.testing.screenshot.ViewHelpers. 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: ApplicationTest.java    From CompactCalendarView with MIT License 6 votes vote down vote up
private void capture(final String name) {
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            compactCalendarView.requestLayout();
            ViewHelpers.setupView(mainContent)
                    .setExactHeightPx(mainContent.getHeight())
                    .setExactWidthPx(mainContent.getWidth())
                    .layout();
            safeSleep(200);
            Screenshot.snap(mainContent)
                    .setName(name)
                    .record();
        }
    });
}
 
Example #2
Source File: LithoViewMatchersTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
@Before
public void before() throws Throwable {
  ComponentsConfiguration.isEndToEndTestRun = true;
  final ComponentContext mComponentContext =
      new ComponentContext(InstrumentationRegistry.getTargetContext());
  final Component mTextComponent = MyComponent.create(mComponentContext).text("foobar").build();
  mView = LithoView.create(InstrumentationRegistry.getTargetContext(), mTextComponent);
  ViewHelpers.setupView(mView).setExactWidthPx(200).setExactHeightPx(100).layout();
}
 
Example #3
Source File: ComponentHostMatchersTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
@Before
public void before() throws Throwable {
  final ComponentContext mComponentContext =
      new ComponentContext(InstrumentationRegistry.getTargetContext());
  final Component mTextComponent =
      MyComponent.create(mComponentContext).text("foobar").customViewTag("zoidberg").build();
  final ComponentTree tree = ComponentTree.create(mComponentContext, mTextComponent).build();
  mView = new LithoView(mComponentContext);
  mView.setComponentTree(tree);
  ViewHelpers.setupView(mView).setExactWidthPx(200).setExactHeightPx(100).layout();
}
 
Example #4
Source File: ScreenshotHelper.java    From Isometric with Apache License 2.0 5 votes vote down vote up
public static void measureAndScreenshotView(View view, int width, int height) {
    ViewHelpers.setupView(view)
            .setExactWidthPx(width)
            .setExactHeightPx(height)
            .layout();
    Screenshot.snap(view)
            .record();
}
 
Example #5
Source File: ScreenshotTest.java    From KataScreenshotAndroid with Apache License 2.0 5 votes vote down vote up
protected void compareScreenshot(View view, int height) {
  Context context = getInstrumentation().getTargetContext();
  WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  DisplayMetrics metrics = new DisplayMetrics();
  windowManager.getDefaultDisplay().getMetrics(metrics);
  ViewHelpers.setupView(view)
      .setExactHeightPx(context.getResources().getDimensionPixelSize(height))
      .setExactWidthPx(metrics.widthPixels)
      .layout();
  Screenshot.snap(view).record();
}
 
Example #6
Source File: ExampleScreenshotTest.java    From screenshot-tests-for-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefault() {
  Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
  LayoutInflater inflater = LayoutInflater.from(targetContext);
  LithoView view = (LithoView) inflater.inflate(R.layout.litho_view, null, false);

  view.setComponent(Example.create(view.getComponentContext()).build());

  ViewHelpers.setupView(view).setExactWidthDp(300).layout();
  Screenshot.snap(view).record();
}
 
Example #7
Source File: ImageRowScreenshotTest.java    From screenshot-tests-for-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefault() {
  Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
  LayoutInflater inflater = LayoutInflater.from(targetContext);
  LithoView view = (LithoView) inflater.inflate(R.layout.litho_view, null, false);

  view.setComponent(ImageRow.create(view.getComponentContext()).build());

  ViewHelpers.setupView(view).setExactWidthDp(300).layout();
  Screenshot.snap(view).record();
}
 
Example #8
Source File: LayoutHierarchyDumperTest.java    From screenshot-tests-for-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicCoordinateCheck() throws Throwable {
  ViewHelpers.setupView(mView).setExactHeightPx(1000).setExactWidthPx(20000).layout();
  ParsedViewDetail node = ParsedViewDetail.convert(mView);
  assertEquals(0, node.absoluteRect.top);
  assertEquals(0, node.absoluteRect.left);
  assertEquals(node.childAt(0).absoluteRect.bottom, node.childAt(1).absoluteRect.top);
  assertTrue(node.childAt(0).absoluteRect.bottom != 0);
}
 
Example #9
Source File: LayoutHierarchyDumperTest.java    From screenshot-tests-for-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testNestedAbsoluteCoordinates() throws Throwable {
  ViewHelpers.setupView(mView).setExactHeightPx(1000).setExactWidthPx(20000).layout();
  ParsedViewDetail node = ParsedViewDetail.convert(mView);

  int textViewHeight = ((ViewGroup) mView).getChildAt(0).getHeight();

  assertEquals(3 * textViewHeight, node.childAt(2).childAt(1).absoluteRect.top);
}
 
Example #10
Source File: LayoutHierarchyDumperTest.java    From screenshot-tests-for-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testDumpHierarchyOnNestedNode() throws Throwable {
  ViewHelpers.setupView(mView).setExactHeightPx(1000).setExactWidthPx(20000).layout();
  ParsedViewDetail node = ParsedViewDetail.convert(((ViewGroup) mView).getChildAt(2));

  assertEquals(0, node.absoluteRect.top);
  assertEquals(0, node.absoluteRect.left);
  int textViewHeight = ((ViewGroup) mView).getChildAt(0).getHeight();

  assertEquals(textViewHeight, node.childAt(1).absoluteRect.top);
}
 
Example #11
Source File: LayoutHierarchyDumperTest.java    From screenshot-tests-for-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testPluginDumps() throws Throwable {
  ViewHelpers.setupView(mView).setExactHeightPx(1000).setExactWidthPx(20000).layout();

  LayoutHierarchyDumper dumper =
      LayoutHierarchyDumper.createWith(
          Collections.<HierarchyPlugin>emptyList(), Collections.singletonList(mAttributePlugin));
  JSONObject root = dumper.dumpHierarchy(mView);

  assertEquals("bar", root.getString("foo:foo"));
}
 
Example #12
Source File: LayoutHierarchyDumperTest.java    From screenshot-tests-for-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testPluginDumpsRecursively() throws Throwable {
  ViewHelpers.setupView(mView).setExactHeightPx(1000).setExactWidthPx(20000).layout();

  LayoutHierarchyDumper dumper =
      LayoutHierarchyDumper.createWith(
          Collections.<HierarchyPlugin>emptyList(),
          Collections.singletonList(mTextAttributePlugin));

  JSONObject node = dumper.dumpHierarchy(mView);

  List<String> allText = new ArrayList<>();
  Queue<JSONObject> toCheck = new ArrayDeque<>();
  toCheck.offer(node);
  while (!toCheck.isEmpty()) {
    JSONObject object = toCheck.poll();
    String maybeText = object.optString("Text:text");
    if (!TextUtils.isEmpty(maybeText)) {
      allText.add(maybeText);
    }
    JSONArray children = object.optJSONArray(BaseViewHierarchyPlugin.KEY_CHILDREN);
    if (children == null) {
      continue;
    }
    for (int i = 0; i < children.length(); ++i) {
      toCheck.offer(children.getJSONObject(i));
    }
  }

  List<String> expected = new ArrayList<>();
  expected.add("foobar");
  expected.add("foobar2");
  expected.add("foobar3");
  expected.add("foobar4");

  assertEquals(expected, allText);
}
 
Example #13
Source File: ApplicationTest.java    From CompactCalendarView with MIT License 5 votes vote down vote up
private void takeScreenShot(final int height) {
    activityRule.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ViewHelpers.setupView(mainContent)
                    .setExactHeightDp(height)
                    .setExactWidthPx(mainContent.getWidth())
                    .layout();
        }
    });

    Screenshot.snap(mainContent)
            .record();
}
 
Example #14
Source File: BaseSnapshotTest.java    From Leanplum-Android-SDK with Apache License 2.0 4 votes vote down vote up
protected void setupView(@NonNull View view) {
  ViewHelpers.setupView(view)
      .setExactWidthDp(SNAPSHOT_WIDTH_DP)
      .setExactHeightDp(SNAPSHOT_HEIGHT_DP)
      .layout();
}