Skip to content
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

Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2a8dcb9
Suite files udpated for chrome - line number changes, filter rules ch…
smoczysko88 Jul 18, 2018
ae0ac30
ChromeEntirePageScreen
Slasheruus Jul 19, 2018
cac7773
Merge remote-tracking branch 'origin/ChromeFullPageScreen' into bugfi…
smoczysko88 Jul 19, 2018
8a6f67b
Chrome limit handler && disabled scrolling
PiteroS678 Jul 19, 2018
bc537b4
Refactoring
PiteroS678 Jul 19, 2018
c3f9f4f
Tests for ResolutionModifier update
PiteroS678 Jul 20, 2018
26772c8
Setting resolution for chrome screen comparator
smoczysko88 Jul 20, 2018
330a8a6
Collect page height update
PiteroS678 Jul 20, 2018
9ada174
Merge remote-tracking branch 'origin/ChromeFullPageScreenNoScrolling'…
smoczysko88 Jul 20, 2018
834a837
Wiki - Hide Modifier update
PiteroS678 Jul 20, 2018
e0120aa
Changed pageLoadStrategy && updated ResolutionModifierTest
PiteroS678 Jul 23, 2018
49dbc7f
Merge remote-tracking branch 'origin/ChromeFullPageScreenNoScrolling'…
smoczysko88 Jul 23, 2018
ed587b2
New chrome arg to fix headless+proxy screenshot issue
tkaik Jul 23, 2018
239dc4a
Merge remote-tracking branch 'origin/ChromeFullPageScreenNoScrolling'…
smoczysko88 Jul 23, 2018
503089f
Revert pageLoadStrategy
PiteroS678 Jul 23, 2018
863341b
Merge remote-tracking branch 'origin/ChromeFullPageScreenNoScrolling'…
smoczysko88 Jul 23, 2018
483662c
Merge remote-tracking branch 'origin/task/w3c-nuvalidator-version-upg…
Slasheruus Jul 25, 2018
6a0f420
Merge branch 'bugfix/aet-integration-tests-stabilization' of github.c…
smoczysko88 Jul 25, 2018
7f3d41b
Merge branch 'ChromeFullPageScreenNoScrolling' of https://github.com/…
tkaik Jul 25, 2018
484381b
Merge branch 'bugfix/aet-integration-tests-stabilization' of github.c…
smoczysko88 Jul 25, 2018
a5fb1d9
S-comparator-Layout-Hide-leaveBlankSpace-false - ResolutionModifier a…
PiteroS678 Jul 25, 2018
a2cff67
ResolutionModifier - refactor
PiteroS678 Jul 26, 2018
2da4b7e
Decreased wait timeouts for tests stabilizations
tkaik Jul 26, 2018
b5b0eba
ResolutionModifier - refactor
PiteroS678 Jul 26, 2018
b470103
ResolutionModifierTest - update & refactor
PiteroS678 Jul 27, 2018
63de36c
Adjustments for Chrome compatibility
smoczysko88 Jul 27, 2018
ac0178a
Tests adjustments for chrome.
smoczysko88 Jul 27, 2018
69de42e
ResolutionModifierTest - new test & refactor,
PiteroS678 Jul 27, 2018
a85618f
Increased cookie max age for tests stabilization
tkaik Jul 27, 2018
b2e2e1d
ResolutionModifier - refactor
PiteroS678 Jul 31, 2018
2cafbda
ResolutionModifierTest - update
PiteroS678 Jul 31, 2018
80da189
ResolutionModifierTest - refactor
PiteroS678 Jul 31, 2018
5f5e26c
Wiki - ResolutionModifier update
PiteroS678 Jul 31, 2018
0ae1f70
layout.xml - new tests
PiteroS678 Aug 1, 2018
0af3bf3
height_detection.jsp - minor fix
PiteroS678 Aug 1, 2018
12e19a9
Wiki - ResolutionModifier update
PiteroS678 Aug 1, 2018
499442c
Wiki - HideModifier update
PiteroS678 Aug 1, 2018
864f783
ResolutionModifier update
PiteroS678 Aug 1, 2018
0ba974f
updated changelog
plutasnyy Aug 2, 2018
4533475
Merge branch 'milestone/chrome-support' into bugfix/aet-integration-t…
plutasnyy Aug 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Copy link
Contributor

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:

  • height param is no longer mandatory,
  • max page height,
  • how does AET detect page height,
  • remove maximize parameter

