Skip to content

Commit

Permalink
[java] Removing deprecated ENABLE_PROFILING_CAPABILITY cap
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Dec 7, 2022
1 parent 7b212ee commit 63a79bd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 107 deletions.
7 changes: 0 additions & 7 deletions java/src/org/openqa/selenium/remote/CapabilityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ public interface CapabilityType {
@Deprecated
String LOGGING_PREFS = "loggingPrefs";

/**
* @deprecated Non W3C compliant
*/
@Deprecated
String ENABLE_PROFILING_CAPABILITY = "webdriver.logging.profiler.enabled";


String BROWSER_NAME = "browserName";
String PLATFORM_NAME = "platformName";
String BROWSER_VERSION = "browserVersion";
Expand Down
5 changes: 0 additions & 5 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ private Capabilities init(Capabilities capabilities) {

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

boolean isProfilingEnabled = capabilities.is(CapabilityType.ENABLE_PROFILING_CAPABILITY);
if (isProfilingEnabled) {
builder.add(LogType.PROFILER);
}

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

Expand Down
28 changes: 7 additions & 21 deletions java/test/org/openqa/selenium/logging/AvailableLogsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@

package org.openqa.selenium.logging;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.openqa.selenium.remote.CapabilityType.ENABLE_PROFILING_CAPABILITY;
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.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
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)
@Ignore(FIREFOX)
Expand Down Expand Up @@ -91,16 +87,6 @@ void profilerLogShouldBeDisabledByDefault() {
.describedAs("Profiler logs should not be enabled by default").isFalse();
}

@Test
@Ignore(value = SAFARI, reason = "Safari does not support profiler logs")
public void shouldBeAbleToEnableProfilerLog() {
Capabilities caps = new ImmutableCapabilities(ENABLE_PROFILING_CAPABILITY, true);
localDriver = new WebDriverBuilder().get(caps);
Set<String> logTypes = localDriver.manage().logs().getAvailableLogTypes();
assertThat(logTypes.contains(LogType.PROFILER))
.describedAs("Profiler log should be enabled").isTrue();
}

@Test
void serverLogShouldBeEnabledByDefaultOnRemote() {
assumeTrue(Boolean.getBoolean("selenium.browser.remote"));
Expand Down
79 changes: 5 additions & 74 deletions java/test/org/openqa/selenium/logging/PerformanceLoggingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,17 @@

package org.openqa.selenium.logging;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.remote.CapabilityType.ENABLE_PROFILING_CAPABILITY;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
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.ImmutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.logging.profiler.EventType;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
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 @@ -64,65 +53,7 @@ void testDisabledProfilingDoesNotLog() {
.isEmpty();
}

@Test
void testLogsSingleHttpCommand() {
startLoggingDriver();
List<LogEntry> entries = getProfilerEntriesOfType(getProfilerEntries(loggingDriver),
EventType.HTTP_COMMAND);
// Expect start of newSession, end of newSession, start of getLogs, end of getLogs
String[] expected = {"\"command\": \"newSession\",\"startorend\": \"start\"",
"\"command\": \"newSession\",\"startorend\": \"end\"",
"\"command\": \"getLog\",\"startorend\": \"start\"",
"\"command\": \"getLog\",\"startorend\": \"end\""};
assertThat(containsExpectedEntries(entries, expected)).isTrue();
}

/**
* Checks if the given list of strings occur in the given order among the
* given log messages (one string per message).
*
* @param entries The list of log entries.
* @param expected The array of expected strings.
* @return true if a match was found for all expected strings, otherwise false.
*/
private boolean containsExpectedEntries(List<LogEntry> entries, String[] expected) {
int index = 0;
for (LogEntry entry : entries) {
if (index == expected.length) {
return true;
}
if (!entry.getMessage().contains(expected[index])) {
index++;
}
}
return (index == expected.length);
}

@Test
@Ignore(CHROME)
@Ignore(EDGE)
public void testGetsYieldToPageLoadLogEntries() {
startLoggingDriver();
loggingDriver.get(pages.formPage);
loggingDriver.findElement(By.id("submitButton")).click();
assertThat(
getProfilerEntriesOfType(getProfilerEntries(loggingDriver), EventType.YIELD_TO_PAGE_LOAD).size())
.isPositive();
}

private void startLoggingDriver() {
if (loggingDriver == null) {
loggingDriver = new WebDriverBuilder()
.get(new ImmutableCapabilities(ENABLE_PROFILING_CAPABILITY, true));
}
}

private LogEntries getProfilerEntries(WebDriver driver) {
return driver.manage().logs().get(LogType.PROFILER);
}

private List<LogEntry> getProfilerEntriesOfType(LogEntries entries, EventType eventType) {
return StreamSupport.stream(entries.spliterator(), false).filter(
entry -> entry.getMessage().contains(eventType.toString())).collect(Collectors.toList());
}
}

0 comments on commit 63a79bd

Please sign in to comment.