ScreenCollector extends WebElementsLocatorParams implements CollectorJob { @Override public CollectorStepResult collect() throws ProcessingException { byte[] screenshot = takeScreenshot(); CollectorStepResult stepResult; if (isPatternAndResultMD5Identical(screenshot)) { stepResult = CollectorStepResult.newResultThatDuplicatesPattern(properties.getPatternId()); } else { try (final InputStream screenshotStream = new ByteArrayInputStream(screenshot)) { String resultId = artifactsDAO.saveArtifact(properties, screenshotStream, CONTENT_TYPE); if (excludeCssSelector != null) { stepResult = getResultWithExcludeSelectors(resultId); } else { stepResult = CollectorStepResult.newCollectedResult(resultId); } } catch (Exception e) { throw new ProcessingException(e.getMessage(), e); } } return stepResult; } ScreenCollector(CollectorProperties properties, WebDriver webDriver, ArtifactsDAO artifactsDAO); @Override CollectorStepResult collect(); @Override void setParameters(Map<String, String> params); static final String NAME; }
@Test public void collectScreenExcludeElements_findAll() throws Exception { when(webDriver.findElements(By.cssSelector(SELECTOR_1))) .thenReturn(Collections.singletonList(webElement1)); when(webDriver.findElements(By.cssSelector(SELECTOR_2))) .thenReturn(Collections.singletonList(webElement2)); LayoutExclude exclude = screenCollector.collect().getPayload().getLayoutExclude(); assertThat(exclude.getExcludedElements()).hasSize(2); assertThat(exclude.getNotFoundElements()).isNullOrEmpty(); }
@Test public void collectScreenExcludeElements_findNone() throws Exception { when(webDriver.findElements(By.cssSelector(SELECTOR_1))) .thenReturn(Collections.emptyList()); when(webDriver.findElements(By.cssSelector(SELECTOR_2))) .thenReturn(Collections.emptyList()); LayoutExclude exclude = screenCollector.collect().getPayload().getLayoutExclude(); assertThat(exclude.getExcludedElements()).isEmpty(); assertThat(exclude.getNotFoundElements()).hasSize(2); }
@Test public void collectScreenExcludeElements_findSome() throws Exception { when(webDriver.findElements(By.cssSelector(SELECTOR_1))) .thenReturn(Collections.singletonList(webElement1)); when(webDriver.findElements(By.cssSelector(SELECTOR_2))) .thenReturn(Collections.emptyList()); LayoutExclude exclude = screenCollector.collect().getPayload().getLayoutExclude(); assertThat(exclude.getExcludedElements()).hasSize(1); assertThat(exclude.getNotFoundElements()).hasSize(1); }