Skip to content

Commit b94f2a6

Browse files
author
Viacheslav Frolov
committed
Make VerticalPastingShootingStrategy aware of DevicePixelRatio
1 parent 9b4f4e1 commit b94f2a6

27 files changed

+604
-425
lines changed

README.md

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ As a result aShot provides an image of the WebElement
2626
<dependency>
2727
<groupId>ru.yandex.qatools.ashot</groupId>
2828
<artifactId>ashot</artifactId>
29-
<version>1.4.12</version>
29+
<version>1.5.1</version>
3030
</dependency>
3131
```
3232

@@ -39,33 +39,6 @@ new AShot()
3939
.takeScreenshot(webDriver);
4040
```
4141

42-
#####Capturing shots when a browser has fixed or variable header height
43-
When using AShot to capture screen of a device (iOS, Android) or it's simulator, then resulting image is returned with browser's header.
44-
45-
For example to capture page on iOS 7 device we will use fixed header's height of 98px.
46-
47-
```java
48-
int browserHeaderHeight = 98;
49-
new AShot()
50-
.shootingStrategy(new ViewportPastingStrategy(browserHeaderHeight))
51-
.takeScreenshot(webDriver);
52-
```
53-
54-
In iOS 8 Safari introduces a feature when browser's header might be 65px or 41px (with address bar hidden).
55-
56-
For example to capture pages on iPad 2 we will use a strategy that can detect current height of browser's header.
57-
58-
```java
59-
int minHeader = 41;
60-
int maxHeader = 65;
61-
int minViewPortHeight = 960;
62-
HeaderDetectionStrategy strategy =
63-
new VariableHeaderDetectionStrategy(minHeader, maxHeader, minViewPortHeight);
64-
new AShot()
65-
.shootingStrategy(new ViewportPastingStrategy(strategy))
66-
.takeScreenshot(webDriver);
67-
```
68-
6942
#####Capturing the WebElement
7043

