Skip to content

Commit

Permalink
Merge pull request #303 from Cognifide/feature/exclude
Browse files Browse the repository at this point in the history
Feature/exclude
  • Loading branch information
tkaik authored Aug 22, 2018
2 parents 3bcac13 + 70e120d commit 29d8ec3
Show file tree
Hide file tree
Showing 20 changed files with 379 additions and 45 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to AET will be documented in this file.
## Unreleased
**List of changes that are finished but not yet released in any final version.**

- [PR-303](https://github.com/Cognifide/aet/pull/303) Added `exclude-elements` parameter to [ScreenCollector](https://github.com/Cognifide/aet/wiki/ScreenCollector)
- [PR-327](https://github.com/Cognifide/aet/pull/327) Default web driver changed from Firefox to Chrome
- [PR-294](https://github.com/Cognifide/aet/pull/294) Added support for full page screenshot in chrome
- [PR-326](https://github.com/Cognifide/aet/pull/326) ([PR-308](https://github.com/Cognifide/aet/pull/308), [PR-310](https://github.com/Cognifide/aet/pull/310), [PR-311](https://github.com/Cognifide/aet/pull/311), [PR-312](https://github.com/Cognifide/aet/pull/312), [PR-313](https://github.com/Cognifide/aet/pull/313), [PR-314](https://github.com/Cognifide/aet/pull/314), [PR-315](https://github.com/Cognifide/aet/pull/315), [PR-316](https://github.com/Cognifide/aet/pull/316), [PR-322](https://github.com/Cognifide/aet/pull/322)) - updated OSGi annotations to 6.0.0 OSGi standard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ public class CollectorStepResult extends StepResult {

private final Status status;

private CollectorStepResult(String artifactId, Status status) {
super(artifactId);
private CollectorStepResult(String artifactId, Payload payload, Status status) {
super(artifactId, payload);
this.status = status;
}

private CollectorStepResult(String artifactId, Status status) {
this(artifactId, null, status);
}

public static CollectorStepResult newPageOpen() {
return new CollectorStepResult(null, Status.PAGE_OPENED);
}

public static CollectorStepResult newCollectedResult(String artifactId, Payload payload) {
return new CollectorStepResult(artifactId, payload, Status.COLLECTED);
}

public static CollectorStepResult newCollectedResult(String artifactId) {
return new CollectorStepResult(artifactId, Status.COLLECTED);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.cognifide.aet.communication.api.metadata;

import com.cognifide.aet.communication.api.metadata.exclude.LayoutExclude;
import java.io.Serializable;

public class Payload implements Serializable {

private static final long serialVersionUID = -4218060468970419297L;

private final LayoutExclude layoutExclude;

public Payload(LayoutExclude layoutExclude) {
this.layoutExclude = layoutExclude;
}

public LayoutExclude getLayoutExclude() {
return layoutExclude;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,25 @@

public abstract class StepResult implements Serializable {

private static final long serialVersionUID = 7758484589529051815L;
private static final long serialVersionUID = 7757386595499766654L;

@Pattern(regexp = "^[0-9a-fA-F]{24}$", message = "Invalid objectID")

private final String artifactId;

private final Payload payload;

private List<String> errors = new ArrayList<>();

private Map<String, String> data = new HashMap<>();

public StepResult(String artifactId) {
public StepResult(String artifactId, Payload payload) {
this.artifactId = artifactId;
this.payload = payload;
}

public StepResult(String artifactId) {
this(artifactId, null);
}

public String getArtifactId() {
Expand All @@ -66,6 +74,10 @@ public List<String> getErrors() {
return errors != null ? ImmutableList.copyOf(errors) : Collections.<String>emptyList();
}

public Payload getPayload() {
return payload;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.cognifide.aet.communication.api.metadata.exclude;

import java.awt.Dimension;
import java.awt.Point;
import java.io.Serializable;

public class ExcludedElement implements Serializable {
private static final long serialVersionUID = 692282363549228800L;

private final Point point;

private final Dimension dimension;

public ExcludedElement(Point point, Dimension dimension) {
this.point = point;
this.dimension = dimension;
}

public Point getPoint() {
return point;
}

public Dimension getDimension() {
return dimension;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.cognifide.aet.communication.api.metadata.exclude;

import java.io.Serializable;
import java.util.List;

public class LayoutExclude implements Serializable {
private static final long serialVersionUID = -6496109702966509444L;

private final List<ExcludedElement> excludedElements;

public LayoutExclude(
List<ExcludedElement> excludedElements) {
this.excludedElements = excludedElements;
}

public List<ExcludedElement> getExcludedElements() {
return excludedElements;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.cognifide.aet.job.api.comparator;

import com.cognifide.aet.communication.api.metadata.Payload;
import com.cognifide.aet.job.api.StepProperties;
import com.google.common.base.MoreObjects;

Expand All @@ -24,16 +25,27 @@ public class ComparatorProperties extends StepProperties {

private final String collectedId;

private final Payload payload;

public ComparatorProperties(String company, String project, String patternId,
String collectedId) {
String collectedId, Payload payload) {
super(company, project, patternId);
this.collectedId = collectedId;
this.payload = payload;
}

public ComparatorProperties(String company, String project, String patternId,
String collectedId) {
this(company, project, patternId, collectedId, null);
}

public String getCollectedId() {
return collectedId;
}

public Payload getPayload() {
return payload;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package com.cognifide.aet.job.common.collectors.screen;

import com.cognifide.aet.communication.api.metadata.CollectorStepResult;
import com.cognifide.aet.communication.api.metadata.Payload;
import com.cognifide.aet.communication.api.metadata.exclude.ExcludedElement;
import com.cognifide.aet.communication.api.metadata.exclude.LayoutExclude;
import com.cognifide.aet.job.api.collector.CollectorJob;
import com.cognifide.aet.job.api.collector.CollectorProperties;
import com.cognifide.aet.job.api.exceptions.ParametersException;
Expand All @@ -28,11 +31,14 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.OutputType;
Expand All @@ -56,12 +62,27 @@ public class ScreenCollector extends WebElementsLocatorParams implements Collect

private final CollectorProperties properties;

private String excludeCssSelector;

ScreenCollector(CollectorProperties properties, WebDriver webDriver, ArtifactsDAO artifactsDAO) {
this.properties = properties;
this.webDriver = webDriver;
this.artifactsDAO = artifactsDAO;
}

private List<ExcludedElement> getExcludeElementsFromWebElements(
List<WebElement> webElements) {
List<ExcludedElement> excludeExcludedElements = new ArrayList<>(webElements.size());
for (WebElement webElement : webElements) {
java.awt.Point point = new java.awt.Point(webElement.getLocation().x,
webElement.getLocation().y);
java.awt.Dimension dimension = new java.awt.Dimension(webElement.getSize().width,
webElement.getSize().height);
excludeExcludedElements.add(new ExcludedElement(point, dimension));
}
return excludeExcludedElements;
}

@Override
public CollectorStepResult collect() throws ProcessingException {
byte[] screenshot = takeScreenshot();
Expand All @@ -72,7 +93,16 @@ public CollectorStepResult collect() throws ProcessingException {
} else {
try (final InputStream screenshotStream = new ByteArrayInputStream(screenshot)) {
String resultId = artifactsDAO.saveArtifact(properties, screenshotStream, CONTENT_TYPE);
stepResult = CollectorStepResult.newCollectedResult(resultId);

if (excludeCssSelector != null) {
List<ExcludedElement> excludeExcludedElements = getExcludeElementsFromWebElements(
webDriver.findElements(By.cssSelector(excludeCssSelector)));
stepResult = CollectorStepResult
.newCollectedResult(resultId,
new Payload((new LayoutExclude(excludeExcludedElements))));
} else {
stepResult = CollectorStepResult.newCollectedResult(resultId);
}
} catch (Exception e) {
throw new ProcessingException(e.getMessage(), e);
}
Expand All @@ -97,6 +127,9 @@ public void setParameters(Map<String, String> params) throws ParametersException
.isNotBlank(params.get(CSS_PARAM))) {
setElementParams(params);
}
if (StringUtils.isNotBlank(params.get(EXCLUDE_ELEMENT_PARAM))) {
excludeCssSelector = params.get(EXCLUDE_ELEMENT_PARAM);
}
}

private byte[] takeScreenshot() throws ProcessingException {
Expand Down
Loading

0 comments on commit 29d8ec3

Please sign in to comment.