Skip to content

Commit 83e57d0

Browse files
Merge pull request #115 from aquality-automation/feature/support-logging-preferences
Support logging preferences from settings.json
2 parents 7dbfca5 + 0cfc422 commit 83e57d0

33 files changed

+411
-114
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Build results
22
target
3+
downloads
34

45
# Log file
56
*.log

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2022 Aquality Automation
189+
Copyright 2023 Aquality Automation
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.aquality-automation</groupId>
88
<artifactId>aquality-selenium</artifactId>
9-
<version>3.1.0</version>
9+
<version>3.2.0</version>
1010
<packaging>jar</packaging>
1111
<name>Aquality Selenium</name>
1212
<description>Library around Selenium WebDriver</description>
@@ -81,19 +81,19 @@
8181
<dependency>
8282
<groupId>com.github.aquality-automation</groupId>
8383
<artifactId>aquality-selenium-core</artifactId>
84-
<version>2.0.4</version>
84+
<version>2.0.5</version>
8585
</dependency>
8686

8787
<dependency>
8888
<groupId>io.github.bonigarcia</groupId>
8989
<artifactId>webdrivermanager</artifactId>
90-
<version>5.3.0</version>
90+
<version>5.3.1</version>
9191
</dependency>
9292

9393
<dependency>
9494
<groupId>com.fasterxml.jackson.core</groupId>
9595
<artifactId>jackson-databind</artifactId>
96-
<version>2.13.4</version>
96+
<version>2.14.1</version>
9797
</dependency>
9898

9999
<dependency>

src/main/java/aquality/selenium/browser/devtools/NetworkHandling.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,32 @@ public NetworkInterceptor addResponseHandler(Predicate<HttpResponse> responseMat
313313
public void clearNetworkInterceptor() {
314314
resetNetworkFilter();
315315
}
316+
317+
/**
318+
* Activates emulation of network conditions.
319+
* @param offline True to emulate internet disconnection.
320+
* @param latency Minimum latency from request sent to response headers received (ms).
321+
* @param downloadThroughput Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
322+
* @param uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
323+
*/
324+
public void emulateConditions(Boolean offline, Number latency, Number downloadThroughput, Number uploadThroughput) {
325+
tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty()));
326+
tools.sendCommand(emulateNetworkConditions(offline, latency, downloadThroughput, uploadThroughput, Optional.empty()));
327+
}
328+
329+
/**
330+
* Activates emulation of network conditions.
331+
* @param offline True to emulate internet disconnection.
332+
* @param latency Minimum latency from request sent to response headers received (ms).
333+
* @param downloadThroughput Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
334+
* @param uploadThroughput Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
335+
* @param connectionType Connection type if known.
336+
* Possible values: "none", "cellular2g", "cellular3g", "cellular4g", "bluetooth", "ethernet",
337+
* "wifi", "wimax", "other".
338+
*/
339+
public void emulateConditions(Boolean offline, Number latency, Number downloadThroughput, Number uploadThroughput, String connectionType) {
340+
tools.sendCommand(enable(Optional.empty(), Optional.empty(), Optional.empty()));
341+
tools.sendCommand(emulateNetworkConditions(offline, latency, downloadThroughput, uploadThroughput,
342+
Optional.of(ConnectionType.fromString(connectionType))));
343+
}
316344
}

