Skip to content

Commit adc1669

Browse files
author
pazone
committed
init
0 parents  commit adc1669

40 files changed

+1570
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
target
2+
.git
3+
.idea
4+
*.iml
5+

LICENCE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2014 YANDEX
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
aShot
2+
=====
3+
4+
WebDriver Screenshot utility
5+
6+
* Takes screenshot of web element from different device types
7+
* Prettifying screenshot images
8+
* Provides configurable screenshot comparison
9+
10+
#####WebElement view
11+
12+
The objective of taking web element looks simply and consists of three goals:
13+
* Take screenshot of the page
14+
* Find element's size and position
15+
* Crop origin screenshot image
16+
17+
As result aShot provides he image with WebElement
18+
![images snippet](//doc/img/images_intent_blur.png)
19+
20+
#####Taking screenshot of page
21+
22+
Different webDrivers have a different behaviour with screenshot taking. Some of them provides screenshot of whole page or viewport only. AShot cam be configured according to exact behaviour. This example configuration allows to take screenshot of whole page when driver provides viewport image only, for example, Chrome, Mobile Safari and etc.
23+
```java
24+
new AShot()
25+
.shootingStrategy(new ViewportPastingStrategy())
26+
.takeScreenshot(webDriver);
27+
```
28+
29+
#####Taking screenshot of web element
30+
31+
To take screenshot of element we just need to set the locator.
32+
```java
33+
new AShot()
34+
.componentSelector(By.cssSelector("#my_element"))
35+
.takeScreenshot(webDriver);
36+
```
37+
38+
In this case aShot will find element's location and position and will crop origin image. WebDriver API gives an opportunity to find coordinates of web element, but also different WebDriver implementations provides differently. In my opinion the most universal way to find coordinates is to use jQuery for it. AShot uses jQuery by default. But some drivers have a problems with Javascript execution such as Opera. In this case it's better to use another way to find web element coordinates.
39+
```java
40+
new AShot()
41+
.componentSelector(By.cssSelector("#my_element"))
42+
.coordsProvider(new WebDriverCoordsProvider()) //find coordinated using WebDriver API
43+
.takeScreenshot(webDriver);
44+
```
45+
Of course, if you don't like to use jQuery, you can implement you own CoordsProvider and contribute this project.
46+
47+
#####Prettifying web element screenshot
48+
49+
So, let's take a simple screenshot of weather snippet at Yandex.com.
50+
51+
```java
52+
new AShot()
53+
.componentSelector(By.cssSelector("#weather"))
54+
.takeScreenshot(webDriver);
55+
```
56+
AShot cropped origin images and we can see this result.
57+
![simple weather snippet](//doc/img/def_crop.png)
58+
59+
In default case DefaultCropper is using. But there is a way to use another cropper
60+
61+
```java
62+
new AShot()
63+
.componentSelector(By.cssSelector("#weather"))
64+
.withCropper(new IndentCropper() //overwriting cropper
65+
.addIndentFilter(blur())) //adding filter for indent
66+
.takeScreenshot(driver);
67+
```
68+
69+
![indent blur weather snippet](//doc/img/weather_indent_blur.png)
70+
This screenshot provides more information about element's position relatively his siblings and blurs indent to focus view on web element.
71+
72+
#####Comparison of screenshots
73+
As you noticed, the ```.takeScreenshot()``` returns a Screenshot object, containing screenshot image and data for comparison.
74+
75+
```java
76+
Screenshot myScreenshot = new AShot()
77+
.componentSelector(By.cssSelector(".#weather"))
78+
.addIgnoredElement(By.cssSelector(".#weather .blinking_element")) //ignored element
79+
.takeScreenshot(driver);
80+
```
81+
82+
To get a diff between two images use ImageDiffer:
83+
84+
```java
85+
ImageDiff diff = new ImageDiffer().makeDiff(myScreenshot, anotherScreenshot);
86+
BufferedImage diffImage = diff.getMarkedImage(); //megred image with marked diff areas
87+
```
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+

doc/img/def_crop.png

13.3 KB
Loading

doc/img/images_intent_blur.png

178 KB
Loading

doc/img/weather_indent_blur.png

58.7 KB
Loading

pom.xml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>ru.yandex.qatools.ashot</groupId>
8+
<artifactId>ashot</artifactId>
9+
<version>1.1</version>
10+
11+
<dependencies>
12+
<dependency>
13+
<groupId>org.seleniumhq.selenium</groupId>
14+
<artifactId>selenium-java</artifactId>
15+
<version>2.39.0</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>com.google.code.gson</groupId>
19+
<artifactId>gson</artifactId>
20+
<version>2.2.4</version>
21+
</dependency>
22+
23+
<!--test-->
24+
<dependency>
25+
<groupId>junit</groupId>
26+
<artifactId>junit</artifactId>
27+
<version>4.11</version>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.hamcrest</groupId>
32+
<artifactId>hamcrest-all</artifactId>
33+
<version>1.3</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.mockito</groupId>
37+
<artifactId>mockito-all</artifactId>
38+
<version>1.8.4</version>
39+
<scope>test</scope>
40+
</dependency>
41+
42+
43+
</dependencies>
44+
45+
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-source-plugin</artifactId>
51+
<executions>
52+
<execution>
53+
<id>attach-sources</id>
54+
<goals>
55+
<goal>jar</goal>
56+
</goals>
57+
</execution>
58+
</executions>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-compiler-plugin</artifactId>
63+
<version>3.1</version>
64+
<configuration>
65+
<source>1.7</source>
66+
<target>1.7</target>
67+
<forceJavacCompilerUse>true</forceJavacCompilerUse>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
74+
</project>

0 commit comments

Comments
 (0)