-
Notifications
You must be signed in to change notification settings - Fork 49
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
Full page screenshot support in Chrome #294
Changes from 33 commits
2a8dcb9
ae0ac30
cac7773
8a6f67b
bc537b4
c3f9f4f
26772c8
330a8a6
9ada174
834a837
e0120aa
49dbc7f
ed587b2
239dc4a
503089f
863341b
483662c
6a0f420
7f3d41b
484381b
a5fb1d9
a2cff67
2da4b7e
b5b0eba
b470103
63de36c
ac0178a
69de42e
a85618f
b2e2e1d
2cafbda
80da189
5f5e26c
0ae1f70
0af3bf3
12e19a9
499442c
864f783
0ba974f
4533475
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import java.util.Map; | ||
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; | ||
|
@@ -34,23 +35,24 @@ public class ResolutionModifier implements CollectorJob { | |
|
||
private static final Logger LOG = LoggerFactory.getLogger(ResolutionModifier.class); | ||
|
||
private static final String PARAM_MAXIMIZE = "maximize"; | ||
|
||
private static final String WIDTH_PARAM = "width"; | ||
|
||
private static final String HEIGHT_PARAM = "height"; | ||
|
||
private static final int MAX_SIZE = 100000; | ||
private static final String JAVASCRIPT_GET_BODY_HEIGHT = "return document.body.scrollHeight"; | ||
|
||
private static final int MAX_SIZE = 15000; | ||
|
||
private static final int INITIAL_HEIGHT = 300; | ||
|
||
private static final int HEIGHT_NOT_DEFINED = 0; | ||
|
||
private final WebDriver webDriver; | ||
|
||
private int width; | ||
|
||
private int height; | ||
|
||
@Deprecated | ||
private boolean maximize; | ||
|
||
public ResolutionModifier(WebDriver webDriver) { | ||
this.webDriver = webDriver; | ||
} | ||
|
@@ -64,33 +66,32 @@ public CollectorStepResult collect() throws ProcessingException { | |
|
||
@Override | ||
public void setParameters(Map<String, String> params) throws ParametersException { | ||
String paramValue = params.get(PARAM_MAXIMIZE); | ||
maximize = Boolean.valueOf(paramValue); | ||
|
||
if (params.containsKey(WIDTH_PARAM) && params.containsKey(HEIGHT_PARAM)) { | ||
if (params.containsKey(WIDTH_PARAM)) { | ||
width = NumberUtils.toInt(params.get(WIDTH_PARAM)); | ||
ParametersValidator.checkRange(width, 1, MAX_SIZE, "Width should be greater than 0"); | ||
|
||
height = NumberUtils.toInt(params.get(HEIGHT_PARAM)); | ||
ParametersValidator.checkRange(height, 1, MAX_SIZE, "Height should be greater than 0"); | ||
|
||
ParametersValidator.checkParameter(!maximize, | ||
"You cannot maximize the window and specify the dimension"); | ||
} else if (params.containsKey(WIDTH_PARAM) || params.containsKey(HEIGHT_PARAM)) { | ||
throw new ParametersException("You have to specify both width and height"); | ||
if (params.containsKey(HEIGHT_PARAM)) { | ||
height = NumberUtils.toInt(params.get(HEIGHT_PARAM)); | ||
ParametersValidator | ||
.checkRange(height, 1, MAX_SIZE, "Height should be greater than 0"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's put here more verbose info:
|
||
} | ||
} else { | ||
throw new ParametersException("You have to specify width, height parameter is optional"); | ||
} | ||
} | ||
|
||
private void setResolution(WebDriver webDriver) { | ||
Window window = webDriver.manage().window(); | ||
if (maximize) { | ||
window.maximize(); | ||
LOG.error("Trying to maximise window to {}x{}!", window.getSize().getWidth(), | ||
window.getSize().getHeight()); | ||
} else { | ||
LOG.info("Setting resolution to {}x{} ", width, height); | ||
window.setSize(new Dimension(width, height)); | ||
if (height == HEIGHT_NOT_DEFINED) { | ||
window.setSize(new Dimension(width, INITIAL_HEIGHT)); | ||
JavascriptExecutor js = (JavascriptExecutor) webDriver; | ||
height = Integer | ||
.parseInt(js.executeScript(JAVASCRIPT_GET_BODY_HEIGHT).toString()); | ||
if (height > MAX_SIZE) { | ||
LOG.warn("Height is over browser limit, changing height to {}", MAX_SIZE); | ||
height = MAX_SIZE; | ||
} | ||
} | ||
LOG.info("Setting resolution to {}x{} ", width, height); | ||
window.setSize(new Dimension(width, height)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ Module name: **hide** | |
|
||
| ! Important information | | ||
|:----------------------- | | ||
| In order to use this modifier it must be declared after the open module in the definition of the test suite XML. | | ||
| *In order to use this modifier it must be declared after the open module in the definition of the test suite XML. | ||
*In order to use this modifier with Resolution Modifier it must be declared before the Resolution Modifier.| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please explain why - e.g. |
||
|
||
##### Parameters | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
#### Resolution Modifier | ||
|
||
Resolution Modifier is responsible for changing browser screen size. Affects [[Screen Collector | ScreenCollector]] results. | ||
Resolution Modifier is responsible for changing browser screen size. Affects [[Screen Collector | ScreenCollector]] results. | ||
|
||
| ! Note | | ||
|:------ | | ||
| Please note that final resoulution of screenshots may be different when scrollbar is dispayed. <br/><br/> Default width of Firefox's Scrollbar is equal to 33px. (so when you want to grab viewport of size 1024, then set width parameter to 1057px) | | ||
| Firefox: Please note that final resoulution of screenshots may be different when scrollbar is dispayed. <br/><br/> Default width of Firefox's Scrollbar is equal to 33px. (so when you want to grab viewport of size 1024, then set width parameter to 1057px) | | ||
|
||
Module name: **resolution** | ||
|
||
##### Parameters | ||
|
||
| Parameter | Value | Description | Mandatory | | ||
| --------- | ----- | ----------- | --------- | | ||
| `width` | int (1 to 100000) | Window width | no | | ||
| `height` | int (1 to 100000) | Window height | no | | ||
| `width` | int (1 to 15000) | Window width | yes | | ||
| `height` | int (1 to 15000) | Window height | no | | ||
|
||
| ! Important information | | ||
|:----------------------- | | ||
| You cannot maximize the window and specify the dimension at the same time. If you specify height param you have to also specify width param and vice versa. | | ||
| Note | | ||
| When height is not specified then it's compute by JavaScript. <br/> If the resolution is specified without height parameter it should be specified after open. | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the typo |
||
|
||
##### Example Usage | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add those changes into resolution modifier documentation:
maximize
parameterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated - 5f5e26c