How to use MapConfig class of org.openqa.selenium.grid.config package

Best Selenium code snippet using org.openqa.selenium.grid.config.MapConfig

Source:DeploymentTypes.java Github

copy

Full Screen

...22import org.openqa.selenium.grid.commands.Hub;23import org.openqa.selenium.grid.commands.Standalone;24import org.openqa.selenium.grid.config.CompoundConfig;25import org.openqa.selenium.grid.config.Config;26import org.openqa.selenium.grid.config.MapConfig;27import org.openqa.selenium.grid.config.MemoizedConfig;28import org.openqa.selenium.grid.config.TomlConfig;29import org.openqa.selenium.grid.distributor.httpd.DistributorServer;30import org.openqa.selenium.grid.node.httpd.NodeServer;31import org.openqa.selenium.grid.router.httpd.RouterServer;32import org.openqa.selenium.grid.server.Server;33import org.openqa.selenium.grid.sessionmap.httpd.SessionMapServer;34import org.openqa.selenium.grid.sessionqueue.httpd.NewSessionQueueServer;35import org.openqa.selenium.grid.web.Values;36import org.openqa.selenium.json.Json;37import org.openqa.selenium.json.JsonOutput;38import org.openqa.selenium.net.PortProber;39import org.openqa.selenium.remote.http.HttpClient;40import org.openqa.selenium.remote.http.HttpRequest;41import org.openqa.selenium.remote.http.HttpResponse;42import org.openqa.selenium.support.ui.FluentWait;43import org.openqa.selenium.testing.Safely;44import org.openqa.selenium.testing.TearDownFixture;45import java.io.IOException;46import java.io.StringReader;47import java.io.UncheckedIOException;48import java.net.ConnectException;49import java.time.Duration;50import java.util.Arrays;51import java.util.List;52import java.util.Map;53public enum DeploymentTypes {54 STANDALONE {55 @Override56 public Deployment start(Capabilities capabilities, Config additionalConfig) {57 StringBuilder rawCaps = new StringBuilder();58 try (JsonOutput out = new Json().newOutput(rawCaps)) {59 out.setPrettyPrint(false).write(capabilities);60 }61 String[] rawConfig = new String[]{62 "[network]",63 "relax-checks = true",64 "",65 "[server]",66 "registration-secret = \"provolone\"",67 "",68 "[sessionqueue]",69 "session-request-timeout = 100",70 "session-retry-interval = 1"71 };72 Config config = new MemoizedConfig(73 new CompoundConfig(74 additionalConfig,75 new TomlConfig(new StringReader(String.join("\n", rawConfig)))));76 Server<?> server = new Standalone().asServer(new CompoundConfig(setRandomPort(), config)).start();77 waitUntilReady(server, Duration.ofSeconds(5));78 return new Deployment(server, server::stop);79 }80 },81 HUB_AND_NODE {82 @Override83 public Deployment start(Capabilities capabilities, Config additionalConfig) {84 StringBuilder rawCaps = new StringBuilder();85 try (JsonOutput out = new Json().newOutput(rawCaps)) {86 out.setPrettyPrint(false).write(capabilities);87 }88 int publish = PortProber.findFreePort();89 int subscribe = PortProber.findFreePort();90 String[] rawConfig = new String[] {91 "[events]",92 "publish = \"tcp://localhost:" + publish + "\"",93 "subscribe = \"tcp://localhost:" + subscribe + "\"",94 "",95 "[network]",96 "relax-checks = true",97 "",98 "[server]",99 "registration-secret = \"feta\"",100 "",101 "[sessionqueue]",102 "session-request-timeout = 100",103 "session-retry-interval = 1"104 };105 Config baseConfig = new MemoizedConfig(106 new CompoundConfig(107 additionalConfig,108 new TomlConfig(new StringReader(String.join("\n", rawConfig)))));109 Config hubConfig = new MemoizedConfig(110 new CompoundConfig(111 setRandomPort(),112 new MapConfig(Map.of("events", Map.of("bind", true))),113 baseConfig));114 Server<?> hub = new Hub().asServer(hubConfig).start();115 MapConfig additionalNodeConfig = new MapConfig(Map.of("node", Map.of("hub", hub.getUrl())));116 Config nodeConfig = new MemoizedConfig(117 new CompoundConfig(118 additionalNodeConfig,119 setRandomPort(),120 baseConfig));121 Server<?> node = new NodeServer().asServer(nodeConfig).start();122 waitUntilReady(node, Duration.ofSeconds(5));123 waitUntilReady(hub, Duration.ofSeconds(5));124 return new Deployment(hub, hub::stop, node::stop);125 }126 },127 DISTRIBUTED {128 @Override129 public Deployment start(Capabilities capabilities, Config additionalConfig) {130 StringBuilder rawCaps = new StringBuilder();131 try (JsonOutput out = new Json().newOutput(rawCaps)) {132 out.setPrettyPrint(false).write(capabilities);133 }134 int publish = PortProber.findFreePort();135 int subscribe = PortProber.findFreePort();136 String[] rawConfig = new String[] {137 "[events]",138 "publish = \"tcp://localhost:" + publish + "\"",139 "subscribe = \"tcp://localhost:" + subscribe + "\"",140 "bind = false",141 "",142 "[network]",143 "relax-checks = true",144 "",145 "[server]",146 "",147 "registration-secret = \"colby\"",148 "",149 "[sessionqueue]",150 "session-request-timeout = 100",151 "session-retry-interval = 1"152 };153 Config sharedConfig = new MemoizedConfig(154 new CompoundConfig(155 additionalConfig,156 new TomlConfig(new StringReader(String.join("\n", rawConfig)))));157 Server<?> eventServer = new EventBusCommand()158 .asServer(new MemoizedConfig(new CompoundConfig(159 new TomlConfig(new StringReader(String.join("\n", new String[] {160 "[events]",161 "publish = \"tcp://localhost:" + publish + "\"",162 "subscribe = \"tcp://localhost:" + subscribe + "\"",163 "bind = true"}))),164 setRandomPort(),165 sharedConfig)))166 .start();167 waitUntilReady(eventServer, Duration.ofSeconds(5));168 Server<?> newSessionQueueServer = new NewSessionQueueServer()169 .asServer(new MemoizedConfig(new CompoundConfig(setRandomPort(), sharedConfig))).start();170 waitUntilReady(newSessionQueueServer, Duration.ofSeconds(5));171 Config newSessionQueueServerConfig = new TomlConfig(new StringReader(String.join(172 "\n",173 new String[] {174 "[sessionqueue]",175 "hostname = \"localhost\"",176 "port = " + newSessionQueueServer.getUrl().getPort()177 }178 )));179 Server<?> sessionMapServer = new SessionMapServer()180 .asServer(new MemoizedConfig(new CompoundConfig(setRandomPort(), sharedConfig))).start();181 Config sessionMapConfig = new TomlConfig(new StringReader(String.join(182 "\n",183 new String[] {184 "[sessions]",185 "hostname = \"localhost\"",186 "port = " + sessionMapServer.getUrl().getPort()187 }188 )));189 Server<?> distributorServer = new DistributorServer()190 .asServer(new MemoizedConfig(new CompoundConfig(191 setRandomPort(),192 sessionMapConfig,193 newSessionQueueServerConfig,194 sharedConfig)))195 .start();196 Config distributorConfig = new TomlConfig(new StringReader(String.join(197 "\n",198 new String[] {199 "[distributor]",200 "hostname = \"localhost\"",201 "port = " + distributorServer.getUrl().getPort()202 }203 )));204 Server<?> router = new RouterServer()205 .asServer(new MemoizedConfig(new CompoundConfig(206 setRandomPort(),207 sessionMapConfig,208 distributorConfig,209 newSessionQueueServerConfig,210 sharedConfig)))211 .start();212 MapConfig nodeConfig = new MapConfig(Map.of("node", Map.of("hub", router.getUrl())));213 Server<?> nodeServer = new NodeServer()214 .asServer(new MemoizedConfig(new CompoundConfig(215 nodeConfig,216 setRandomPort(),217 sharedConfig,218 sessionMapConfig,219 distributorConfig,220 newSessionQueueServerConfig)))221 .start();222 waitUntilReady(nodeServer, Duration.ofSeconds(5));223 waitUntilReady(router, Duration.ofSeconds(5));224 return new Deployment(225 router,226 router::stop,227 nodeServer::stop,228 distributorServer::stop,229 sessionMapServer::stop,230 newSessionQueueServer::stop,231 eventServer::stop);232 }233 };234 private static Config setRandomPort() {235 return new MapConfig(Map.of("server", Map.of("port", PortProber.findFreePort())));236 }237 private static void waitUntilReady(Server<?> server, Duration duration) {238 HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl());239 try {240 new FluentWait<>(client)241 .withTimeout(duration)242 .pollingEvery(Duration.ofMillis(250))243 .ignoring(IOException.class)244 .ignoring(UncheckedIOException.class)245 .ignoring(ConnectException.class)246 .until(247 c -> {248 HttpResponse response = c.execute(new HttpRequest(GET, "/status"));249 Map<String, Object> status = Values.get(response, MAP_TYPE);...

Full Screen

Full Screen

Source:NettyAppServer.java Github

copy

Full Screen

...17package org.openqa.selenium.environment.webserver;18import com.google.common.collect.ImmutableMap;19import org.openqa.selenium.grid.config.CompoundConfig;20import org.openqa.selenium.grid.config.Config;21import org.openqa.selenium.grid.config.MapConfig;22import org.openqa.selenium.grid.config.MemoizedConfig;23import org.openqa.selenium.grid.server.BaseServerOptions;24import org.openqa.selenium.grid.server.Server;25import org.openqa.selenium.internal.Require;26import org.openqa.selenium.io.TemporaryFilesystem;27import org.openqa.selenium.json.Json;28import org.openqa.selenium.net.PortProber;29import org.openqa.selenium.netty.server.NettyServer;30import org.openqa.selenium.remote.http.Contents;31import org.openqa.selenium.remote.http.HttpClient;32import org.openqa.selenium.remote.http.HttpHandler;33import org.openqa.selenium.remote.http.HttpMethod;34import org.openqa.selenium.remote.http.HttpRequest;35import org.openqa.selenium.remote.http.HttpResponse;36import java.io.File;37import java.io.IOException;38import java.io.UncheckedIOException;39import java.net.MalformedURLException;40import java.net.URL;41import static com.google.common.net.HttpHeaders.CONTENT_TYPE;42import static java.nio.charset.StandardCharsets.UTF_8;43import static java.util.Collections.singletonMap;44import static org.openqa.selenium.json.Json.JSON_UTF_8;45import static org.openqa.selenium.remote.http.Contents.bytes;46import static org.openqa.selenium.remote.http.Contents.string;47public class NettyAppServer implements AppServer {48 private final static Config sslConfig = new MapConfig(49 singletonMap("server", singletonMap("https-self-signed", true)));50 private final Server<?> server;51 private final Server<?> secure;52 public NettyAppServer() {53 Config config = createDefaultConfig();54 BaseServerOptions options = new BaseServerOptions(config);55 File tempDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("generated", "pages");56 HttpHandler handler = new HandlersForTests(57 options.getHostname().orElse("localhost"),58 options.getPort(),59 tempDir.toPath());60 server = new NettyServer(options, handler);61 Config secureConfig = new CompoundConfig(sslConfig, createDefaultConfig());62 BaseServerOptions secureOptions = new BaseServerOptions(secureConfig);63 HttpHandler secureHandler = new HandlersForTests(64 secureOptions.getHostname().orElse("localhost"),65 secureOptions.getPort(),66 tempDir.toPath());67 secure = new NettyServer(secureOptions, secureHandler);68 }69 public NettyAppServer(HttpHandler handler) {70 this(71 createDefaultConfig(),72 Require.nonNull("Handler", handler));73 }74 private NettyAppServer(Config config, HttpHandler handler) {75 Require.nonNull("Config", config);76 Require.nonNull("Handler", handler);77 server = new NettyServer(new BaseServerOptions(new MemoizedConfig(config)), handler);78 secure = null;79 }80 private static Config createDefaultConfig() {81 return new MemoizedConfig(new MapConfig(82 singletonMap("server", singletonMap("port", PortProber.findFreePort()))));83 }84 @Override85 public void start() {86 server.start();87 if (secure != null) {88 secure.start();89 }90 }91 @Override92 public void stop() {93 server.stop();94 if (secure != null) {95 secure.stop();96 }97 }98 @Override99 public String whereIs(String relativeUrl) {100 return createUrl(server, "http", getHostName(), relativeUrl);101 }102 @Override103 public String whereElseIs(String relativeUrl) {104 return createUrl(server, "http", getAlternateHostName(), relativeUrl);105 }106 @Override107 public String whereIsSecure(String relativeUrl) {108 if (secure == null) {109 throw new IllegalStateException("Server not configured to return HTTPS url");110 }111 return createUrl(secure, "https", getHostName(), relativeUrl);112 }113 @Override114 public String whereIsWithCredentials(String relativeUrl, String user, String password) {115 return String.format(116 "http://%s:%s@%s:%d/%s",117 user,118 password,119 getHostName(),120 server.getUrl().getPort(),121 relativeUrl);122 }123 private String createUrl(Server<?> server, String protocol, String hostName, String relativeUrl) {124 if (!relativeUrl.startsWith("/")) {125 relativeUrl = "/" + relativeUrl;126 }127 try {128 return new URL(129 protocol,130 hostName,131 server.getUrl().getPort(),132 relativeUrl133 ).toString();134 } catch (MalformedURLException e) {135 throw new UncheckedIOException(e);136 }137 }138 @Override139 public String create(Page page) {140 try (HttpClient client = HttpClient.Factory.createDefault().createClient(new URL(whereIs("/")))) {141 HttpRequest request = new HttpRequest(HttpMethod.POST, "/common/createPage");142 request.setHeader(CONTENT_TYPE, JSON_UTF_8);143 request.setContent(Contents.asJson(ImmutableMap.of("content", page.toString())));144 HttpResponse response = client.execute(request);145 return string(response);146 } catch (IOException ex) {147 throw new RuntimeException(ex);148 }149 }150 @Override151 public String getHostName() {152 return AppServer.detectHostname();153 }154 @Override155 public String getAlternateHostName() {156 return AppServer.detectAlternateHostname();157 }158 public static void main(String[] args) {159 MemoizedConfig config = new MemoizedConfig(new MapConfig(singletonMap("server", singletonMap("port", 2310))));160 BaseServerOptions options = new BaseServerOptions(config);161 HttpHandler handler = new HandlersForTests(162 options.getHostname().orElse("localhost"),163 options.getPort(),164 TemporaryFilesystem.getDefaultTmpFS().createTempDir("netty", "server").toPath());165 NettyAppServer server = new NettyAppServer(166 config,167 handler);168 server.start();169 System.out.printf("Server started. Root URL: %s%n", server.whereIs("/"));170 }171}...

Full Screen

Full Screen

Source:NettyServerTest.java Github

copy

Full Screen

...19import org.junit.Ignore;20import org.junit.Test;21import org.openqa.selenium.grid.config.CompoundConfig;22import org.openqa.selenium.grid.config.Config;23import org.openqa.selenium.grid.config.MapConfig;24import org.openqa.selenium.grid.server.BaseServerOptions;25import org.openqa.selenium.grid.server.Server;26import org.openqa.selenium.net.PortProber;27import org.openqa.selenium.remote.http.HttpClient;28import org.openqa.selenium.remote.http.HttpRequest;29import org.openqa.selenium.remote.http.HttpResponse;30import java.net.URL;31import java.util.concurrent.atomic.AtomicInteger;32import static org.assertj.core.api.Assertions.assertThat;33import static org.junit.Assert.assertEquals;34import static org.junit.Assert.assertTrue;35import static org.openqa.selenium.remote.http.Contents.utf8String;36import static org.openqa.selenium.remote.http.HttpMethod.DELETE;37import static org.openqa.selenium.remote.http.HttpMethod.GET;38public class NettyServerTest {39 /**40 * There is a bug between an OkHttp client and the Netty server where a TCP41 * RST causes the same HTTP request to be generated twice. This is clearly42 * less than desirable behaviour, so this test attempts to ensure the problem43 * does not occur. I suspect the problem is to do with OkHttp's connection44 * pool, but it seems cruel to make our users deal with this. Better to have45 * it be something the server handles.46 */47 @Test48 public void ensureMultipleCallsWorkAsExpected() {49 System.out.println("\n\n\n\nNetty!");50 AtomicInteger count = new AtomicInteger(0);51 Server<?> server = new NettyServer(52 new BaseServerOptions(53 new MapConfig(54 ImmutableMap.of("server", ImmutableMap.of("port", PortProber.findFreePort())))),55 req -> {56 count.incrementAndGet();57 return new HttpResponse().setContent(utf8String("Count is " + count.get()));58 }59 ).start();60 // TODO: avoid using netty for this61 HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl());62 HttpResponse res = client.execute(new HttpRequest(GET, "/does-not-matter"));63 outputHeaders(res);64 assertThat(count.get()).isEqualTo(1);65 client.execute(new HttpRequest(GET, "/does-not-matter"));66 outputHeaders(res);67 assertThat(count.get()).isEqualTo(2);68 }69 @Test70 public void shouldDisableAllowOrigin() {71 // TODO: Server setup72 Server<?> server = new NettyServer(73 new BaseServerOptions(74 new MapConfig(75 ImmutableMap.of("server", ImmutableMap.of("port", PortProber.findFreePort())))),76 req -> {77 return new HttpResponse().setContent(utf8String("Count is "));78 }79 ).start();80 // TODO: Client setup81 URL url = server.getUrl();82 HttpClient client = HttpClient.Factory.createDefault().createClient(url);83 HttpRequest request = new HttpRequest(DELETE, "/session");84 String exampleUrl = "http://www.example.com";85 request.setHeader("Origin", exampleUrl);86 request.setHeader("Accept", "*/*");87 HttpResponse response = client.execute(request);88 // TODO: Assertion89 assertEquals("Access-Control-Allow-Credentials should be null", null,90 response.getHeader("Access-Control-Allow-Credentials"));91 assertEquals("Access-Control-Allow-Origin should be null",92 null,93 response.getHeader("Access-Control-Allow-Origin"));94 }95 @Test96 @Ignore97 public void shouldAllowCORS() {98 // TODO: Server setup99 Config cfg = new CompoundConfig(100 new MapConfig(ImmutableMap.of("server", ImmutableMap.of("allow-cors", "true"))));101 BaseServerOptions options = new BaseServerOptions(cfg);102 assertTrue("Allow CORS should be enabled", options.getAllowCORS());103 // TODO: Server setup104 Server<?> server = new NettyServer(105 options,106 req -> new HttpResponse()107 ).start();108 // TODO: Client setup109 URL url = server.getUrl();110 HttpClient client = HttpClient.Factory.createDefault().createClient(url);111 HttpRequest request = new HttpRequest(DELETE, "/session");112 String exampleUrl = "http://www.example.com";113 request.setHeader("Origin", exampleUrl);114 request.setHeader("Accept", "*/*");...

Full Screen

Full Screen

Source:EventBusCommand.java Github

copy

Full Screen

...26import org.openqa.selenium.events.EventName;27import org.openqa.selenium.grid.TemplateGridCommand;28import org.openqa.selenium.grid.config.CompoundConfig;29import org.openqa.selenium.grid.config.Config;30import org.openqa.selenium.grid.config.MapConfig;31import org.openqa.selenium.grid.config.MemoizedConfig;32import org.openqa.selenium.grid.config.Role;33import org.openqa.selenium.grid.server.BaseServerOptions;34import org.openqa.selenium.grid.server.EventBusOptions;35import org.openqa.selenium.grid.server.Server;36import org.openqa.selenium.internal.Require;37import org.openqa.selenium.netty.server.NettyServer;38import org.openqa.selenium.remote.http.HttpResponse;39import org.openqa.selenium.remote.http.Route;40import java.util.Collections;41import java.util.Set;42import java.util.concurrent.CountDownLatch;43import java.util.concurrent.TimeUnit;44import java.util.logging.Logger;45import static java.net.HttpURLConnection.HTTP_NO_CONTENT;46import static org.openqa.selenium.grid.config.StandardGridRoles.EVENT_BUS_ROLE;47import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;48import static org.openqa.selenium.json.Json.JSON_UTF_8;49import static org.openqa.selenium.remote.http.Contents.asJson;50@AutoService(CliCommand.class)51public class EventBusCommand extends TemplateGridCommand {52 private static final Logger LOG = Logger.getLogger(EventBusCommand.class.getName());53 @Override54 public String getName() {55 return "event-bus";56 }57 @Override58 public String getDescription() {59 return "Standalone instance of the event bus.";60 }61 @Override62 public Set<Role> getConfigurableRoles() {63 return ImmutableSet.of(EVENT_BUS_ROLE, HTTPD_ROLE);64 }65 @Override66 public boolean isShown() {67 return false;68 }69 @Override70 public Set<Object> getFlagObjects() {71 return Collections.emptySet();72 }73 @Override74 protected String getSystemPropertiesConfigPrefix() {75 return "selenium";76 }77 @Override78 protected Config getDefaultConfig() {79 return new MapConfig(ImmutableMap.of(80 "events", ImmutableMap.of(81 "bind", true,82 "publish", "tcp://*:4442",83 "subscribe", "tcp://*:4443"),84 "server", ImmutableMap.of(85 "port", 5557)));86 }87 public Server<?> asServer(Config initialConfig) {88 Require.nonNull("Config", initialConfig);89 Config config = new MemoizedConfig(new CompoundConfig(initialConfig, getDefaultConfig()));90 EventBusOptions events = new EventBusOptions(config);91 EventBus bus = events.getEventBus();92 BaseServerOptions serverOptions = new BaseServerOptions(config);93 return new NettyServer(...

Full Screen

Full Screen

Source:RouterServer.java Github

copy

Full Screen

...21import org.openqa.selenium.BuildInfo;22import org.openqa.selenium.cli.CliCommand;23import org.openqa.selenium.grid.TemplateGridCommand;24import org.openqa.selenium.grid.config.Config;25import org.openqa.selenium.grid.config.MapConfig;26import org.openqa.selenium.grid.config.Role;27import org.openqa.selenium.grid.distributor.Distributor;28import org.openqa.selenium.grid.distributor.config.DistributorOptions;29import org.openqa.selenium.grid.distributor.remote.RemoteDistributor;30import org.openqa.selenium.grid.graphql.GraphqlHandler;31import org.openqa.selenium.grid.log.LoggingOptions;32import org.openqa.selenium.grid.router.ProxyCdpIntoGrid;33import org.openqa.selenium.grid.router.Router;34import org.openqa.selenium.grid.server.BaseServerOptions;35import org.openqa.selenium.grid.server.NetworkOptions;36import org.openqa.selenium.grid.server.Server;37import org.openqa.selenium.grid.sessionmap.SessionMap;38import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;39import org.openqa.selenium.netty.server.NettyServer;40import org.openqa.selenium.remote.http.HttpClient;41import org.openqa.selenium.remote.http.HttpResponse;42import org.openqa.selenium.remote.http.Route;43import org.openqa.selenium.remote.tracing.Tracer;44import java.net.URL;45import java.util.Collections;46import java.util.Set;47import java.util.logging.Logger;48import static java.net.HttpURLConnection.HTTP_NO_CONTENT;49import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;50import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;51import static org.openqa.selenium.grid.config.StandardGridRoles.ROUTER_ROLE;52import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_MAP_ROLE;53import static org.openqa.selenium.net.Urls.fromUri;54import static org.openqa.selenium.remote.http.Route.get;55@AutoService(CliCommand.class)56public class RouterServer extends TemplateGridCommand {57 private static final Logger LOG = Logger.getLogger(RouterServer.class.getName());58 @Override59 public String getName() {60 return "router";61 }62 @Override63 public String getDescription() {64 return "Creates a router to front the selenium grid.";65 }66 @Override67 public Set<Role> getConfigurableRoles() {68 return ImmutableSet.of(DISTRIBUTOR_ROLE, HTTPD_ROLE, ROUTER_ROLE, SESSION_MAP_ROLE);69 }70 @Override71 public Set<Object> getFlagObjects() {72 return Collections.emptySet();73 }74 @Override75 protected String getSystemPropertiesConfigPrefix() {76 return "router";77 }78 @Override79 protected Config getDefaultConfig() {80 return new MapConfig(ImmutableMap.of("server", ImmutableMap.of("port", 4444)));81 }82 @Override83 protected void execute(Config config) {84 LoggingOptions loggingOptions = new LoggingOptions(config);85 Tracer tracer = loggingOptions.getTracer();86 NetworkOptions networkOptions = new NetworkOptions(config);87 HttpClient.Factory clientFactory = networkOptions.getHttpClientFactory(tracer);88 SessionMapOptions sessionsOptions = new SessionMapOptions(config);89 SessionMap sessions = sessionsOptions.getSessionMap();90 BaseServerOptions serverOptions = new BaseServerOptions(config);91 DistributorOptions distributorOptions = new DistributorOptions(config);92 URL distributorUrl = fromUri(distributorOptions.getDistributorUri());93 Distributor distributor = new RemoteDistributor(94 tracer,...

Full Screen

Full Screen

Source:DefaultDistributorConfig.java Github

copy

Full Screen

...16// under the License.17package org.openqa.selenium.grid.distributor.httpd;18import com.google.common.collect.ImmutableMap;19import org.openqa.selenium.grid.config.Config;20import org.openqa.selenium.grid.config.MapConfig;21import java.util.Map;22class DefaultDistributorConfig extends MapConfig {23 DefaultDistributorConfig() {24 super(ImmutableMap.of(25 "events", ImmutableMap.of(26 "publish", "tcp://*:4442",27 "subscribe", "tcp://*:4443",28 "bind", true)));29 }30}...

Full Screen

Full Screen

MapConfig

Using AI Code Generation

copy

Full Screen

1MapConfig config = new MapConfig(Map.of("key", "value"));2String value = config.get("key");3Config config = new MapConfig(Map.of("key", "value"));4String value = config.get("key").toString();5Config config = new MapConfig(Map.of("key", "value"));6String value = config.get("key").as(String.class);7Config config = new MapConfig(Map.of("key", "value"));8String value = config.get("key").as(String.class, "default");9Config config = new MapConfig(Map.of("key", "value"));10String value = config.get("key").as(String.class, () -> "default");11Config config = new MapConfig(Map.of("key", "value"));12String value = config.get("key").as(String.class, () -> {13 throw new RuntimeException("This should not be called");14});15Config config = new MapConfig(Map.of("key", "value"));16String value = config.get("key").as(String.class, "default");17Config config = new MapConfig(Map.of("key", "value"));18String value = config.get("key").as(String.class, () -> "default");19Config config = new MapConfig(Map.of("key", "value"));20String value = config.get("key").as(String.class, () -> {21 throw new RuntimeException("This should not be called");22});23Config config = new MapConfig(Map

Full Screen

Full Screen
copy
1public final <T extends Throwable> T expectException( Class<T> exceptionClass, Runnable runnable )2{3 try4 {5 runnable.run();6 }7 catch( Throwable throwable )8 {9 if( throwable instanceof AssertionError && throwable.getCause() != null )10 throwable = throwable.getCause(); //allows testing for "assert x != null : new IllegalArgumentException();"11 assert exceptionClass.isInstance( throwable ) : throwable; //exception of the wrong kind was thrown.12 assert throwable.getClass() == exceptionClass : throwable; //exception thrown was a subclass, but not the exact class, expected.13 @SuppressWarnings( "unchecked" )14 T result = (T)throwable;15 return result;16 }17 assert false; //expected exception was not thrown.18 return null; //to keep the compiler happy.19}20
Full Screen
copy
1@Test2public void testThrowsExceptionWhenWrongSku() {34 // Given5 String articleSimpleSku = "999-999";6 int amountOfTransactions = 1;7 Exception exception = null;89 // When10 try {11 createNInboundTransactionsForSku(amountOfTransactions, articleSimpleSku);12 } catch (RuntimeException e) {13 exception = e;14 }1516 // Then17 shouldValidateThrowsExceptionWithMessage(exception, MESSAGE_NON_EXISTENT_SKU);18}1920private void shouldValidateThrowsExceptionWithMessage(final Exception e, final String message) {21 assertNotNull(e);22 assertTrue(e.getMessage().contains(message));23}24
Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

...Most popular Stackoverflow questions on MapConfig

Most used methods in MapConfig

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful