Skip to content

Commit

Permalink
[java] Fixing preconditions that check chrome version
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Jul 19, 2019
1 parent ccd7460 commit 14a4bb2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.openqa.selenium.remote.CapabilityType.ENABLE_PROFILING_CAPABILITY;
import static org.openqa.selenium.testing.TestUtilities.getChromeVersion;
import static org.openqa.selenium.testing.TestUtilities.isChrome;
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.MARIONETTE;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
import static org.openqa.selenium.testing.TestUtilities.isOldChromedriver;

import org.junit.After;
import org.junit.Test;
Expand Down Expand Up @@ -58,15 +59,15 @@ public void quitDriver() {

@Test
public void browserLogShouldBeEnabledByDefault() {
assumeFalse(isOldChromedriver(driver));
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
Set<String> logTypes = driver.manage().logs().getAvailableLogTypes();
assertThat(logTypes.contains(LogType.BROWSER))
.describedAs("Browser logs should be enabled by default").isTrue();
}

@Test
public void clientLogShouldBeEnabledByDefault() {
assumeFalse(isOldChromedriver(driver));
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
// Do one action to have *something* in the client logs.
driver.get(pages.formPage);
Set<String> logTypes = driver.manage().logs().getAvailableLogTypes();
Expand All @@ -85,15 +86,15 @@ public void clientLogShouldBeEnabledByDefault() {

@Test
public void driverLogShouldBeEnabledByDefault() {
assumeFalse(isOldChromedriver(driver));
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
Set<String> logTypes = driver.manage().logs().getAvailableLogTypes();
assertThat(logTypes.contains(LogType.DRIVER))
.describedAs("Remote driver logs should be enabled by default").isTrue();
}

@Test
public void profilerLogShouldBeDisabledByDefault() {
assumeFalse(isOldChromedriver(driver));
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
Set<String> logTypes = driver.manage().logs().getAvailableLogTypes();
assertThat(logTypes.contains(LogType.PROFILER))
.describedAs("Profiler logs should not be enabled by default").isFalse();
Expand All @@ -102,7 +103,7 @@ public void profilerLogShouldBeDisabledByDefault() {
@Test
@Ignore(value = SAFARI, reason = "Safari does not support profiler logs")
public void shouldBeAbleToEnableProfilerLog() {
assumeFalse(isOldChromedriver(driver));
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
Capabilities caps = new ImmutableCapabilities(ENABLE_PROFILING_CAPABILITY, true);
localDriver = new WebDriverBuilder().get(caps);
Set<String> logTypes = localDriver.manage().logs().getAvailableLogTypes();
Expand Down
11 changes: 6 additions & 5 deletions java/client/test/org/openqa/selenium/logging/GetLogsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package org.openqa.selenium.logging;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.openqa.selenium.testing.TestUtilities.getChromeVersion;
import static org.openqa.selenium.testing.TestUtilities.isChrome;
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;
Expand All @@ -35,7 +37,6 @@
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.NeedsLocalEnvironment;
import org.openqa.selenium.testing.TestUtilities;
import org.openqa.selenium.testing.drivers.WebDriverBuilder;

import java.util.HashMap;
Expand All @@ -62,7 +63,7 @@ public void quitDriver() {

@Test
public void logBufferShouldBeResetAfterEachGetLogCall() {
assumeFalse(TestUtilities.isOldChromedriver(driver)); // Only chromedriver2 supports logging.
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
driver.get(pages.errorsPage);
driver.findElement(By.cssSelector("input")).click();

Expand All @@ -80,7 +81,7 @@ public void logBufferShouldBeResetAfterEachGetLogCall() {

@Test
public void differentLogsShouldNotContainTheSameLogEntries() {
assumeFalse(TestUtilities.isOldChromedriver(driver)); // Only chromedriver2 supports logging.
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
driver.get(pages.errorsPage);
driver.findElement(By.cssSelector("input")).click();

Expand Down Expand Up @@ -123,7 +124,7 @@ private static boolean hasOverlappingLogEntries(LogEntries firstLog, LogEntries
@Test
@NeedsLocalEnvironment
public void turningOffLogShouldMeanNoLogMessages() {
assumeFalse(TestUtilities.isOldChromedriver(driver)); // Only chromedriver2 supports logging.
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
Set<String> logTypes = driver.manage().logs().getAvailableLogTypes();
for (String logType : logTypes) {
createWebDriverWithLogging(logType, Level.OFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
package org.openqa.selenium.logging;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.openqa.selenium.testing.TestUtilities.getChromeVersion;
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.MARIONETTE;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
import static org.openqa.selenium.testing.TestUtilities.isChrome;
import static org.openqa.selenium.testing.TestUtilities.isOldChromedriver;

import org.junit.After;
import org.junit.Test;
Expand Down Expand Up @@ -60,7 +59,7 @@ public void quitDriver() {

@Test
public void performanceLogShouldBeDisabledByDefault() {
assumeFalse(isOldChromedriver(driver));
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
Set<String> logTypes = driver.manage().logs().getAvailableLogTypes();
assertThat(logTypes.contains(LogType.PERFORMANCE))
.describedAs("Performance log should not be enabled by default").isFalse();
Expand All @@ -75,7 +74,7 @@ void createLocalDriverWithPerformanceLogType() {

@Test
public void shouldBeAbleToEnablePerformanceLog() {
assumeTrue(isChrome(driver) && !isOldChromedriver(driver)); // Only in the new chromedriver.
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
createLocalDriverWithPerformanceLogType();
Set<String> logTypes = localDriver.manage().logs().getAvailableLogTypes();
assertThat(logTypes.contains(LogType.PERFORMANCE))
Expand All @@ -84,7 +83,7 @@ public void shouldBeAbleToEnablePerformanceLog() {

@Test
public void pageLoadShouldProducePerformanceLogEntries() {
assumeTrue(isChrome(driver) && !isOldChromedriver(driver)); // Only in the new chromedriver.
assumeTrue(!isChrome(driver) || getChromeVersion(driver) > 20);
createLocalDriverWithPerformanceLogType();
localDriver.get(pages.simpleTestPage);
LogEntries entries = localDriver.manage().logs().get(LogType.PERFORMANCE);
Expand Down
11 changes: 6 additions & 5 deletions java/client/test/org/openqa/selenium/testing/TestUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public static boolean isChrome(WebDriver driver) {
return !(driver instanceof HtmlUnitDriver) && getUserAgent(driver).contains("Chrome");
}

public static boolean isOldChromedriver(WebDriver driver) {
public static int getChromeVersion(WebDriver driver) {
if (!(driver instanceof HasCapabilities)) {
// Driver does not support capabilities -- not a chromedriver at all.
return false;
return 0;
}
Capabilities caps = ((HasCapabilities) driver).getCapabilities();
String chromedriverVersion = (String) caps.getCapability("chrome.chromedriverVersion");
Expand All @@ -111,14 +111,15 @@ public static boolean isOldChromedriver(WebDriver driver) {
String[] versionMajorMinor = chromedriverVersion.split("\\.", 2);
if (versionMajorMinor.length > 1) {
try {
return 20 < Long.parseLong(versionMajorMinor[0]);
return Integer.parseInt(versionMajorMinor[0]);
} catch (NumberFormatException e) {
// First component of the version is not a number -- not a chromedriver.
return false;
return 0;
}
}
}
return false;
return 0;

}

/**
Expand Down

0 comments on commit 14a4bb2

Please sign in to comment.