Commit 37bccb7a authored by Anthony Berent's avatar Anthony Berent Committed by Commit Bot

Flatten UiCapture directory structure

Having multiple directories for screenshots complicates adding
the UI capture tests to the bots, and is no longer needed to
identify the screenshots or to make the file names unique. Put
all the screenshots in a single directory.

Bug: None
Change-Id: Ie25b9a1f9bacd5ada27e57fdbd742b1a9d893fa6
Reviewed-on: https://chromium-review.googlesource.com/902102
Commit-Queue: Anthony Berent <aberent@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534708}
parent 40381082
...@@ -31,7 +31,6 @@ import java.io.IOException; ...@@ -31,7 +31,6 @@ import java.io.IOException;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) // Tab switcher button only exists on phones. @Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) // Tab switcher button only exists on phones.
@ScreenShooter.Directory("Example")
public class ExampleUiCaptureTest { public class ExampleUiCaptureTest {
@Rule @Rule
public ChromeActivityTestRule<ChromeTabbedActivity> mActivityTestRule = public ChromeActivityTestRule<ChromeTabbedActivity> mActivityTestRule =
...@@ -53,7 +52,6 @@ public class ExampleUiCaptureTest { ...@@ -53,7 +52,6 @@ public class ExampleUiCaptureTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("TabSwitcher")
public void testCaptureTabSwitcher() throws IOException, InterruptedException { public void testCaptureTabSwitcher() throws IOException, InterruptedException {
mScreenShooter.shoot("NTP", ScreenShooter.TagsEnum.UiCatalogueExample); mScreenShooter.shoot("NTP", ScreenShooter.TagsEnum.UiCatalogueExample);
Espresso.onView(ViewMatchers.withId(R.id.tab_switcher_button)).perform(ViewActions.click()); Espresso.onView(ViewMatchers.withId(R.id.tab_switcher_button)).perform(ViewActions.click());
......
...@@ -36,7 +36,6 @@ import java.util.concurrent.TimeoutException; ...@@ -36,7 +36,6 @@ import java.util.concurrent.TimeoutException;
// clang-format off // clang-format off
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@ScreenShooter.Directory("InfoBars")
public class InfoBarAppearanceTest { public class InfoBarAppearanceTest {
// clang-format on // clang-format on
......
...@@ -94,7 +94,6 @@ public class NewTabPageUiCaptureTest { ...@@ -94,7 +94,6 @@ public class NewTabPageUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"NewTabPage", "UiCatalogue"}) @Feature({"NewTabPage", "UiCatalogue"})
@ScreenShooter.Directory("New Tab Page")
public void testCaptureNewTabPage() { public void testCaptureNewTabPage() {
assertThat(ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_MODERN_LAYOUT), assertThat(ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_MODERN_LAYOUT),
is(mEnableNTPModernLayout)); is(mEnableNTPModernLayout));
......
...@@ -64,7 +64,6 @@ public class HomeSheetCardsUiCaptureTest { ...@@ -64,7 +64,6 @@ public class HomeSheetCardsUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("HomeSheetCards")
public void testContextMenu() throws Exception { public void testContextMenu() throws Exception {
mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false); mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false);
waitForWindowUpdates(); waitForWindowUpdates();
...@@ -77,7 +76,6 @@ public class HomeSheetCardsUiCaptureTest { ...@@ -77,7 +76,6 @@ public class HomeSheetCardsUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("HomeSheetCards")
public void testScrolling() throws Exception { public void testScrolling() throws Exception {
mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false); mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false);
waitForWindowUpdates(); waitForWindowUpdates();
...@@ -105,7 +103,6 @@ public class HomeSheetCardsUiCaptureTest { ...@@ -105,7 +103,6 @@ public class HomeSheetCardsUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("HomeSheetCards")
public void testContentSuggestionPlaceholder() throws Exception { public void testContentSuggestionPlaceholder() throws Exception {
FakeSuggestionsSource source = (FakeSuggestionsSource) mDepsFactory.suggestionsSource; FakeSuggestionsSource source = (FakeSuggestionsSource) mDepsFactory.suggestionsSource;
source.setSuggestionsForCategory(KnownCategories.ARTICLES, Collections.emptyList()); source.setSuggestionsForCategory(KnownCategories.ARTICLES, Collections.emptyList());
......
...@@ -52,7 +52,6 @@ public class HomeSheetNoTilesUiCaptureTest { ...@@ -52,7 +52,6 @@ public class HomeSheetNoTilesUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("HomeSheetTiles")
public void testNoTiles() { public void testNoTiles() {
mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false); mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false);
waitForWindowUpdates(); waitForWindowUpdates();
......
...@@ -54,7 +54,6 @@ public class HomeSheetTilesUiCaptureTest { ...@@ -54,7 +54,6 @@ public class HomeSheetTilesUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("HomeSheetTiles")
public void testAppearance() { public void testAppearance() {
mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false); mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false);
waitForWindowUpdates(); waitForWindowUpdates();
...@@ -64,7 +63,6 @@ public class HomeSheetTilesUiCaptureTest { ...@@ -64,7 +63,6 @@ public class HomeSheetTilesUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("HomeSheetTiles")
public void testContextMenu() { public void testContextMenu() {
mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false); mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false);
waitForWindowUpdates(); waitForWindowUpdates();
......
...@@ -37,7 +37,6 @@ import org.chromium.ui.test.util.UiRestriction; ...@@ -37,7 +37,6 @@ import org.chromium.ui.test.util.UiRestriction;
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) // ChromeHome is only enabled on phones @Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) // ChromeHome is only enabled on phones
@ScreenShooter.Directory("HomeSheetStates")
public class HomeSheetUiCaptureTest { public class HomeSheetUiCaptureTest {
@Rule @Rule
public SuggestionsBottomSheetTestRule mActivityRule = new SuggestionsBottomSheetTestRule(); public SuggestionsBottomSheetTestRule mActivityRule = new SuggestionsBottomSheetTestRule();
...@@ -61,7 +60,6 @@ public class HomeSheetUiCaptureTest { ...@@ -61,7 +60,6 @@ public class HomeSheetUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("SignInPromo")
public void testSignInPromo() { public void testSignInPromo() {
// Needs to be "Full" to for this to work on small screens in landscape. // Needs to be "Full" to for this to work on small screens in landscape.
mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false); mActivityRule.setSheetState(BottomSheet.SHEET_STATE_FULL, false);
...@@ -74,7 +72,6 @@ public class HomeSheetUiCaptureTest { ...@@ -74,7 +72,6 @@ public class HomeSheetUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("AllDismissed")
public void testAllDismissed() { public void testAllDismissed() {
NewTabPageAdapter adapter = mActivityRule.getAdapter(); NewTabPageAdapter adapter = mActivityRule.getAdapter();
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
...@@ -98,7 +95,6 @@ public class HomeSheetUiCaptureTest { ...@@ -98,7 +95,6 @@ public class HomeSheetUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("NewTab")
public void testNewTab() { public void testNewTab() {
// Select "New tab" from the menu. // Select "New tab" from the menu.
MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrumentation(), MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrumentation(),
......
...@@ -49,7 +49,6 @@ public class SuggestionsBottomSheetUiCaptureTest { ...@@ -49,7 +49,6 @@ public class SuggestionsBottomSheetUiCaptureTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"UiCatalogue"}) @Feature({"UiCatalogue"})
@ScreenShooter.Directory("SuggestionsBottomSheetPosition")
public void testBottomSheetPosition() throws Exception { public void testBottomSheetPosition() throws Exception {
mActivityRule.setSheetState(BottomSheet.SHEET_STATE_HALF, false); mActivityRule.setSheetState(BottomSheet.SHEET_STATE_HALF, false);
waitForWindowUpdates(); waitForWindowUpdates();
......
...@@ -29,10 +29,6 @@ import org.chromium.chrome.browser.ChromeVersionInfo; ...@@ -29,10 +29,6 @@ import org.chromium.chrome.browser.ChromeVersionInfo;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -43,15 +39,16 @@ import java.util.Map; ...@@ -43,15 +39,16 @@ import java.util.Map;
/** /**
* Rule for taking screen shots within tests. Screenshots are saved as * Rule for taking screen shots within tests. Screenshots are saved as
* {@code screenshot_dir/test_class_directory/test_directory/shot_name random.png}. * {@code screenshot_dir/shot_name random.png}.
* The associated JSON file describing the screenshot is saved as * The associated JSON file describing the screenshot is saved as
* {@code screenshot_dir/test_class_directory/test_directory/shot_name random.json}. * {@code screenshot_dir/shot_name random.json}.
* <p> * <p>
* {@code screenshot_dir} comes from the instrumentation test command line, which is set by the * {@code screenshot_dir} comes from the instrumentation test command line, which is set by the
* test runners. {@code test_class_directory} and {@code test_directory} can both the set by the * test runners
* {@link ScreenShooter.Directory} annotation. {@code test_class_directory} defaults to nothing * <p>
* (i.e. no directory created at this level), and {@code test_directory} defaults to the name of * {@code shot_name} is the argument to {@code shoot()}
* the individual test. {@code random} is a random value to make the filenames unique. * </p>
* {@code random} is a random value to make the filenames unique.
* <p> * <p>
* The JSON file contains three categories of data: * The JSON file contains three categories of data:
* <dl> * <dl>
...@@ -70,7 +67,6 @@ import java.util.Map; ...@@ -70,7 +67,6 @@ import java.util.Map;
* &#064;RunWith(ChromeJUnit4ClassRunner.class) * &#064;RunWith(ChromeJUnit4ClassRunner.class)
* &#064;CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) * &#064;CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
* &#064;Restriction(RESTRICTION_TYPE_PHONE) // Tab switcher button only exists on phones. * &#064;Restriction(RESTRICTION_TYPE_PHONE) // Tab switcher button only exists on phones.
* &#064;ScreenShooter.Directory("Example")
* public class ExampleUiCaptureTest { * public class ExampleUiCaptureTest {
* &#064;Rule * &#064;Rule
* public ChromeActivityTestRule<ChromeTabbedActivity> mActivityTestRule = * public ChromeActivityTestRule<ChromeTabbedActivity> mActivityTestRule =
...@@ -88,7 +84,6 @@ import java.util.Map; ...@@ -88,7 +84,6 @@ import java.util.Map;
* &#064;Test * &#064;Test
* &#064;SmallTest * &#064;SmallTest
* &#064;Feature({"UiCatalogue"}) * &#064;Feature({"UiCatalogue"})
* &#064;ScreenShooter.Directory("TabSwitcher")
* public void testCaptureTabSwitcher() throws IOException, InterruptedException { * public void testCaptureTabSwitcher() throws IOException, InterruptedException {
* mScreenShooter.shoot("NTP"); * mScreenShooter.shoot("NTP");
* Espresso.onView(ViewMatchers.withId(R.id.tab_switcher_button)). * Espresso.onView(ViewMatchers.withId(R.id.tab_switcher_button)).
...@@ -120,7 +115,6 @@ public class ScreenShooter extends TestWatcher { ...@@ -120,7 +115,6 @@ public class ScreenShooter extends TestWatcher {
private final UiDevice mDevice; private final UiDevice mDevice;
private final String mBaseDir; private final String mBaseDir;
private File mDir;
private String mTestClassName; private String mTestClassName;
private String mTestMethodName; private String mTestMethodName;
private static final String[] FILTERS = {TEST_CLASS_FILTER, TEST_METHOD_FILTER, private static final String[] FILTERS = {TEST_CLASS_FILTER, TEST_METHOD_FILTER,
...@@ -137,12 +131,6 @@ public class ScreenShooter extends TestWatcher { ...@@ -137,12 +131,6 @@ public class ScreenShooter extends TestWatcher {
UiCatalogueExample, UiCatalogueExample,
} }
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Directory {
String value();
}
public ScreenShooter() { public ScreenShooter() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
mDevice = UiDevice.getInstance(instrumentation); mDevice = UiDevice.getInstance(instrumentation);
...@@ -151,20 +139,9 @@ public class ScreenShooter extends TestWatcher { ...@@ -151,20 +139,9 @@ public class ScreenShooter extends TestWatcher {
@Override @Override
protected void starting(Description d) { protected void starting(Description d) {
mDir = new File(mBaseDir);
mTestClassName = d.getClassName(); mTestClassName = d.getClassName();
mTestMethodName = d.getMethodName(); mTestMethodName = d.getMethodName();
Class<?> testClass = d.getTestClass(); Class<?> testClass = d.getTestClass();
Directory classDirectoryAnnotation = testClass.getAnnotation(Directory.class);
String classDirName =
classDirectoryAnnotation == null ? "" : classDirectoryAnnotation.value();
if (!classDirName.isEmpty()) mDir = new File(mBaseDir, classDirName);
Directory methodDirectoryAnnotation = d.getAnnotation(Directory.class);
String testMethodDir = methodDirectoryAnnotation == null
? d.getMethodName()
: methodDirectoryAnnotation.value();
if (!testMethodDir.isEmpty()) mDir = new File(mDir, testMethodDir);
if (!mDir.exists()) assertTrue("Create screenshot directory", mDir.mkdirs());
mFeatures = d.getAnnotation(Feature.class).value(); mFeatures = d.getAnnotation(Feature.class).value();
} }
...@@ -180,7 +157,7 @@ public class ScreenShooter extends TestWatcher { ...@@ -180,7 +157,7 @@ public class ScreenShooter extends TestWatcher {
* @param tags User selected tags from {@link TagsEnum}. * @param tags User selected tags from {@link TagsEnum}.
*/ */
public void shoot(String shotName, TagsEnum... tags) { public void shoot(String shotName, TagsEnum... tags) {
assertNotNull("ScreenShooter rule initialized", mDir); assertNotNull("ScreenShooter rule initialized", mTestClassName);
Map<String, String> filters = new HashMap<>(); Map<String, String> filters = new HashMap<>();
setFilterValue(filters, TEST_CLASS_FILTER, mTestClassName); setFilterValue(filters, TEST_CLASS_FILTER, mTestClassName);
setFilterValue(filters, TEST_METHOD_FILTER, mTestMethodName); setFilterValue(filters, TEST_METHOD_FILTER, mTestMethodName);
...@@ -223,7 +200,7 @@ public class ScreenShooter extends TestWatcher { ...@@ -223,7 +200,7 @@ public class ScreenShooter extends TestWatcher {
metadata.put("Android build fingerprint", Build.FINGERPRINT); metadata.put("Android build fingerprint", Build.FINGERPRINT);
try { try {
File shotFile = File.createTempFile(shotName, IMAGE_SUFFIX, mDir); File shotFile = File.createTempFile(shotName, IMAGE_SUFFIX, new File(mBaseDir));
assertTrue("Screenshot " + shotName, mDevice.takeScreenshot(shotFile)); assertTrue("Screenshot " + shotName, mDevice.takeScreenshot(shotFile));
writeImageDescription(shotFile, filters, tags, metadata); writeImageDescription(shotFile, filters, tags, metadata);
} catch (IOException e) { } catch (IOException e) {
...@@ -253,7 +230,7 @@ public class ScreenShooter extends TestWatcher { ...@@ -253,7 +230,7 @@ public class ScreenShooter extends TestWatcher {
String jsonFileName = String jsonFileName =
shotFileName.substring(0, shotFileName.length() - IMAGE_SUFFIX.length()) shotFileName.substring(0, shotFileName.length() - IMAGE_SUFFIX.length())
+ JSON_SUFFIX; + JSON_SUFFIX;
try (FileWriter fileWriter = new FileWriter(new File(mDir, jsonFileName));) { try (FileWriter fileWriter = new FileWriter(new File(mBaseDir, jsonFileName));) {
fileWriter.write(imageDescription.toString()); fileWriter.write(imageDescription.toString());
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment