From 23c4767ab613b4ea69ce63c966f3b2ca7386491b Mon Sep 17 00:00:00 2001 From: Tomasz Kaik Date: Wed, 3 Jul 2019 21:14:20 +0200 Subject: [PATCH 01/13] Minimum resolution height set to 1 px to prevent error --- .../common/modifiers/resolution/ResolutionModifier.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifier.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifier.java index 9b64c72b9..7d1570ed6 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifier.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifier.java @@ -23,10 +23,9 @@ import com.cognifide.aet.job.common.utils.javascript.JavaScriptJobExecutor; import com.cognifide.aet.job.common.utils.Sampler; import java.util.Map; -import java.util.function.Supplier; +import java.util.function.IntSupplier; import org.apache.commons.lang3.math.NumberUtils; import org.openqa.selenium.Dimension; -import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver.Window; import org.slf4j.Logger; @@ -44,6 +43,7 @@ public class ResolutionModifier implements CollectorJob { private static final int HEIGHT_MAX_SIZE = 35000; private static final int INITIAL_HEIGHT = 300; + private static final int MINIMUM_HEIGHT = 1; private static final int HEIGHT_NOT_DEFINED = 0; private static final int HEIGHT_NOT_CALCULATED = -1; private static final int DEFAULT_SAMPLING_WAIT_PERIOD = 100; @@ -108,6 +108,8 @@ private void setResolution() throws ProcessingException { height = HEIGHT_MAX_SIZE; } else if (height == HEIGHT_NOT_CALCULATED) { throw new ProcessingException("Failed to calculate height, could not parse javascript result to integer"); + } else if (height < MINIMUM_HEIGHT) { + height = MINIMUM_HEIGHT; } } LOG.info("Setting resolution to {}x{} ", width, height); @@ -118,7 +120,7 @@ private int calculateWindowHeight() { Window window = webDriver.manage().window(); window.setSize(new Dimension(width, INITIAL_HEIGHT)); - Supplier heightSupplier = () -> { + IntSupplier heightSupplier = () -> { int heightResult = HEIGHT_NOT_CALCULATED; try { LOG.debug("Executing Resolution Modifier"); From e66ea3d0d09d742655f4a723d4550f42d6e760b6 Mon Sep 17 00:00:00 2001 From: Tomasz Kaik Date: Wed, 3 Jul 2019 21:16:01 +0200 Subject: [PATCH 02/13] screen collectors validates subimage size on full img Prevents RasterFormatException --- .../common/collectors/screen/ScreenCollector.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java index 3aa9c9f01..574c3e792 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java @@ -212,8 +212,7 @@ private byte[] getImagePart(byte[] fullPage, WebElement webElement) BufferedImage fullImg = ImageIO.read(in); Point point = webElement.getLocation(); Dimension size = webElement.getSize(); - BufferedImage screenshotSection = fullImg.getSubimage(point.getX(), point.getY(), - size.getWidth(), size.getHeight()); + BufferedImage screenshotSection = getSubImage(fullImg, point, size); return bufferedImageToByteArray(screenshotSection); } catch (IOException e) { throw new ProcessingException("Unable to create image from taken screenshot", e); @@ -222,6 +221,18 @@ private byte[] getImagePart(byte[] fullPage, WebElement webElement) } } + private BufferedImage getSubImage(BufferedImage fullImg, Point point, Dimension size) { + int width = size.getWidth(); + int height = size.getHeight(); + if (point.getX() + width > fullImg.getWidth()) { + width = fullImg.getWidth() - point.getX(); + } + if (point.getY() + height > fullImg.getHeight()) { + height = fullImg.getHeight() - point.getY(); + } + return fullImg.getSubimage(point.getX(), point.getY(), width, height); + } + private byte[] bufferedImageToByteArray(BufferedImage bufferedImage) throws ProcessingException { try (ByteArrayOutputStream temporaryStream = new ByteArrayOutputStream()) { ImageIO.write(bufferedImage, PNG_FORMAT, temporaryStream); From 39d9c3751cb8308846be3683ab299de7fed4ea41 Mon Sep 17 00:00:00 2001 From: Tomasz Kaik Date: Wed, 3 Jul 2019 21:26:14 +0200 Subject: [PATCH 03/13] Sample site and test suite cases for resolution height/paratial size issues --- .../comparators/layout/0px_height_page.jsp | 9 ++++ .../comparators/layout/1px_height_page.jsp | 9 ++++ .../layout/partial_bigger_than_page.jsp | 10 +++++ .../test-suite/partials/layout.xml | 43 +++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp create mode 100644 integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp create mode 100644 integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp diff --git a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp new file mode 100644 index 000000000..4a8bcba8b --- /dev/null +++ b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp @@ -0,0 +1,9 @@ + + + + +AET Demo Page + + + + diff --git a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp new file mode 100644 index 000000000..0ab1530ef --- /dev/null +++ b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp @@ -0,0 +1,9 @@ + + + + +AET Demo Page + + + + diff --git a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp new file mode 100644 index 000000000..1ee20b038 --- /dev/null +++ b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp @@ -0,0 +1,10 @@ + + + + +AET Demo Page + + +
+ + diff --git a/integration-tests/test-suite/partials/layout.xml b/integration-tests/test-suite/partials/layout.xml index c00480ecd..91e52393a 100644 --- a/integration-tests/test-suite/partials/layout.xml +++ b/integration-tests/test-suite/partials/layout.xml @@ -532,5 +532,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From cb014fec29db0cbe0bc94288b4d66f537c8dbb20 Mon Sep 17 00:00:00 2001 From: Tomasz Kaik Date: Sun, 14 Jul 2019 17:33:52 +0200 Subject: [PATCH 04/13] license header for new files; test-suite fixes --- .../resolution/ResolutionModifier.java | 4 +++- .../comparators/layout/0px_height_page.jsp | 19 +++++++++++++++++++ .../comparators/layout/1px_height_page.jsp | 19 +++++++++++++++++++ .../layout/partial_bigger_than_page.jsp | 19 +++++++++++++++++++ .../test-suite/partials/layout.xml | 4 ++-- 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifier.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifier.java index 7d1570ed6..ceff87bbe 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifier.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/modifiers/resolution/ResolutionModifier.java @@ -24,6 +24,7 @@ import com.cognifide.aet.job.common.utils.Sampler; import java.util.Map; import java.util.function.IntSupplier; +import java.util.function.Supplier; import org.apache.commons.lang3.math.NumberUtils; import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; @@ -109,6 +110,7 @@ private void setResolution() throws ProcessingException { } else if (height == HEIGHT_NOT_CALCULATED) { throw new ProcessingException("Failed to calculate height, could not parse javascript result to integer"); } else if (height < MINIMUM_HEIGHT) { + LOG.warn("Detected page height is 0, setting height to 1"); height = MINIMUM_HEIGHT; } } @@ -120,7 +122,7 @@ private int calculateWindowHeight() { Window window = webDriver.manage().window(); window.setSize(new Dimension(width, INITIAL_HEIGHT)); - IntSupplier heightSupplier = () -> { + Supplier heightSupplier = () -> { int heightResult = HEIGHT_NOT_CALCULATED; try { LOG.debug("Executing Resolution Modifier"); diff --git a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp index 4a8bcba8b..0c7cf683b 100644 --- a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp +++ b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page.jsp @@ -1,3 +1,22 @@ +<%-- + + 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. + +--%> diff --git a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp index 0ab1530ef..11c5bf002 100644 --- a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp +++ b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/1px_height_page.jsp @@ -1,3 +1,22 @@ +<%-- + + 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. + +--%> diff --git a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp index 1ee20b038..fab881810 100644 --- a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp +++ b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/partial_bigger_than_page.jsp @@ -1,3 +1,22 @@ +<%-- + + 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. + +--%> diff --git a/integration-tests/test-suite/partials/layout.xml b/integration-tests/test-suite/partials/layout.xml index 91e52393a..221104f5e 100644 --- a/integration-tests/test-suite/partials/layout.xml +++ b/integration-tests/test-suite/partials/layout.xml @@ -564,10 +564,10 @@ - + - + From 8b1a0a8003d8cf4a6c6289a79db8e0f0f209bdf7 Mon Sep 17 00:00:00 2001 From: Bartek Date: Thu, 8 Aug 2019 15:07:54 +0200 Subject: [PATCH 05/13] Minimum height set to 1px while getting partial screenshot --- .../collectors/screen/ScreenCollector.java | 38 ++++++++----------- .../layout/0px_height_page_partial.jsp | 29 ++++++++++++++ .../test-suite/partials/layout.xml | 14 +++++++ 3 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page_partial.jsp diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java index 574c3e792..25b33f939 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java @@ -26,35 +26,22 @@ import com.cognifide.aet.job.common.SeleniumWaitHelper; import com.cognifide.aet.job.common.modifiers.WebElementsLocatorParams; import com.cognifide.aet.vs.ArtifactsDAO; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.*; + +import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Set; import java.util.stream.Collectors; -import javax.imageio.ImageIO; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.collections.CollectionUtils; -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; -import org.openqa.selenium.Point; -import org.openqa.selenium.TakesScreenshot; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebDriverException; -import org.openqa.selenium.WebElement; public class ScreenCollector extends WebElementsLocatorParams implements CollectorJob { @@ -230,6 +217,13 @@ private BufferedImage getSubImage(BufferedImage fullImg, Point point, Dimension if (point.getY() + height > fullImg.getHeight()) { height = fullImg.getHeight() - point.getY(); } + if (point.getX() + width == 0) { + width = 1; + } + if (point.getY() + height == 0) { + height = 1; + } + return fullImg.getSubimage(point.getX(), point.getY(), width, height); } diff --git a/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page_partial.jsp b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page_partial.jsp new file mode 100644 index 000000000..d8472ef06 --- /dev/null +++ b/integration-tests/sample-site/src/main/webapp/sanity/comparators/layout/0px_height_page_partial.jsp @@ -0,0 +1,29 @@ +<%-- + + 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. + +--%> + + + + +AET Demo Page + + +

+ + diff --git a/integration-tests/test-suite/partials/layout.xml b/integration-tests/test-suite/partials/layout.xml index 221104f5e..124df0256 100644 --- a/integration-tests/test-suite/partials/layout.xml +++ b/integration-tests/test-suite/partials/layout.xml @@ -560,6 +560,20 @@
+ + + + + + + + + + + + + + From 522f26f84b15382a2fb57a26613b8f45c1fc4b07 Mon Sep 17 00:00:00 2001 From: Bartek Date: Thu, 8 Aug 2019 15:30:50 +0200 Subject: [PATCH 06/13] cleanup --- .../collectors/screen/ScreenCollector.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java index 25b33f939..eec965d13 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java @@ -30,8 +30,16 @@ import org.apache.commons.collections.CollectionUtils; 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.*; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.Point; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.WebElement; + import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -39,8 +47,16 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.stream.Collectors; public class ScreenCollector extends WebElementsLocatorParams implements CollectorJob { From ebc842c75966883eb1e6905df7db9ffe50bcd20b Mon Sep 17 00:00:00 2001 From: Bartek Jackowiak Date: Thu, 8 Aug 2019 15:33:31 +0200 Subject: [PATCH 07/13] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d44a3693..a3c944729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to AET will be documented in this file. - [PR-506](https://github.com/Cognifide/aet/pull/506) About tab ([#475](https://github.com/Cognifide/aet/issues/475)) - [PR-462](https://github.com/Cognifide/aet/pull/462) Popup window unification([#367](https://github.com/Cognifide/aet/issues/367)) - [PR-489](https://github.com/Cognifide/aet/pull/489) Cleaner integration tests +- [PR-518](https://github.com/Cognifide/aet/pull/518) Minimum site height ([#384](https://github.com/Cognifide/aet/issues/384)) ## Version 3.2.2 From fc00e36f57b9e44c8d492f8c9e6889de2f4c0fa6 Mon Sep 17 00:00:00 2001 From: Bartek Date: Fri, 9 Aug 2019 10:54:09 +0200 Subject: [PATCH 08/13] refactor --- .../common/collectors/screen/ScreenCollector.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java index eec965d13..049b07a60 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java @@ -227,17 +227,11 @@ private byte[] getImagePart(byte[] fullPage, WebElement webElement) private BufferedImage getSubImage(BufferedImage fullImg, Point point, Dimension size) { int width = size.getWidth(); int height = size.getHeight(); - if (point.getX() + width > fullImg.getWidth()) { - width = fullImg.getWidth() - point.getX(); + if (point.getX() + width > fullImg.getWidth() || point.getX() + width == 0) { + width = Math.max(1, fullImg.getWidth() - point.getX()); } - if (point.getY() + height > fullImg.getHeight()) { - height = fullImg.getHeight() - point.getY(); - } - if (point.getX() + width == 0) { - width = 1; - } - if (point.getY() + height == 0) { - height = 1; + if (point.getY() + height > fullImg.getHeight() || point.getY() + height == 0) { + height = Math.max(1, fullImg.getHeight() - point.getY()); } return fullImg.getSubimage(point.getX(), point.getY(), width, height); From 12aa32fa2c50a2ac1298736e2b16ffb4f2cbda57 Mon Sep 17 00:00:00 2001 From: Bartek Date: Fri, 9 Aug 2019 13:45:19 +0200 Subject: [PATCH 09/13] Add screen collector unit test --- .../collectors/screen/ScreenCollector.java | 17 ++-- .../screen/ScreenCollectorImageTest.java | 84 ++++++++++++++++++ .../jobs/src/test/resources/screens/48x48.png | Bin 0 -> 613 bytes 3 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 core/jobs/src/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java create mode 100644 core/jobs/src/test/resources/screens/48x48.png diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java index 049b07a60..6431f8c71 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollector.java @@ -224,19 +224,18 @@ private byte[] getImagePart(byte[] fullPage, WebElement webElement) } } - private BufferedImage getSubImage(BufferedImage fullImg, Point point, Dimension size) { - int width = size.getWidth(); - int height = size.getHeight(); - if (point.getX() + width > fullImg.getWidth() || point.getX() + width == 0) { - width = Math.max(1, fullImg.getWidth() - point.getX()); - } - if (point.getY() + height > fullImg.getHeight() || point.getY() + height == 0) { - height = Math.max(1, fullImg.getHeight() - point.getY()); - } + BufferedImage getSubImage(BufferedImage fullImg, Point point, Dimension size) { + int width = calculateMeasure(fullImg.getWidth(), size.getWidth(), point.getX()); + int height = calculateMeasure(fullImg.getHeight(), size.getHeight(), point.getY()); return fullImg.getSubimage(point.getX(), point.getY(), width, height); } + private int calculateMeasure(int fullImgMeasure, int subImgMeasure, int point) { + int result = Math.min(subImgMeasure, fullImgMeasure - point); + return Math.max(result, 1); + } + private byte[] bufferedImageToByteArray(BufferedImage bufferedImage) throws ProcessingException { try (ByteArrayOutputStream temporaryStream = new ByteArrayOutputStream()) { ImageIO.write(bufferedImage, PNG_FORMAT, temporaryStream); diff --git a/core/jobs/src/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java b/core/jobs/src/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java new file mode 100644 index 000000000..0140784cd --- /dev/null +++ b/core/jobs/src/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java @@ -0,0 +1,84 @@ +/** + * 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.job.common.collectors.screen; + +import com.cognifide.aet.job.api.collector.CollectorProperties; +import com.cognifide.aet.job.api.exceptions.ParametersException; +import com.cognifide.aet.vs.ArtifactsDAO; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.remote.RemoteWebDriver; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; + + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(MockitoJUnitRunner.class) +public class ScreenCollectorImageTest { + + private static final Color black = new Color(0); + + @InjectMocks + private ScreenCollector screenCollector; + + private BufferedImage testImage; + + + @Before + public void setup() throws Exception { + String path = getClass().getResource("/screens/48x48.png").getFile(); + File image = new File(path); + testImage = ImageIO.read(image); + } + + @Test + public void testSubImageSize() { + Point point = new org.openqa.selenium.Point(12, 12); + Dimension dimension = new Dimension(24, 24); + + BufferedImage subImage = screenCollector.getSubImage(testImage, point, dimension); + + assertThat(subImage.getHeight()).isEqualTo(24); + assertThat(subImage.getWidth()).isEqualTo(24); + + } + + @Test + public void testSubImageContent() { + Point point = new org.openqa.selenium.Point(12, 12); + Dimension dimension = new Dimension(24, 24); + + BufferedImage subImage = screenCollector.getSubImage(testImage, point, dimension); + boolean onlyBlack = true; + + for (int i = 0; i < subImage.getHeight(); i++) { + for (int j = 0; j < subImage.getWidth(); j++) { + onlyBlack &= black.equals(new Color(subImage.getRGB(i, j))); + } + } + assertThat(onlyBlack).isTrue(); + } +} diff --git a/core/jobs/src/test/resources/screens/48x48.png b/core/jobs/src/test/resources/screens/48x48.png new file mode 100644 index 0000000000000000000000000000000000000000..ec742855ae6555525141ee329dc221d972e93ae6 GIT binary patch literal 613 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1SD@Hc}*5j~)%+dJZrCUQ}-Y6VZ^eEk=p!G;2RHv!+Qdq{-gHJB$XIz@FWrqdVI#zaj zvDJKf=XP1`;A(on-qF2!@}ll3KlU%VpmePHaowKX-*;5AbDZT0K0A-o;cAwfmYneB zouL=MbJ_nAaF9?IGXCmPWypN}V<|s>{QE^Vr~lrWzc~KnY@QDtM~Z#SvyMm~F`jKY z_p@DL$5fTpA9E`1EZ`QhFN!Vu(OY~mtuei=$0uu^g^P~Z?ud6uVMZa3G9Ps;%9^5| zA{%CrUl^ucdTpP2eWJnowM%yT6-yNAC^o9NoLI5Ahbyb&(yEC`O0K^R#p`c;Q$MLX zc{Pt)A8W`$r%it!)PL9=z1hI@r3!1Z!~5>k+8(BTu?wzlSo1#lbk%pM-e+KMKM*l-)AiVUZ{NRrd*Ar&zdDA5Z$%4a+r{I6@xoc)5n0T@pr;JNj1^1m z%YcIHC7!;n?2kD(xfBE+-*a`}e#`psM%*#H8&ny;M< wn52E$@7=OfU;zkW$9%M3kOK%_6kcFEa*Z>3d+e;oK$96fUHx3vIVCg!0Aa2GQvd(} literal 0 HcmV?d00001 From 4c3f01e57c0fec3fb01dcd992c5e093e4605ee9f Mon Sep 17 00:00:00 2001 From: Bartek Date: Fri, 9 Aug 2019 16:14:50 +0200 Subject: [PATCH 10/13] Add tests to ScreenCollector --- .../screen/ScreenCollectorImageTest.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/core/jobs/src/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java b/core/jobs/src/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java index 0140784cd..bf6264e96 100644 --- a/core/jobs/src/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java +++ b/core/jobs/src/test/java/com/cognifide/aet/job/common/collectors/screen/ScreenCollectorImageTest.java @@ -15,18 +15,13 @@ */ package com.cognifide.aet.job.common.collectors.screen; -import com.cognifide.aet.job.api.collector.CollectorProperties; -import com.cognifide.aet.job.api.exceptions.ParametersException; -import com.cognifide.aet.vs.ArtifactsDAO; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.openqa.selenium.Dimension; import org.openqa.selenium.Point; -import org.openqa.selenium.remote.RemoteWebDriver; import javax.imageio.ImageIO; import java.awt.*; @@ -81,4 +76,26 @@ public void testSubImageContent() { } assertThat(onlyBlack).isTrue(); } + + @Test + public void testSubImageSize_whenElementIsHidden() { + Point point = new Point(0, 0); + Dimension dimension = new Dimension(0, 0); + + BufferedImage subImage = screenCollector.getSubImage(testImage, point, dimension); + + assertThat(subImage.getHeight()).isEqualTo(1); + assertThat(subImage.getWidth()).isEqualTo(1); + } + + @Test + public void testSubImageSize_whenElementIsBiggerThanImage() { + Point point = new Point(20, 20); + Dimension dimension = new Dimension(48, 48); + + BufferedImage subImage = screenCollector.getSubImage(testImage, point, dimension); + + assertThat(subImage.getHeight()).isEqualTo(28); + assertThat(subImage.getWidth()).isEqualTo(28); + } } From 4b36e675aa1a9adc471d73ccd83f91dc6a3c995f Mon Sep 17 00:00:00 2001 From: Bartek Date: Tue, 13 Aug 2019 09:08:50 +0200 Subject: [PATCH 11/13] Update test case --- integration-tests/test-suite/partials/layout.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/test-suite/partials/layout.xml b/integration-tests/test-suite/partials/layout.xml index 124df0256..24cc8b98b 100644 --- a/integration-tests/test-suite/partials/layout.xml +++ b/integration-tests/test-suite/partials/layout.xml @@ -564,7 +564,7 @@ - + From b01cc3f49a07c3f4eca04ee48693f14628ca8ca7 Mon Sep 17 00:00:00 2001 From: Bartek Date: Tue, 13 Aug 2019 09:52:53 +0200 Subject: [PATCH 12/13] Update integration tests number --- .../cognifide/aet/sanity/functional/HomePageTilesTest.java | 4 ++-- .../src/test/resources/features/filtering.feature | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java b/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java index ed0c3a51c..330b5cfc9 100644 --- a/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java +++ b/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java @@ -29,9 +29,9 @@ @Modules(GuiceModule.class) public class HomePageTilesTest { - private static final int TESTS = 149; + private static final int TESTS = 153; - private static final int EXPECTED_TESTS_SUCCESS = 85; + private static final int EXPECTED_TESTS_SUCCESS = 89; private static final int EXPECTED_TESTS_CONDITIONALLY_PASSED = 11; diff --git a/integration-tests/sanity-functional/src/test/resources/features/filtering.feature b/integration-tests/sanity-functional/src/test/resources/features/filtering.feature index de70a55a8..fb7241932 100644 --- a/integration-tests/sanity-functional/src/test/resources/features/filtering.feature +++ b/integration-tests/sanity-functional/src/test/resources/features/filtering.feature @@ -38,7 +38,7 @@ Feature: Tests Results Filtering Given I have opened sample tests report page When I search for tests containing "layout" Then There are 39 tiles visible - And Statistics text contains "39 ( 17 / 0 / 22 (11) / 0 )" + And Statistics text contains "43 ( 17 / 0 / 26 (11) / 0 )" Scenario: Filtering Tests Results: jserrors Given I have opened sample tests report page From a7bc060fb7fdbcb2f76cd8918d1d646e49b632d4 Mon Sep 17 00:00:00 2001 From: Bartek Date: Wed, 14 Aug 2019 07:51:31 +0200 Subject: [PATCH 13/13] Update filtering.feature tests number --- .../src/test/resources/features/filtering.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/sanity-functional/src/test/resources/features/filtering.feature b/integration-tests/sanity-functional/src/test/resources/features/filtering.feature index 62c9a01dc..31b16bb56 100644 --- a/integration-tests/sanity-functional/src/test/resources/features/filtering.feature +++ b/integration-tests/sanity-functional/src/test/resources/features/filtering.feature @@ -37,7 +37,7 @@ Feature: Tests Results Filtering Scenario: Filtering Tests Results: layout Given I have opened sample tests report page When I search for tests containing "layout" - Then There are 39 tiles visible + Then There are 43 tiles visible And Statistics text contains "43 ( 17 / 0 / 26 (11) / 0 )" Scenario: Filtering Tests Results: jserrors