src/main/java/aquality/selenium/configuration/ITimeoutConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
public interface ITimeoutConfiguration extends aquality.selenium.core.configurations.ITimeoutConfiguration {
99

1010
/**
11-
* Gets WedDriver AsynchronousJavaScript timeout.
11+
* Gets WebDriver AsynchronousJavaScript timeout.
1212
*
1313
* @return AsynchronousJavaScript timeout.
1414
*/
1515
Duration getScript();
1616

1717
/**
18-
* Gets WedDriver PageLoad timeout.
18+
* Gets WebDriver PageLoad timeout.
1919
*
2020
* @return PageLoad timeout.
2121
*/

src/main/java/aquality/selenium/configuration/driversettings/ChromeSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public AbstractDriverOptions<?> getDriverOptions() {
2121
setCapabilities(chromeOptions);
2222
setChromeArgs(chromeOptions);
2323
chromeOptions.setPageLoadStrategy(getPageLoadStrategy());
24+
setLoggingPreferences(chromeOptions, ChromeOptions.LOGGING_PREFS);
2425
return chromeOptions;
2526
}
2627

src/main/java/aquality/selenium/configuration/driversettings/DriverSettings.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88
import org.apache.commons.lang3.StringUtils;
99
import org.openqa.selenium.MutableCapabilities;
1010
import org.openqa.selenium.PageLoadStrategy;
11+
import org.openqa.selenium.logging.LoggingPreferences;
12+
1113
import java.io.File;
1214
import java.io.IOException;
1315
import java.util.Arrays;
1416
import java.util.Collections;
1517
import java.util.List;
1618
import java.util.Map;
19+
import java.util.logging.Level;
1720
import java.util.stream.Collectors;
1821

1922
abstract class DriverSettings implements IDriverSettings {
2023

2124
private final ISettingsFile settingsFile;
2225
private Map<String, Object> options;
2326
private Map<String, Object> capabilities;
27+
private Map<String, Level> loggingPreferences;
2428
private List<String> startArguments;
2529

2630
protected DriverSettings(ISettingsFile settingsFile) {
@@ -45,6 +49,15 @@ protected Map<String, Object> getBrowserCapabilities() {
4549
return capabilities;
4650
}
4751

52+
protected Map<String, Level> getLoggingPreferences() {
53+
if (loggingPreferences == null) {
54+
loggingPreferences = getMapOrEmpty(CapabilityType.LOGGING_PREFERENCES).entrySet().stream().collect(
55+
Collectors.toMap(entry -> entry.getKey().toLowerCase(),
56+
pair -> Level.parse(pair.getValue().toString().toUpperCase())));
57+
}
58+
return loggingPreferences;
59+
}
60+
4861
private Map<String, Object> getMapOrEmpty(CapabilityType capabilityType) {
4962
String path = getDriverSettingsPath(capabilityType);
5063
Map<String, Object> map = getSettingsFile().isValuePresent(path) ? getSettingsFile().getMap(path) : Collections.emptyMap();
@@ -123,6 +136,14 @@ void setCapabilities(MutableCapabilities options) {
123136
getBrowserCapabilities().forEach(options::setCapability);
124137
}
125138

139+
void setLoggingPreferences(MutableCapabilities options, String capabilityKey) {
140+
if (!getLoggingPreferences().isEmpty()) {
141+
LoggingPreferences logs = new LoggingPreferences();
142+
getLoggingPreferences().forEach(logs::enable);
143+
options.setCapability(capabilityKey, logs);
144+
}
145+
}
146+
126147
@Override
127148
public String getDownloadDir() {
128149
Map<String, Object> browserOptions = getBrowserOptions();
@@ -136,7 +157,10 @@ public String getDownloadDir() {
136157
}
137158

138159
private enum CapabilityType {
139-
CAPABILITIES("capabilities"), OPTIONS("options"), START_ARGS("startArguments");
160+
CAPABILITIES("capabilities"),
161+
OPTIONS("options"),
162+
START_ARGS("startArguments"),
163+
LOGGING_PREFERENCES("loggingPreferences");
140164

141165
private final String key;
142166

src/main/java/aquality/selenium/configuration/driversettings/EdgeSettings.java

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

33
import aquality.selenium.browser.BrowserName;
44
import aquality.selenium.core.utilities.ISettingsFile;
5-
import org.openqa.selenium.chrome.ChromeOptions;
65
import org.openqa.selenium.edge.EdgeOptions;
76
import org.openqa.selenium.remote.AbstractDriverOptions;
87

@@ -22,6 +21,7 @@ public AbstractDriverOptions<?> getDriverOptions() {
2221
setPrefs(edgeOptions);
2322
getBrowserStartArguments().forEach(edgeOptions::addArguments);
2423
edgeOptions.setPageLoadStrategy(getPageLoadStrategy());
24+
setLoggingPreferences(edgeOptions, EdgeOptions.LOGGING_PREFS);
2525
return edgeOptions;
2626
}
2727

src/main/java/aquality/selenium/elements/actions/JsActions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public boolean isElementOnScreen() {
140140
*/
141141
public String getElementText() {
142142
logElementAction("loc.get.text.js");
143-
return (String) executeScript(JavaScript.GET_ELEMENT_TEXT);
143+
String value = (String) executeScript(JavaScript.GET_ELEMENT_TEXT);
144+
logElementAction("loc.text.value", value);
145+
return value;
144146
}
145147

146148
/**

src/main/java/aquality/selenium/elements/actions/MouseActions.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package aquality.selenium.elements.actions;
22

33
import aquality.selenium.browser.AqualityServices;
4-
import aquality.selenium.browser.Browser;
54
import aquality.selenium.core.utilities.IElementActionRetrier;
65
import aquality.selenium.elements.interfaces.IElement;
76
import org.openqa.selenium.interactions.Actions;
@@ -51,8 +50,10 @@ public void moveMouseToElement() {
5150
*/
5251
public void moveMouseFromElement() {
5352
infoLoc("loc.movingFrom");
54-
performAction(actions -> actions.moveToElement(element.getElement(),
55-
-element.getElement().getSize().width / 2, -element.getElement().getSize().height / 2));
53+
AqualityServices.get(IElementActionRetrier.class).doWithRetry(() ->
54+
new Actions(getBrowser().getDriver())
55+
.moveToElement(element.getElement(), -element.getElement().getSize().width, -element.getElement().getSize().height)
56+
.build().perform());
5657
}
5758

5859
/**

0 commit comments

Comments
 (0)