Skip to content

Commit c3b9051

Browse files
author
Denys Zaiats
committed
[fullscreen_screenshot] - disabling the taking of the screenshots in case if no failures
1 parent 60bad95 commit c3b9051

File tree

6 files changed

+87
-34
lines changed

6 files changed

+87
-34
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.itarray</groupId>
88
<artifactId>automotion</artifactId>
9-
<version>2.1.0-rc2</version>
9+
<version>2.1.0-rc3</version>
1010
<name>Automotion</name>
1111
<description>Library for smart visual automation testing</description>
1212
<url>https://automotion.itarray.net</url>

src/main/java/net/itarray/automotion/internal/DriverFacade.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@ public void takeScreenshot(File file) {
4040
file.getParentFile().mkdirs();
4141

4242
if (!isPhantomJSDriver() && !isAppiumContext() && parseInt(getZoom().replace("%", "")) <= 100) {
43-
Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportRetina(100, 0, 0, (SystemHelper.isRetinaDisplay()) ? 2 : 1)).takeScreenshot(driver);
43+
long windowYOffset = (long) executeScript("return window.pageYOffset");
44+
long windowXOffset = (long) executeScript("return window.pageXOffset");
45+
46+
Screenshot screenshot = new AShot()
47+
.shootingStrategy(ShootingStrategies.viewportRetina(100,
48+
Integer.parseInt(System.getProperty("headerCutPx") != null ? System.getProperty("headerCutPx") : "0"),
49+
Integer.parseInt(System.getProperty("footerCutPx") != null ? System.getProperty("footerCutPx") : "0"),
50+
(SystemHelper.isRetinaDisplay()) ? 2 : 1)).takeScreenshot(driver);
51+
4452
try {
4553
ImageIO.write(screenshot.getImage(), "PNG", file);
4654
} catch (IOException e) {
4755
e.printStackTrace();
4856
}
57+
58+
executeScript("window.scrollTo(" + windowXOffset + ", " + windowYOffset + ")");
4959
} else {
5060
byte[] bytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
5161

src/main/java/net/itarray/automotion/internal/ResponsiveUIValidatorBase.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,17 @@
1212
import org.openqa.selenium.Dimension;
1313

1414
import java.awt.*;
15-
import java.io.BufferedWriter;
16-
import java.io.File;
17-
import java.io.FileOutputStream;
18-
import java.io.IOException;
19-
import java.io.OutputStreamWriter;
20-
import java.io.Writer;
15+
import java.io.*;
2116
import java.nio.charset.StandardCharsets;
2217

2318
import static net.itarray.automotion.validation.Constants.*;
2419

2520
public abstract class ResponsiveUIValidatorBase {
2621

27-
private final Errors errors;
2822
protected final UIElement page;
29-
private final long startTime;
3023
protected final UISnapshot snapshot;
24+
private final Errors errors;
25+
private final long startTime;
3126
private final DriverFacade driver;
3227
private final double zoomFactor;
3328
private DrawableScreenshot drawableScreenshot;
@@ -47,12 +42,12 @@ protected ResponsiveUIValidatorBase(UISnapshot snapshot) {
4742

4843

4944
public DrawableScreenshot getDrawableScreenshot() {
50-
if (drawableScreenshot == null) {
45+
if (drawableScreenshot == null && this.errors.hasMessages()) {
5146
File screenshotName = snapshot.takeScreenshot();
5247
Vector extend = driver.getExtend(screenshotName);
5348
this.drawableScreenshot = new DrawableScreenshot(extend, getTransform(), getDrawingConfiguration(), getNameOfToBeValidated(), screenshotName);
5449
}
55-
if (isWithReport() && !rootElementDrawn) {
50+
if (isWithReport() && !rootElementDrawn && this.errors.hasMessages()) {
5651
rootElementDrawn = true;
5752
drawRootElement();
5853
}
@@ -104,7 +99,7 @@ public ResponsiveUIValidatorBase dontDrawMap() {
10499
public boolean validate() {
105100

106101
//if (errors.hasMessages()) {
107-
compileValidationReport();
102+
compileValidationReport();
108103
//}
109104

110105
return !errors.hasMessages();
@@ -127,7 +122,9 @@ public boolean isPixels() {
127122
}
128123

129124
@Override
130-
public Scalar getTolerance() { return tolerance; }
125+
public Scalar getTolerance() {
126+
return tolerance;
127+
}
131128

132129
@Override
133130
public void add(String message) {
@@ -136,29 +133,41 @@ public void add(String message) {
136133

137134
@Override
138135
public void draw(UIElement element) {
139-
if (isWithReport()) {
140-
getDrawableScreenshot().draw(element);
136+
DrawableScreenshot drawableScreenshot = getDrawableScreenshot();
137+
if (drawableScreenshot != null) {
138+
if (isWithReport()) {
139+
getDrawableScreenshot().draw(element);
140+
}
141141
}
142142
}
143143

144144
@Override
145145
public void drawRoot(UIElement element) {
146-
if (isWithReport()) {
147-
getDrawableScreenshot().drawRoot(element);
146+
DrawableScreenshot drawableScreenshot = getDrawableScreenshot();
147+
if (drawableScreenshot != null) {
148+
if (isWithReport()) {
149+
getDrawableScreenshot().drawRoot(element);
150+
}
148151
}
149152
}
150153

151154
@Override
152155
public void drawHorizontalLine(Vector onLine) {
153-
if (isWithReport()) {
154-
getDrawableScreenshot().drawHorizontalLine(onLine.getY());
156+
DrawableScreenshot drawableScreenshot = getDrawableScreenshot();
157+
if (drawableScreenshot != null) {
158+
if (isWithReport()) {
159+
getDrawableScreenshot().drawHorizontalLine(onLine.getY());
160+
}
155161
}
156162
}
157163

158164
@Override
159165
public void drawVerticalLine(Vector onLine) {
160-
if (isWithReport()) {
161-
getDrawableScreenshot().drawVerticalLine(onLine.getX());
166+
DrawableScreenshot drawableScreenshot = getDrawableScreenshot();
167+
if (drawableScreenshot != null) {
168+
if (isWithReport()) {
169+
getDrawableScreenshot().drawVerticalLine(onLine.getX());
170+
}
162171
}
163172
}
164173

@@ -173,8 +182,12 @@ public int errorCount() {
173182
protected abstract String getNameOfToBeValidated();
174183

175184
private void compileValidationReport() {
176-
if (isWithReport()) {
177-
getDrawableScreenshot().saveDrawing();
185+
DrawableScreenshot drawableScreenshot = getDrawableScreenshot();
186+
187+
if (drawableScreenshot != null) {
188+
if (isWithReport()) {
189+
getDrawableScreenshot().saveDrawing();
190+
}
178191
}
179192

180193
if (isWithReport()) {
@@ -224,8 +237,8 @@ private void writeResults(DrawableScreenshot drawableScreenshot) {
224237
jsonResults.put(ROOT_ELEMENT, rootDetails);
225238
jsonResults.put(TIME_EXECUTION, String.valueOf(System.currentTimeMillis() - startTime) + " milliseconds");
226239
jsonResults.put(ELEMENT_NAME, getNameOfToBeValidated());
227-
jsonResults.put(SCREENSHOT, drawableScreenshot.getScreenshotName().getName());
228-
jsonResults.put(DRAWINGS, drawableScreenshot.getDrawingsOutput().getName());
240+
jsonResults.put(SCREENSHOT, drawableScreenshot != null ? drawableScreenshot.getScreenshotName().getName() : "");
241+
jsonResults.put(DRAWINGS, drawableScreenshot != null ? drawableScreenshot.getDrawingsOutput().getName() : "");
229242

230243
long ms = System.currentTimeMillis();
231244
String uuid = Helper.getGeneratedStringWithLength(7);

src/main/java/net/itarray/automotion/validation/ResponsiveUIValidator.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package net.itarray.automotion.validation;
22

3-
import net.itarray.automotion.internal.DrawingConfiguration;
4-
import net.itarray.automotion.internal.DriverFacade;
5-
import net.itarray.automotion.internal.HtmlReportBuilder;
6-
import net.itarray.automotion.internal.ResolutionImpl;
7-
import net.itarray.automotion.internal.ZoomUnknown;
3+
import net.itarray.automotion.internal.*;
84
import net.itarray.automotion.internal.geometry.Scalar;
95
import net.itarray.automotion.validation.properties.Resolution;
106
import net.itarray.automotion.validation.properties.Zoom;
117
import org.openqa.selenium.WebDriver;
12-
import org.openqa.selenium.chrome.ChromeDriverService;
138

149
import java.awt.*;
1510
import java.util.ArrayList;
@@ -167,6 +162,24 @@ public void setRetinaScaleFactor(double factor) {
167162
scaleFactor = factor;
168163
}
169164

165+
/**
166+
* Set header cut height. It is needed for the taking of fullscreen screenshot on the pages with the fixed header
167+
*
168+
* @param px
169+
*/
170+
public void setHeaderCutPx(int px) {
171+
System.setProperty("headerCutPx", String.valueOf(px));
172+
}
173+
174+
/**
175+
* Set footer cut height. It is needed for the taking of fullscreen screenshot on the pages with the fixed header
176+
*
177+
* @param px
178+
*/
179+
public void setFooterCutPx(int px) {
180+
System.setProperty("footerCutPx", String.valueOf(px));
181+
}
182+
170183
/**
171184
* Get retina scale factor. By default is 1
172185
*

src/main/java/util/validator/ResponsiveUIValidator.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ public void setRetinaScaleFactor(double factor) {
104104
responsiveUIValidator.setRetinaScaleFactor(factor);
105105
}
106106

107+
/**
108+
* Set header cut height. It is needed for the taking of fullscreen screenshot on the pages with the fixed header
109+
*
110+
* @param px
111+
*/
112+
public void setHeaderCutPx(int px) {
113+
System.setProperty("headerCutPx", String.valueOf(px));
114+
}
115+
116+
/**
117+
* Set footer cut height. It is needed for the taking of fullscreen screenshot on the pages with the fixed header
118+
*
119+
* @param px
120+
*/
121+
public void setFooterCutPx(int px) {
122+
System.setProperty("footerCutPx", String.valueOf(px));
123+
}
124+
107125
public boolean isMobileTopBarOffset() {
108126
return responsiveUIValidator.isMobileTopBarOffsetState();
109127
}

src/test/java/ResponsiveValidatorNewDSLTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.openqa.selenium.By;
1212
import org.openqa.selenium.WebDriver;
1313
import org.openqa.selenium.WebElement;
14-
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
1514

1615
import java.awt.*;
1716
import java.util.HashMap;
@@ -65,7 +64,7 @@ public void setUp() {
6564
WebDriverFactory driverFactory = new WebDriverFactory();
6665
driver = driverFactory.getDriver();
6766
driver.get("http://visual.itarray.net");
68-
driver.manage().window().maximize();
67+
//driver.manage().window().maximize();
6968

7069
start = System.currentTimeMillis();
7170

0 commit comments

Comments
 (0)