Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/exclude #303

Merged
merged 52 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9a2a0c5
Preparing prototype
PiteroS678 Jul 31, 2018
60f3205
created threshold, moved logic from image comparision result to layou…
plutasnyy Aug 1, 2018
f013b93
created tests for threshold
plutasnyy Aug 1, 2018
f769083
created status conditionally passed in frontend
plutasnyy Aug 1, 2018
aa31764
created documentation for threshold parameters
plutasnyy Aug 1, 2018
645fb72
Preparing prototype
PiteroS678 Aug 1, 2018
2b53717
merge with treshold
Jul 23, 2018
5e82351
Preparing prototype
PiteroS678 Aug 2, 2018
ddebdaf
updated documentation
plutasnyy Aug 2, 2018
d3bccfe
Update SuiteReportLayoutCase.md
plutasnyy Aug 2, 2018
bff0d18
Refactor
PiteroS678 Aug 2, 2018
7039644
added sum of passed and conditionally passed in side panel
plutasnyy Aug 2, 2018
972a64a
rafactor saveArtifact
plutasnyy Aug 2, 2018
b8d98fe
added integration tests for exclude
plutasnyy Aug 2, 2018
6d087df
updated photo
plutasnyy Aug 2, 2018
49527b4
added documentation about exclude elements
plutasnyy Aug 2, 2018
55b1f12
removed blank line
plutasnyy Aug 2, 2018
0a31c80
updated documentation
plutasnyy Aug 2, 2018
27c45c5
centered button
plutasnyy Aug 2, 2018
4386af1
added integrations tests
plutasnyy Aug 2, 2018
ccc8720
fixed wrong class in dynamic content
plutasnyy Aug 2, 2018
2ae9496
fixed typo in test name
plutasnyy Aug 2, 2018
23e4997
removed unused incrementation
plutasnyy Aug 2, 2018
2c82913
Refactor
PiteroS678 Aug 2, 2018
3930e29
Show difference in test - fix
PiteroS678 Aug 3, 2018
a47a732
ScreenCollector refactor
PiteroS678 Aug 3, 2018
77e96a9
Wiki - move `exclude-elements` parameter to ScreenCollector
PiteroS678 Aug 3, 2018
41ba6cb
ScreenCollector refactor
PiteroS678 Aug 3, 2018
bc02476
Added height to tests
PiteroS678 Aug 3, 2018
a08bacd
href update
PiteroS678 Aug 3, 2018
cce570a
Wiki - `exclude-elements` value update
PiteroS678 Aug 3, 2018
5593ae5
LayoutComparator refactor
PiteroS678 Aug 3, 2018
cf2ab30
LoginModifierTest - ignore removed
PiteroS678 Aug 3, 2018
f60959b
Empty lines removed
PiteroS678 Aug 3, 2018
a260f02
merge with threhold
plutasnyy Aug 3, 2018
ba5008e
removed duplicated tests
plutasnyy Aug 3, 2018
0290864
ScreenCollector - fix
PiteroS678 Aug 3, 2018
2b6afa6
Merge branch 'feature/exclude' of https://github.com/Cognifide/aet in…
plutasnyy Aug 3, 2018
d10788d
updated tests
plutasnyy Aug 3, 2018
b10c8a3
removed blank lines
plutasnyy Aug 3, 2018
282dc0f
StepResult - serialVersionUID update
PiteroS678 Aug 6, 2018
a5b09de
LayoutComparator - update
PiteroS678 Aug 6, 2018
adc9e4e
Payload & ScreenCollector - refactor
PiteroS678 Aug 6, 2018
5385992
ScreenCollector - refactor
PiteroS678 Aug 7, 2018
54fc03d
Exclude feature - refactor
PiteroS678 Aug 7, 2018
6b7db4d
Exclude feature - refactor
PiteroS678 Aug 7, 2018
8427fc9
ScreenCollector - refactor
PiteroS678 Aug 7, 2018
8d42fd3
Wiki - ScreenCollector update
PiteroS678 Aug 7, 2018
c113b3d
merge with master
plutasnyy Aug 14, 2018
09d18c0
Merge branch 'master' into feature/exclude
tkaik Aug 21, 2018
11534ca
Merge branch 'master' of https://github.com/Cognifide/aet into featur…
tkaik Aug 21, 2018
70e120d
CHANGELOG update
PiteroS678 Aug 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 exclude;

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

public LayoutExclude getExclude() {
return exclude;
}
}
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe returning Optional<Payload> here would be a good idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPayload() from StepResult is used only in ComparatorMessageListenerImpl without if statement. If you mean to use it further - LayoutComparator then Optional<Payload> is nice idea.

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.LinkedList;
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 LinkedList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ArrayList here to have better performance. You may estimate it's size with 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,15 @@ 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 +126,13 @@ public void setParameters(Map<String, String> params) throws ParametersException
.isNotBlank(params.get(CSS_PARAM))) {
setElementParams(params);
}
if (params.containsKey(EXCLUDE_ELEMENT_PARAM)) {
if (StringUtils.isNotBlank(params.get(EXCLUDE_ELEMENT_PARAM))) {
excludeCssSelector = params.get(EXCLUDE_ELEMENT_PARAM);
} else {
throw new ParametersException("Elements to exclude are not specified in suite");
}
}
}

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