Skip to content

Commit

Permalink
[java] Removing deprecated LOGGING_PREFS cap
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Dec 7, 2022
1 parent 5fbddf6 commit c583458
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 130 deletions.
8 changes: 0 additions & 8 deletions java/src/org/openqa/selenium/remote/CapabilityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ public interface CapabilityType {
@Deprecated
String OVERLAPPING_CHECK_DISABLED = "overlappingCheckDisabled";

/**
* @deprecated Non W3C compliant
* Use {@link org.openqa.selenium.chrome.ChromeOptions#LOGGING_PREFS} or
* Use {@link org.openqa.selenium.edge.EdgeOptions#LOGGING_PREFS}
*/
@Deprecated
String LOGGING_PREFS = "loggingPrefs";

String BROWSER_NAME = "browserName";
String PLATFORM_NAME = "platformName";
String BROWSER_VERSION = "browserVersion";
Expand Down
11 changes: 0 additions & 11 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
import org.openqa.selenium.interactions.Sequence;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.logging.LocalLogs;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingHandler;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.logging.Logs;
import org.openqa.selenium.logging.NeedsLocalLogs;
import org.openqa.selenium.print.PrintOptions;
Expand Down Expand Up @@ -93,7 +91,6 @@
import static java.util.Collections.singleton;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.logging.Level.SEVERE;
import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS;
import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_JAVASCRIPT;

Expand Down Expand Up @@ -205,14 +202,6 @@ private Capabilities init(Capabilities capabilities) {

ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>();

LoggingPreferences mergedLoggingPrefs = new LoggingPreferences();
mergedLoggingPrefs.addPreferences((LoggingPreferences) capabilities.getCapability(LOGGING_PREFS));

if (!mergedLoggingPrefs.getEnabledLogTypes().contains(LogType.CLIENT) ||
mergedLoggingPrefs.getLevel(LogType.CLIENT) != Level.OFF) {
builder.add(LogType.CLIENT);
}

Set<String> logTypesToInclude = builder.build();

LocalLogs performanceLogger = LocalLogs.getStoringLoggerInstance(logTypesToInclude);
Expand Down
32 changes: 1 addition & 31 deletions java/test/org/openqa/selenium/json/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.DesiredCapabilities;
Expand All @@ -46,20 +45,12 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static java.util.logging.Level.ALL;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.OFF;
import static java.util.logging.Level.WARNING;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.byLessThan;
import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
import static org.openqa.selenium.Proxy.ProxyType.PAC;
import static org.openqa.selenium.json.Json.MAP_TYPE;
import static org.openqa.selenium.logging.LogType.BROWSER;
import static org.openqa.selenium.logging.LogType.CLIENT;
import static org.openqa.selenium.logging.LogType.DRIVER;
import static org.openqa.selenium.logging.LogType.SERVER;

@Tag("UnitTests")
class JsonTest {
Expand Down Expand Up @@ -370,27 +361,6 @@ void shouldConvertCapabilitiesToAMapAndIncludeCustomValues() {
assertThat(converted.getCapability("furrfu")).isEqualTo("fishy");
}

@Test
void shouldParseCapabilitiesWithLoggingPreferences() {
String caps = String.format(
"{\"%s\": {" +
"\"browser\": \"WARNING\"," +
"\"client\": \"DEBUG\", " +
"\"driver\": \"ALL\", " +
"\"server\": \"OFF\"}}",
CapabilityType.LOGGING_PREFS);

Capabilities converted = new Json().toType(caps, Capabilities.class);

LoggingPreferences lp =
(LoggingPreferences) converted.getCapability(CapabilityType.LOGGING_PREFS);
assertThat(lp).isNotNull();
assertThat(lp.getLevel(BROWSER)).isEqualTo(WARNING);
assertThat(lp.getLevel(CLIENT)).isEqualTo(FINE);
assertThat(lp.getLevel(DRIVER)).isEqualTo(ALL);
assertThat(lp.getLevel(SERVER)).isEqualTo(OFF);
}

@Test
void shouldNotParseQuotedJsonObjectsAsActualJsonObjects() {
String jsonStr = "{\"inner\":\"{\\\"color\\\":\\\"green\\\",\\\"number\\\":123}\"}";
Expand Down
38 changes: 6 additions & 32 deletions java/test/org/openqa/selenium/logging/GetLogsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,22 @@

package org.openqa.selenium.logging;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.testing.drivers.Browser.HTMLUNIT;
import static org.openqa.selenium.testing.drivers.Browser.IE;
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
import static org.openqa.selenium.testing.drivers.Browser.HTMLUNIT;
import static org.openqa.selenium.testing.drivers.Browser.IE;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;

@Ignore(HTMLUNIT)
@Ignore(IE)
Expand Down Expand Up @@ -114,25 +109,4 @@ private static boolean hasOverlappingLogEntries(LogEntries firstLog, LogEntries
return false;
}

@Test
void turningOffLogShouldMeanNoLogMessages() {
Set<String> logTypes = driver.manage().logs().getAvailableLogTypes();
for (String logType : logTypes) {
createWebDriverWithLogging(logType, Level.OFF);
LogEntries entries = localDriver.manage().logs().get(logType);
assertThat(entries.getAll())
.describedAs("There should be no log entries for log type %s when logging is turned off.", logType)
.isEmpty();
quitDriver();
}
}

private void createWebDriverWithLogging(String logType, Level logLevel) {
LoggingPreferences loggingPrefs = new LoggingPreferences();
loggingPrefs.enable(logType, logLevel);
Capabilities caps = new ImmutableCapabilities(CapabilityType.LOGGING_PREFS, loggingPrefs);
localDriver = new WebDriverBuilder().get(caps);
localDriver.get(pages.errorsPage);
localDriver.findElement(By.cssSelector("input")).click();
}
}
40 changes: 6 additions & 34 deletions java/test/org/openqa/selenium/logging/PerformanceLogTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@

package org.openqa.selenium.logging;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
import static org.openqa.selenium.testing.drivers.Browser.HTMLUNIT;
import static org.openqa.selenium.testing.drivers.Browser.IE;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.util.Set;
import java.util.logging.Level;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
import static org.openqa.selenium.testing.drivers.Browser.HTMLUNIT;
import static org.openqa.selenium.testing.drivers.Browser.IE;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;

@Ignore(HTMLUNIT)
@Ignore(IE)
Expand All @@ -58,27 +53,4 @@ void performanceLogShouldBeDisabledByDefault() {
assertThat(logTypes.contains(LogType.PERFORMANCE))
.describedAs("Performance log should not be enabled by default").isFalse();
}

void createLocalDriverWithPerformanceLogType() {
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
Capabilities caps = new ImmutableCapabilities(CapabilityType.LOGGING_PREFS, logPrefs);
localDriver = new WebDriverBuilder().get(caps);
}

@Test
void shouldBeAbleToEnablePerformanceLog() {
createLocalDriverWithPerformanceLogType();
Set<String> logTypes = localDriver.manage().logs().getAvailableLogTypes();
assertThat(logTypes.contains(LogType.PERFORMANCE))
.describedAs("Profiler log should be enabled").isTrue();
}

@Test
void pageLoadShouldProducePerformanceLogEntries() {
createLocalDriverWithPerformanceLogType();
localDriver.get(pages.simpleTestPage);
LogEntries entries = localDriver.manage().logs().get(LogType.PERFORMANCE);
assertThat(entries).isNotEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@

import com.google.common.collect.ImmutableMap;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.logging.LoggingPreferences;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -80,17 +78,6 @@ void testCopyConstructorDoesNotAliasToArgument() {
assertThat(newCapabilities.getCapability("BrowserName")).isEqualTo("firefox");
}

@Test
void testExtractDebugLogLevelFromCapabilityMap() {
Map<String, Object> capabilitiesMap
= ImmutableMap.of(CapabilityType.LOGGING_PREFS, ImmutableMap.of("browser", "DEBUG"));

DesiredCapabilities caps = new DesiredCapabilities(capabilitiesMap);
LoggingPreferences prefs =
(LoggingPreferences) caps.getCapability(CapabilityType.LOGGING_PREFS);
assertThat(prefs.getLevel("browser")).isSameAs(Level.FINE);
}

@Test
void shouldAutomaticallyConvertPlatformFromStringToEnum() {
DesiredCapabilities caps = new DesiredCapabilities();
Expand Down

0 comments on commit c583458

Please sign in to comment.