Copy link
Contributor Author

@PiteroS678 PiteroS678 Jul 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated - 5f5e26c


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;
}
Expand All @@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put here more verbose info:

"Height should be greater than 0 and smaller than " + MAX_SIZE

}
} 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
Expand Up @@ -29,20 +29,22 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;

@RunWith(MockitoJUnitRunner.class)
public class ResolutionModifierTest {

private static final String PARAM_MAXIMIZE = "maximize";

private static final String WIDTH_PARAM = "width";

private static final String HEIGHT_PARAM = "height";

private static final String NOT_A_NUMBER = "NaN";

private static final String JAVASCRIPT_GET_BODY_HEIGHT = "return document.body.scrollHeight";

private static final int WINDOW_WIDTH = 1024;

private static final int WINDOW_HEIGHT = 768;
Expand All @@ -51,8 +53,13 @@ public class ResolutionModifierTest {

private static final int CUSTOM_HEIGHT = 600;

private static final int BROWSER_HEIGHT_LIMIT = 15000;

@Mock
private RemoteWebDriver webDriver;

@Mock
private WebDriver webDriver;
private Capabilities capabilities;

@Mock
private Map<String, String> params;
Expand All @@ -72,6 +79,7 @@ public class ResolutionModifierTest {
@Before
public void setUp() {
when(webDriver.manage()).thenReturn(options);
when(webDriver.getCapabilities()).thenReturn(capabilities);
when(options.window()).thenReturn(window);
when(window.getSize()).thenReturn(windowDimension);
when(windowDimension.getWidth()).thenReturn(WINDOW_WIDTH);
Expand Down Expand Up @@ -110,28 +118,6 @@ public void setParametersTest_height0() throws ParametersException {
tested.setParameters(params);
}

@Test(expected = ParametersException.class)
public void setParametersTest_maximizeWithWindowSize() throws ParametersException {
when(params.get(PARAM_MAXIMIZE)).thenReturn("true");
when(params.containsKey(HEIGHT_PARAM)).thenReturn(true);
when(params.get(HEIGHT_PARAM)).thenReturn("100");

tested.setParameters(params);
}

@Test
public void collectTest_maximize() throws ParametersException, ProcessingException {
when(params.get(PARAM_MAXIMIZE)).thenReturn("true");

tested.setParameters(params);
tested.collect();

verify(window, times(1)).maximize();
verify(windowDimension, times(1)).getWidth();
verify(windowDimension, times(1)).getHeight();
verify(window, never()).setSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
}

@Test
public void collectTest_setWidthHeight() throws ParametersException, ProcessingException {
when(params.containsKey(HEIGHT_PARAM)).thenReturn(true);
Expand All @@ -142,25 +128,49 @@ public void collectTest_setWidthHeight() throws ParametersException, ProcessingE
tested.setParameters(params);
tested.collect();

verify(window, never()).maximize();
verify(windowDimension, never()).getWidth();
verify(windowDimension, never()).getHeight();
verify(window, times(1)).setSize(new Dimension(CUSTOM_WIDTH, CUSTOM_HEIGHT));
}

@Test(expected = ParametersException.class)
public void collectTest_setOnlyHeight() throws ParametersException, ProcessingException {
public void collectTest_setOnlyHeight() throws ParametersException {
when(params.containsKey(HEIGHT_PARAM)).thenReturn(true);
when(params.get(HEIGHT_PARAM)).thenReturn("" + CUSTOM_HEIGHT);

tested.setParameters(params);
}

@Test(expected = ParametersException.class)
public void collectTest_setOnlyWidth() throws ParametersException, ProcessingException {
private void setUp_setOnlyWidth(){
when(params.containsKey(WIDTH_PARAM)).thenReturn(true);
when(params.containsKey(HEIGHT_PARAM)).thenReturn(false);
when(params.get(WIDTH_PARAM)).thenReturn("" + CUSTOM_WIDTH);
}

@Test
public void collectTest_setOnlyWidth() throws ParametersException, ProcessingException {
setUp_setOnlyWidth();
when(webDriver.executeScript(JAVASCRIPT_GET_BODY_HEIGHT))
.thenReturn(CUSTOM_HEIGHT);

tested.setParameters(params);
tested.collect();

verify(windowDimension, never()).getWidth();
verify(windowDimension, never()).getHeight();
verify(window, times(1)).setSize(new Dimension(CUSTOM_WIDTH, CUSTOM_HEIGHT));
}

@Test
public void collectTest_setOnlyWidth_reachedBrowserHeightLimit() throws ParametersException, ProcessingException {
setUp_setOnlyWidth();
when(webDriver.executeScript(JAVASCRIPT_GET_BODY_HEIGHT))
.thenReturn(BROWSER_HEIGHT_LIMIT + 5000L);

tested.setParameters(params);
tested.collect();

verify(windowDimension, never()).getWidth();
verify(windowDimension, never()).getHeight();
verify(window, times(1)).setSize(new Dimension(CUSTOM_WIDTH, BROWSER_HEIGHT_LIMIT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ private DesiredCapabilities setupCapabilities() {

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-plugins");
options.addArguments("--headless");
options.addArguments("--hide-scrollbars");
options.setAcceptInsecureCerts(true);

capabilities.setCapability(ChromeOptions.CAPABILITY, options);

Expand Down
3 changes: 2 additions & 1 deletion documentation/src/main/wiki/HideModifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain why - e.g. because the Hide modifier might affect the total height of the page (when used without leaveBlankSpace="true")


##### Parameters

Expand Down
13 changes: 6 additions & 7 deletions documentation/src/main/wiki/ResolutionModifier.md
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. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the typo compute -> computed and make the open a link text that points to https://github.com/Cognifide/aet/wiki/Open


##### Example Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,6 @@ <h1 id="forms">Forms</h1>
</div>
</div>
</div>
<div class="form-group">
<label for="select" class="col-lg-2 control-label">Selects</label>
<div class="col-lg-10">
<select class="form-control" id="select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select> <br /> <select multiple="" class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-default">Cancel</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,6 @@
</div>
</div>
</div>
<div class="form-group">
<label for="select" class="col-lg-2 control-label">Selects</label>
<div class="col-lg-10">
<select class="form-control" id="select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select> <br /> <select multiple="" class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-default">Cancel</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
Cookie dynamicCookieValue = new Cookie("DynamicSampleCookieName",dt.format(date));
Cookie dynamicCookieName = new Cookie(dt.format(date),"staticCookieValue");
dynamicCookieValue.setMaxAge(60*60*24);
// expire cookie after 1 second in order to have it cleared for next run
dynamicCookieName.setMaxAge(10);
// expire cookie after 60 second in order to have it cleared for next run
dynamicCookieName.setMaxAge(60);
response.addCookie( dynamicCookieValue );
response.addCookie( dynamicCookieName );
%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<test name="S-comparator-Layout-Executejavascript-cmd-hide">
<collect>
<open />
<resolution width="1500" />
<sleep duration="3000" />
<executejavascript cmd="document.getElementById('demo1').style.display='none'" />
<executejavascript cmd="document.getElementById('demo2').style.display='none'" />
Expand All @@ -39,6 +40,7 @@
<test name="S-comparator-Layout-Executejavascript-cmd-background">
<collect>
<open />
<resolution width="1500" />
<sleep duration="3000" />
<executejavascript cmd="document.body.style.background = 'green';" />
<screen />
Expand All @@ -53,6 +55,7 @@
<test name="S-comparator-Layout-Executejavascript-snippetUrl-background">
<collect>
<open />
<resolution width="1500" />
<sleep duration="3000" />
<executejavascript snippetUrl="${snippet.url.domain}snippets/change-bg-snippet.js" />
<screen />
Expand All @@ -67,6 +70,7 @@
<test name="S-comparator-Layout-Executejavascript-snippetUrl-basicAuth-background">
<collect>
<open />
<resolution width="1500" />
<sleep duration="3000" />
<executejavascript snippetUrl="${snippet.url.domain}secured/change-bg-snippet.js" basicAuthUsername="user" basicAuthPassword="password" />
<screen />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<accessibility-filter principle="WCAG2A.Principle1.Guideline1_3.1_3_1.F68" />
<accessibility-filter line="252" />
<accessibility-filter column="6" />
<accessibility-filter line="317" column="50" />
<accessibility-filter line="299" column="50" />
</accessibility>
</compare>
<urls>
Expand Down
1 change: 1 addition & 0 deletions integration-tests/test-suite/partials/click.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<test name="S-modifier-Click">
<collect>
<open />
<resolution width="1500" />
<click xpath="//a[@id='hide']" timeout="3000"/>
<sleep duration="1000" />
<screen />
Expand Down
Loading