Skip to content

Commit

Permalink
[java] Removing usage of deprecated caps in DesiredCapabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed May 30, 2022
1 parent 67dba3e commit 8e7983f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
12 changes: 6 additions & 6 deletions java/src/org/openqa/selenium/remote/DesiredCapabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@

import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
import static org.openqa.selenium.remote.CapabilityType.PLATFORM;
import static org.openqa.selenium.remote.CapabilityType.BROWSER_VERSION;
import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME;
import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_JAVASCRIPT;
import static org.openqa.selenium.remote.CapabilityType.VERSION;

public class DesiredCapabilities extends MutableCapabilities {

public DesiredCapabilities(String browser, String version, Platform platform) {
setCapability(BROWSER_NAME, browser);
setCapability(VERSION, version);
setCapability(PLATFORM, platform);

This comment has been minimized.

Copy link
@Mahoney

Mahoney Dec 28, 2022

Contributor

Does selenium not do semantic versioning? This is a breaking change in a bugfix release. Just spent two hours trying to work out why on earth going from 4.2.0 to 4.2.1 breaks our tests.

This comment has been minimized.

Copy link
@titusfortner

titusfortner Dec 28, 2022

Member

No, Selenium does not do Semantic versioning. These capabilities have been deprecated for years at this point, and have been throwing explicit warnings for the past 6 months. Update all capabilities to w3c compliant ones: https://www.selenium.dev/blog/2022/legacy-protocol-support/

setCapability(BROWSER_VERSION, version);
setCapability(PLATFORM_NAME, platform);
}

public DesiredCapabilities() {
Expand Down Expand Up @@ -64,11 +64,11 @@ public void setBrowserName(String browserName) {
}

public void setVersion(String version) {
setCapability(VERSION, version);
setCapability(BROWSER_VERSION, version);
}

public void setPlatform(Platform platform) {
setCapability(PLATFORM, platform);
setCapability(PLATFORM_NAME, platform);
}

/**
Expand Down
50 changes: 28 additions & 22 deletions java/test/org/openqa/selenium/json/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openqa.selenium.Capabilities;
Expand Down Expand Up @@ -129,14 +130,6 @@ public void shouldUseBeanSettersToPopulateFields() {
assertThat(seen.theName).isEqualTo("fishy");
}

public static class BeanWithSetter {
String theName;

public void setName(String name) {
theName = name;
}
}

@Test
public void shouldAllowUserToPopulateFieldsDirectly() {
Map<String, String> map = ImmutableMap.of("theName", "fishy");
Expand All @@ -159,14 +152,6 @@ public void settingFinalFieldsShouldWork() {
assertThat(seen.theName).isEqualTo("fishy");
}

public static class BeanWithFinalField {
private final String theName;

public BeanWithFinalField() {
this.theName = "magic";
}
}

@Test
public void canConstructASimpleString() {
String text = new Json().toType("\"cheese\"", String.class);
Expand Down Expand Up @@ -257,14 +242,16 @@ public void shouldPopulateFieldsOnNestedBeans() {

@Test
public void shouldProperlyFillInACapabilitiesObject() {
DesiredCapabilities capabilities =
new DesiredCapabilities("browser", CapabilityType.VERSION, Platform.ANY);
capabilities.setJavascriptEnabled(true);
DesiredCapabilities capabilities = new DesiredCapabilities(CapabilityType.BROWSER_NAME,
CapabilityType.BROWSER_VERSION,
Platform.ANY);
String text = new Json().toJson(capabilities);

Capabilities readCapabilities = new Json().toType(text, DesiredCapabilities.class);

assertThat(readCapabilities).isEqualTo(capabilities);
assertThat(readCapabilities.getBrowserName()).isEqualTo(capabilities.getBrowserName());
assertThat(readCapabilities.getBrowserVersion()).isEqualTo(capabilities.getBrowserVersion());
assertThat(readCapabilities.getPlatformName()).isEqualTo(capabilities.getPlatformName());
}

@Test
Expand Down Expand Up @@ -536,14 +523,33 @@ public void canCoerceSimpleValuesToStrings() {
Json json = new Json();
String raw = json.toJson(value);
Map<String, String> roundTripped = json.toType(
raw,
new TypeToken<Map<String, String>>(){}.getType());
raw,
new TypeToken<Map<String, String>>() {
}.getType());

assertThat(roundTripped.get("boolean")).isEqualTo("true");
assertThat(roundTripped.get("integer")).isEqualTo("42");
assertThat(roundTripped.get("float")).isEqualTo("3.14");
}

public static class BeanWithSetter {

String theName;

public void setName(String name) {
theName = name;
}
}

public static class BeanWithFinalField {

private final String theName;

public BeanWithFinalField() {
this.theName = "magic";
}
}

public static class SimpleBean {

private String value;
Expand Down

0 comments on commit 8e7983f

Please sign in to comment.