Skip to content

Commit

Permalink
[grid] Choosing the driver builder with highest score
Browse files Browse the repository at this point in the history
Previously we were using all builders that had a score
higher than zero for each set of stereotypes. But this
can lead to erroneous behaviour because two different
builders should not serve the same stereotypes, it will
be misleading for the user.

With this, we only use the builder that has the highest
score. The current behaviour is not affected, and this
paves the way to have insert a DriverService for
Safari Tech Preview.
  • Loading branch information
diemol committed Sep 27, 2021
1 parent ba05dd9 commit 0dcffa2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ private void addDriverConfigs(

builders.stream()
.filter(builder -> builder.score(stereotype) > 0)
.forEach(builder -> {
.max(Comparator.comparingInt(builder -> builder.score(stereotype)))
.ifPresent(builder -> {
int maxDriverSessions = getDriverMaxSessions(info, driverMaxSessions);
for (int i = 0; i < maxDriverSessions; i++) {
driverConfigs.putAll(driverInfoConfig, factoryFactory.apply(stereotype));
Expand Down Expand Up @@ -445,7 +446,8 @@ private Map<WebDriverInfo, Collection<SessionFactory>> discoverDrivers(
Capabilities caps = enhanceStereotype(info.getCanonicalCapabilities());
builders.stream()
.filter(builder -> builder.score(caps) > 0)
.forEach(builder -> {
.max(Comparator.comparingInt(builder -> builder.score(caps)))
.ifPresent(builder -> {
int maxDriverSessions = getDriverMaxSessions(info, maxSessions);
for (int i = 0; i < maxDriverSessions; i++) {
toReturn.putAll(info, factoryFactory.apply(caps));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.ServiceLoader;

Expand Down Expand Up @@ -100,7 +101,8 @@ private static Collection<SessionFactory> createSessionFactory(

builders.stream()
.filter(builder -> builder.score(stereotype) > 0)
.forEach(builder -> {
.max(Comparator.comparingInt(builder -> builder.score(stereotype)))
.ifPresent(builder -> {
DriverService.Builder<?, ?> driverServiceBuilder;
Class<?> clazz = builder.getClass();
try {
Expand Down

0 comments on commit 0dcffa2

Please sign in to comment.