Skip to content

Commit

Permalink
[grid] Displaying the real stereotype config at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Apr 28, 2023
1 parent 79c7847 commit 0c02532
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/grid/node/SessionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public interface SessionFactory extends
Function<CreateSessionRequest, Either<WebDriverException, ActiveSession>>,
Predicate<Capabilities> {

Capabilities getStereotype();
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public DriverServiceSessionFactory(
this.sessionCapabilitiesMutator = new SessionCapabilitiesMutator(this.stereotype);
}

@Override
public Capabilities getStereotype() {
return stereotype;
}

@Override
public boolean test(Capabilities capabilities) {
return predicate.test(capabilities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,12 @@ private void report(Map.Entry<WebDriverInfo, Collection<SessionFactory>> entry)
StringBuilder caps = new StringBuilder();
try (JsonOutput out = JSON.newOutput(caps)) {
out.setPrettyPrint(false);
out.write(entry.getKey().getCanonicalCapabilities());
Optional<SessionFactory> optionalSessionFactory = entry.getValue().stream().findFirst();
if (optionalSessionFactory.isPresent()) {
out.write(optionalSessionFactory.get().getStereotype());
} else {
out.write(entry.getKey().getCanonicalCapabilities());
}
}

LOG.info(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public DockerSessionFactory(
this.slotMatcher = new DefaultSlotMatcher();
}

@Override
public Capabilities getStereotype() {
return stereotype;
}

@Override
public boolean test(Capabilities capabilities) {
return slotMatcher.matches(stereotype, capabilities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public RelaySessionFactory(
.copyOf(Require.nonNull("Stereotype", stereotype));
}

@Override
public Capabilities getStereotype() {
return stereotype;
}

@Override
public boolean test(Capabilities capabilities) {
// If a request reaches this point is because the basic match of W3C caps has already been done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ void shouldBeAbleToGetUrlsOfAllNodes() throws URISyntaxException {
String nodeUri = "http://localhost:5556";
Node node = LocalNode.builder(tracer, bus, new URI(nodeUri), publicUri, registrationSecret)
.add(stereotype, new SessionFactory() {
@Override
public Capabilities getStereotype() {
return null;
}

@Override
public Either<WebDriverException, ActiveSession> apply(
CreateSessionRequest createSessionRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@ public static class HelperFactory {

public static SessionFactory create(Config config, Capabilities caps) {
return new SessionFactory() {
@Override
public Capabilities getStereotype() {
return null;
}

@Override
public Either<WebDriverException, ActiveSession> apply(
CreateSessionRequest createSessionRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public TestSessionFactory(Capabilities stereotype, BiFunction<SessionId, Capabil
this.sessionGenerator = sessionGenerator;
}

@Override
public Capabilities getStereotype() {
return stereotype;
}

@Override
public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sessionRequest) {
SessionId id = new SessionId(UUID.randomUUID());
Expand Down

0 comments on commit 0c02532

Please sign in to comment.