Skip to content

Commit 47b9825

Browse files
committed
Support logging preferences from settings.json
+ update package versions (selenium to v4.7.2)
1 parent 7dbfca5 commit 47b9825

File tree

17 files changed

+71
-20
lines changed

17 files changed

+71
-20
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/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/resources/localization/be.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"loc.browser.forward": "Пераходзім да наступнай старонкі",
55
"loc.browser.capabilities": "Атрымалі capabilities браўзэра з settings файла: %s",
66
"loc.browser.options": "Атрымалі опцыі профіля браўзэра з settings файла: %s",
7+
"loc.browser.loggingPreferences": "Атрымалі налады лагавання браўзэра з settings файла: %s",
78
"loc.browser.driver.quit": "Закрываем браўзэр",
89
"loc.browser.getUrl": "Атрымліваем адрас бягучай старонкі",
910
"loc.browser.url.value": "Адрас бягучай старонкі: [%s]",

src/main/resources/localization/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"loc.browser.forward": "Proceed to the next page",
55
"loc.browser.capabilities": "Got browser capabilities from settings file: %s",
66
"loc.browser.options": "Got browser profile options from settings file: %s",
7+
"loc.browser.loggingPreferences": "Got browser logging preferences from settings file: %s",
78
"loc.browser.driver.quit": "Closing browser",
89
"loc.browser.getUrl": "Getting current url",
910
"loc.browser.url.value": "Current url: [%s]",

src/main/resources/localization/pl.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"loc.browser.forward": "Przejście do następnej strony",
55
"loc.browser.capabilities": "Pobrano możliwości przeglądarki z pliku ustawień: %s",
66
"loc.browser.options": "Pobrano opcje profilu przeglądarki z pliku ustawień: %s",
7+
"loc.browser.loggingPreferences": "Pobrano ustawienia logowania przeglądarki z pliku ustawień: %s",
78
"loc.browser.driver.quit": "Zamykanie przeglądarki",
89
"loc.browser.getUrl": "Pobieranie aktualnego adresu URL",
910
"loc.browser.url.value": "Aktualny adres URL: [%s]",
@@ -45,7 +46,7 @@
4546
"loc.combobox.impossible.to.select.contain.value.or.text": "Wybieranie wartości ze znaczeniem/tekstem '%1$s' w polu kombi '%2$s' nie jest możliwe",
4647
"loc.el.getattr": "Pobieranie atrybutu '%1$s'",
4748
"loc.el.attr.value": "Wartość atrybutu '%1$s': [%2$s]",
48-
"loc.el.attr.set": "Ustawienie wartości atrybutu '%1$s': [%2$s]",
49+
"loc.el.attr.set": "Ustawianie wartości atrybutu '%1$s': [%2$s]",
4950
"loc.el.cssvalue": "Pobieranie wartości css '%1$s'",
5051
"loc.el.execute.pinnedjs": "Wykonywanie przypiętego JavaScript",
5152
"loc.el.execute.pinnedjs.result": "Wynik wykonania przypiętego JavaScript: [%1$s]",

0 commit comments

Comments
 (0)