Skip to content

Commit 7e541ed

Browse files
committed
[grid] Adding tests for flag to disable CDP if needed.
1 parent c50df52 commit 7e541ed

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@
1717

1818
package org.openqa.selenium.grid.node.config;
1919

20-
import static java.util.Collections.emptyMap;
21-
import static java.util.Collections.emptySet;
22-
import static java.util.Collections.singletonMap;
23-
import static org.assertj.core.api.Assertions.assertThat;
24-
import static org.junit.Assert.fail;
25-
import static org.junit.Assume.assumeFalse;
26-
import static org.junit.Assume.assumeTrue;
27-
2820
import com.google.common.collect.ImmutableMap;
2921

3022
import org.assertj.core.api.Condition;
@@ -58,6 +50,14 @@
5850
import java.util.Map;
5951
import java.util.Optional;
6052

53+
import static java.util.Collections.emptyMap;
54+
import static java.util.Collections.emptySet;
55+
import static java.util.Collections.singletonMap;
56+
import static org.assertj.core.api.Assertions.assertThat;
57+
import static org.junit.Assert.fail;
58+
import static org.junit.Assume.assumeFalse;
59+
import static org.junit.Assume.assumeTrue;
60+
6161
@SuppressWarnings("DuplicatedCode")
6262
public class NodeOptionsTest {
6363

@@ -107,6 +107,12 @@ public void shouldDetectCorrectDriversOnWindows() {
107107
assertThat(reported).isNot(supporting("safari"));
108108
}
109109

110+
@Test
111+
public void cdpCanBeDisabled() {
112+
Config config = new MapConfig(singletonMap("node", singletonMap("enable-cdp", "false")));
113+
NodeOptions nodeOptions = new NodeOptions(config);
114+
assertThat(nodeOptions.isCdpEnabled()).isFalse();
115+
}
110116

111117
@Test
112118
public void shouldDetectCorrectDriversOnMac() {

java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,32 @@ public void nodeDrainsAfterSessionCountIsReached() throws URISyntaxException {
274274

275275
assertThat(localNode.isDraining()).isTrue();
276276
}
277+
278+
@Test
279+
public void cdpIsDisabledAndResponseCapsShowThat() throws URISyntaxException {
280+
Tracer tracer = DefaultTestTracer.createTracer();
281+
EventBus bus = new GuavaEventBus();
282+
URI uri = new URI("http://localhost:7890");
283+
Capabilities stereotype = new ImmutableCapabilities("browserName", "cheese");
284+
285+
LocalNode.Builder builder = LocalNode.builder(tracer, bus, uri, uri, registrationSecret)
286+
.enableCdp(false)
287+
.add(stereotype,
288+
new TestSessionFactory((id, caps)
289+
-> new Session(id, uri, stereotype, caps, Instant.now())));
290+
LocalNode localNode = builder.build();
291+
292+
Either<WebDriverException, CreateSessionResponse> response = localNode.newSession(
293+
new CreateSessionRequest(
294+
ImmutableSet.of(W3C),
295+
stereotype,
296+
ImmutableMap.of()));
297+
assertThat(response.isRight()).isTrue();
298+
299+
CreateSessionResponse sessionResponse = response.right();
300+
Capabilities capabilities = sessionResponse.getSession().getCapabilities();
301+
Object cdpEnabled = capabilities.getCapability("se:cdpEnabled");
302+
assertThat(cdpEnabled).isNotNull();
303+
assertThat(Boolean.parseBoolean(cdpEnabled.toString())).isFalse();
304+
}
277305
}

0 commit comments

Comments
 (0)