7144
One can take a screenshot of the particular WebElement(s). Just specify the element(s).
@@ -82,7 +55,7 @@ new AShot()
8255
.takeScreenshot(webDriver, myWebElement);
8356
```
8457
Feel free to implement own CoordsProvider. Pull requests are welcome.
85-
58+
8659
#####Prettifying the screenshot
8760

8861
So, let's take a simple screenshot of the weather snippet at Yandex.com.
256 KB
Loading

doc/img/iPadSafariWithHeader.png

288 KB
Loading

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<groupId>ru.yandex.qatools.ashot</groupId>
1212
<artifactId>ashot</artifactId>
13-
<version>1.5-SNAPSHOT</version>
13+
<version>1.5.1-SNAPSHOT</version>
1414

1515
<organization>
1616
<name>Yandex</name>
@@ -49,7 +49,7 @@
4949
<dependency>
5050
<groupId>org.seleniumhq.selenium</groupId>
5151
<artifactId>selenium-java</artifactId>
52-
<version>2.39.0</version>
52+
<version>2.47.2</version>
5353
</dependency>
5454
<dependency>
5555
<groupId>com.google.code.gson</groupId>

src/main/java/ru/yandex/qatools/ashot/AShot.java

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import ru.yandex.qatools.ashot.coordinates.JqueryCoordsProvider;
1010
import ru.yandex.qatools.ashot.cropper.DefaultCropper;
1111
import ru.yandex.qatools.ashot.cropper.ImageCropper;
12-
import ru.yandex.qatools.ashot.screentaker.ScreenTaker;
13-
import ru.yandex.qatools.ashot.screentaker.ShootingStrategy;
12+
import ru.yandex.qatools.ashot.shooting.ShootingStrategy;
13+
import ru.yandex.qatools.ashot.shooting.SimpleShootingStrategy;
1414

1515
import java.awt.image.BufferedImage;
1616
import java.io.Serializable;
@@ -25,11 +25,11 @@
2525

2626
public class AShot implements Serializable {
2727

28-
private ScreenTaker taker = new ScreenTaker();
2928
private CoordsProvider coordsProvider = new JqueryCoordsProvider();
3029
private ImageCropper cropper = new DefaultCropper();
3130
private Set<By> ignoredLocators = new HashSet<>();
3231
private Set<Coords> ignoredAreas = new HashSet<>();
32+
private ShootingStrategy shootingStrategy = new SimpleShootingStrategy();
3333

3434
public AShot coordsProvider(final CoordsProvider coordsProvider) {
3535
this.coordsProvider = coordsProvider;
@@ -42,20 +42,6 @@ public AShot imageCropper(ImageCropper cropper) {
4242
return this;
4343
}
4444

45-
/**
46-
* Sets taker impl.
47-
* Usually is not used.
48-
*
49-
* @param taker ScreenTaker
50-
* @return this;
51-
* @see ru.yandex.qatools.ashot.screentaker.ScreenTaker
52-
*/
53-
@SuppressWarnings("UnusedDeclaration")
54-
public AShot screenTaker(ScreenTaker taker) {
55-
this.taker = taker;
56-
return this;
57-
}
58-
5945
/**
6046
* Sets the list of locators to ignore during image comparison.
6147
*
@@ -106,22 +92,10 @@ public synchronized AShot addIgnoredArea(Coords area) {
10692
*
10793
* @param strategy shooting strategy
10894
* @return this
109-
* @see ru.yandex.qatools.ashot.screentaker.ShootingStrategy
95+
* @see ru.yandex.qatools.ashot.shooting.ShootingStrategy
11096
*/
11197
public AShot shootingStrategy(ShootingStrategy strategy) {
112-
this.taker.withShootingStrategy(strategy);
113-
return this;
114-
}
115-
116-
/**
117-
* Sets device pixel ratio.
118-
* for example, Retina = 2.
119-
*
120-
* @param dpr device pixel ratio
121-
* @return this
122-
*/
123-
public AShot dpr(float dpr) {
124-
this.taker.withDpr(dpr);
98+
this.shootingStrategy = strategy;
12599
return this;
126100
}
127101

@@ -136,7 +110,7 @@ public AShot dpr(float dpr) {
136110
*/
137111
public Screenshot takeScreenshot(WebDriver driver, Collection<WebElement> elements) {
138112
Set<Coords> elementCoords = coordsProvider.ofElements(driver, elements);
139-
BufferedImage shot = taker.take(driver, elementCoords);
113+
BufferedImage shot = shootingStrategy.getScreenshot(driver, elementCoords);
140114
Screenshot screenshot = cropper.crop(shot, elementCoords);
141115
Set<Coords> ignoredAreas = compileIgnoredAreas(driver, intersectingWith(screenshot));
142116
screenshot.setIgnoredAreas(ignoredAreas);
@@ -163,7 +137,7 @@ public Screenshot takeScreenshot(WebDriver driver, WebElement element) {
163137
* @see Screenshot
164138
*/
165139
public Screenshot takeScreenshot(WebDriver driver) {
166-
Screenshot screenshot = new Screenshot(taker.take(driver));
140+
Screenshot screenshot = new Screenshot(shootingStrategy.getScreenshot(driver));
167141
screenshot.setIgnoredAreas(compileIgnoredAreas(driver, CoordsPreparationStrategy.simple()));
168142
return screenshot;
169143
}

src/main/java/ru/yandex/qatools/ashot/screentaker/FixedHeaderDetectionStrategy.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/ru/yandex/qatools/ashot/screentaker/HeadCuttingShootingStrategy.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/main/java/ru/yandex/qatools/ashot/screentaker/HeaderDetectionStrategy.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/main/java/ru/yandex/qatools/ashot/screentaker/ScreenTaker.java

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/main/java/ru/yandex/qatools/ashot/screentaker/ShootingStrategy.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)