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

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

Source:EndToEndTest.java Github

copy

Full Screen

...33import org.openqa.selenium.grid.config.CompoundConfig;34import org.openqa.selenium.grid.config.Config;35import org.openqa.selenium.grid.config.MapConfig;36import org.openqa.selenium.grid.config.MemoizedConfig;37import org.openqa.selenium.grid.config.TomlConfig;38import org.openqa.selenium.grid.data.Session;39import org.openqa.selenium.grid.distributor.httpd.DistributorServer;40import org.openqa.selenium.grid.node.SessionFactory;41import org.openqa.selenium.grid.node.httpd.NodeServer;42import org.openqa.selenium.grid.router.httpd.RouterServer;43import org.openqa.selenium.grid.server.BaseServerOptions;44import org.openqa.selenium.grid.server.Server;45import org.openqa.selenium.grid.sessionmap.httpd.SessionMapServer;46import org.openqa.selenium.grid.sessionqueue.httpd.NewSessionQueuerServer;47import org.openqa.selenium.grid.testing.TestSessionFactory;48import org.openqa.selenium.grid.web.Values;49import org.openqa.selenium.json.Json;50import org.openqa.selenium.json.JsonOutput;51import org.openqa.selenium.net.PortProber;52import org.openqa.selenium.remote.RemoteWebDriver;53import org.openqa.selenium.remote.SessionId;54import org.openqa.selenium.remote.http.Contents;55import org.openqa.selenium.remote.http.HttpClient;56import org.openqa.selenium.remote.http.HttpHandler;57import org.openqa.selenium.remote.http.HttpRequest;58import org.openqa.selenium.remote.http.HttpResponse;59import org.openqa.selenium.support.ui.FluentWait;60import org.openqa.selenium.testing.Safely;61import org.openqa.selenium.testing.TearDownFixture;62import java.io.StringReader;63import java.io.UncheckedIOException;64import java.net.URI;65import java.net.URISyntaxException;66import java.time.Duration;67import java.time.Instant;68import java.util.Collection;69import java.util.Map;70import java.util.UUID;71import java.util.function.Supplier;72import static java.time.Duration.ofSeconds;73import static org.assertj.core.api.Assertions.assertThat;74import static org.junit.Assert.assertEquals;75import static org.junit.Assert.assertFalse;76import static org.junit.Assert.assertTrue;77import static org.junit.Assert.fail;78import static org.openqa.selenium.json.Json.MAP_TYPE;79import static org.openqa.selenium.remote.http.Contents.asJson;80import static org.openqa.selenium.remote.http.Contents.string;81import static org.openqa.selenium.remote.http.HttpMethod.GET;82import static org.openqa.selenium.remote.http.HttpMethod.POST;83@RunWith(Parameterized.class)84public class EndToEndTest {85 private static final Capabilities CAPS = new ImmutableCapabilities("browserName", "cheese");86 private final Json json = new Json();87 @Parameterized.Parameters(name = "End to End {0}")88 public static Collection<Supplier<TestData>> buildGrids() {89 return ImmutableSet.of(90 EndToEndTest::createFullyDistributed,91 EndToEndTest::createHubAndNode,92 EndToEndTest::createStandalone);93 }94 @Parameter95 public Supplier<TestData> values;96 private Server<?> server;97 private HttpClient.Factory clientFactory;98 @Before99 public void setFields() {100 TestData data = values.get();101 this.server = data.server;102 this.clientFactory = HttpClient.Factory.createDefault();103 }104 @After105 public void stopServers() {106 Safely.safelyCall(values.get().fixtures);107 }108 private static TestData createStandalone() {109 StringBuilder rawCaps = new StringBuilder();110 try (JsonOutput out = new Json().newOutput(rawCaps)) {111 out.setPrettyPrint(false).write(CAPS);112 }113 String[] rawConfig = new String[]{114 "[network]",115 "relax-checks = true",116 "",117 "[node]",118 "detect-drivers = false",119 "driver-factories = [",120 String.format("\"%s\",", TestSessionFactoryFactory.class.getName()),121 String.format("\"%s\"", rawCaps.toString().replace("\"", "\\\"")),122 "]",123 "",124 "[server]",125 "port = " + PortProber.findFreePort(),126 "registration-secret = \"provolone\""127 };128 Config config = new MemoizedConfig(129 new TomlConfig(new StringReader(String.join("\n", rawConfig))));130 Server<?> server = new Standalone().asServer(config).start();131 waitUntilReady(server);132 return new TestData(server, server::stop);133 }134 private static TestData createHubAndNode() {135 StringBuilder rawCaps = new StringBuilder();136 try (JsonOutput out = new Json().newOutput(rawCaps)) {137 out.setPrettyPrint(false).write(CAPS);138 }139 int publish = PortProber.findFreePort();140 int subscribe = PortProber.findFreePort();141 String[] rawConfig = new String[] {142 "[events]",143 "publish = \"tcp://localhost:" + publish + "\"",144 "subscribe = \"tcp://localhost:" + subscribe + "\"",145 "",146 "[network]",147 "relax-checks = true",148 "",149 "[node]",150 "detect-drivers = false",151 "driver-factories = [",152 String.format("\"%s\",", TestSessionFactoryFactory.class.getName()),153 String.format("\"%s\"", rawCaps.toString().replace("\"", "\\\"")),154 "]",155 "",156 "[server]",157 "registration-secret = \"feta\""158 };159 TomlConfig baseConfig = new TomlConfig(new StringReader(String.join("\n", rawConfig)));160 Config hubConfig = new CompoundConfig(161 new MapConfig(ImmutableMap.of("events", ImmutableMap.of("bind", true))),162 baseConfig);163 Server<?> hub = new Hub().asServer(setRandomPort(hubConfig)).start();164 Server<?> node = new NodeServer().asServer(setRandomPort(baseConfig)).start();165 waitUntilReady(node);166 waitUntilReady(hub);167 return new TestData(hub, hub::stop, node::stop);168 }169 private static TestData createFullyDistributed() {170 StringBuilder rawCaps = new StringBuilder();171 try (JsonOutput out = new Json().newOutput(rawCaps)) {172 out.setPrettyPrint(false).write(CAPS);173 }174 int publish = PortProber.findFreePort();175 int subscribe = PortProber.findFreePort();176 String[] rawConfig = new String[] {177 "[events]",178 "publish = \"tcp://localhost:" + publish + "\"",179 "subscribe = \"tcp://localhost:" + subscribe + "\"",180 "bind = false",181 "",182 "[network]",183 "relax-checks = true",184 "",185 "[node]",186 "detect-drivers = false",187 "driver-factories = [",188 String.format("\"%s\",", TestSessionFactoryFactory.class.getName()),189 String.format("\"%s\"", rawCaps.toString().replace("\"", "\\\"")),190 "]",191 "",192 "[server]",193 "registration-secret = \"colby\""194 };195 Config sharedConfig = new MemoizedConfig(new TomlConfig(new StringReader(String.join("\n", rawConfig))));196 Server<?> eventServer = new EventBusCommand()197 .asServer(new CompoundConfig(198 new TomlConfig(new StringReader(String.join("\n", new String[] {199 "[events]",200 "publish = \"tcp://localhost:" + publish + "\"",201 "subscribe = \"tcp://localhost:" + subscribe + "\"",202 "bind = true"}))),203 setRandomPort(sharedConfig)))204 .start();205 waitUntilReady(eventServer);206 Server<?> newSessionQueueServer = new NewSessionQueuerServer().asServer(setRandomPort(sharedConfig)).start();207 waitUntilReady(newSessionQueueServer);208 Server<?> sessionMapServer = new SessionMapServer().asServer(setRandomPort(sharedConfig)).start();209 Config sessionMapConfig = new TomlConfig(new StringReader(String.join(210 "\n",211 new String[] {212 "[sessions]",213 "hostname = \"localhost\"",214 "port = " + sessionMapServer.getUrl().getPort()215 }216 )));217 Server<?> distributorServer = new DistributorServer()218 .asServer(setRandomPort(new CompoundConfig(sharedConfig, sessionMapConfig)))219 .start();220 Config distributorConfig = new TomlConfig(new StringReader(String.join(221 "\n",222 new String[] {223 "[distributor]",224 "hostname = \"localhost\"",225 "port = " + distributorServer.getUrl().getPort()226 }227 )));228 Server<?> router = new RouterServer()229 .asServer(setRandomPort(new CompoundConfig(sharedConfig, sessionMapConfig, distributorConfig)))230 .start();231 Server<?> nodeServer = new NodeServer()232 .asServer(setRandomPort(new CompoundConfig(sharedConfig, sessionMapConfig, distributorConfig)))233 .start();234 waitUntilReady(nodeServer);...

Full Screen

Full Screen

Source:NodeOptionsTest.java Github

copy

Full Screen

...35import org.openqa.selenium.firefox.FirefoxOptions;36import org.openqa.selenium.grid.config.Config;37import org.openqa.selenium.grid.config.ConfigException;38import org.openqa.selenium.grid.config.MapConfig;39import org.openqa.selenium.grid.config.TomlConfig;40import org.openqa.selenium.grid.data.CreateSessionRequest;41import org.openqa.selenium.grid.node.ActiveSession;42import org.openqa.selenium.grid.node.SessionFactory;43import org.openqa.selenium.internal.Either;44import org.openqa.selenium.json.Json;45import java.io.StringReader;46import java.util.ArrayList;47import java.util.Collection;48import java.util.Collections;49import java.util.List;50import java.util.Map;51@SuppressWarnings("DuplicatedCode")52public class NodeOptionsTest {53 @Test54 public void canConfigureNodeWithDriverDetection() {55 assumeFalse("We don't have driver servers in PATH when we run unit tests",56 Boolean.parseBoolean(System.getenv("GITHUB_ACTIONS")));57 assumeTrue("ChromeDriver needs to be available", new ChromeDriverInfo().isAvailable());58 Config config = new MapConfig(singletonMap("node", singletonMap("detect-drivers", "true")));59 List<Capabilities> reported = new ArrayList<>();60 new NodeOptions(config).getSessionFactories(caps -> {61 reported.add(caps);62 return Collections.singleton(HelperFactory.create(config, caps));63 });64 ChromeDriverInfo chromeDriverInfo = new ChromeDriverInfo();65 String expected = chromeDriverInfo.getDisplayName();66 reported.stream()67 .filter(chromeDriverInfo::isSupporting)68 .filter(caps -> expected.equalsIgnoreCase(caps.getBrowserName()))69 .findFirst()70 .orElseThrow(() -> new AssertionError("Unable to find Chrome info"));71 }72 @Test73 public void shouldDetectCorrectDriversOnWindows() {74 assumeTrue(Platform.getCurrent().is(Platform.WINDOWS));75 assumeFalse("We don't have driver servers in PATH when we run unit tests",76 Boolean.parseBoolean(System.getenv("GITHUB_ACTIONS")));77 Config config = new MapConfig(singletonMap("node", singletonMap("detect-drivers", "true")));78 List<Capabilities> reported = new ArrayList<>();79 new NodeOptions(config).getSessionFactories(caps -> {80 reported.add(caps);81 return Collections.singleton(HelperFactory.create(config, caps));82 });83 assertThat(reported).is(supporting("chrome"));84 assertThat(reported).is(supporting("firefox"));85 assertThat(reported).is(supporting("internet explorer"));86 assertThat(reported).is(supporting("MicrosoftEdge"));87 assertThat(reported).isNot(supporting("safari"));88 }89 @Test90 public void shouldDetectCorrectDriversOnMac() {91 assumeTrue(Platform.getCurrent().is(Platform.MAC));92 assumeFalse("We don't have driver servers in PATH when we run unit tests",93 Boolean.parseBoolean(System.getenv("GITHUB_ACTIONS")));94 Config config = new MapConfig(singletonMap("node", singletonMap("detect-drivers", "true")));95 List<Capabilities> reported = new ArrayList<>();96 new NodeOptions(config).getSessionFactories(caps -> {97 reported.add(caps);98 return Collections.singleton(HelperFactory.create(config, caps));99 });100 // There may be more drivers available, but we know that these are meant to be here.101 assertThat(reported).is(supporting("safari"));102 assertThat(reported).isNot(supporting("internet explorer"));103 }104 @Test105 public void canConfigureNodeWithoutDriverDetection() {106 Config config = new MapConfig(singletonMap("node", singletonMap("detect-drivers", "false")));107 List<Capabilities> reported = new ArrayList<>();108 new NodeOptions(config).getSessionFactories(caps -> {109 reported.add(caps);110 return Collections.singleton(HelperFactory.create(config, caps));111 });112 assertThat(reported).isEmpty();113 }114 @Test115 public void shouldThrowConfigExceptionIfDetectDriversIsFalseAndSpecificDriverIsAdded() {116 Config config = new MapConfig(117 singletonMap("node",118 ImmutableMap.of(119 "detect-drivers", "false",120 "driver-implementation", "[chrome]"121 )));122 List<Capabilities> reported = new ArrayList<>();123 try {124 new NodeOptions(config).getSessionFactories(caps -> {125 reported.add(caps);126 return Collections.singleton(HelperFactory.create(config, caps));127 });128 fail("Should have not executed 'getSessionFactories' successfully");129 } catch (ConfigException e) {130 // Fall through131 }132 assertThat(reported).isEmpty();133 }134 @Test135 public void detectDriversByDefault() {136 Config config = new MapConfig(emptyMap());137 List<Capabilities> reported = new ArrayList<>();138 new NodeOptions(config).getSessionFactories(caps -> {139 reported.add(caps);140 return Collections.singleton(HelperFactory.create(config, caps));141 });142 assertThat(reported).isNotEmpty();143 }144 @Test145 public void canBeConfiguredToUseHelperClassesToCreateSessionFactories() {146 Capabilities caps = new ImmutableCapabilities("browserName", "cheese");147 StringBuilder capsString = new StringBuilder();148 new Json().newOutput(capsString).setPrettyPrint(false).write(caps);149 Config config = new TomlConfig(new StringReader(String.format(150 "[node]\n" +151 "detect-drivers = false\n" +152 "driver-factories = [" +153 " \"%s\",\n" +154 " \"%s\"\n" +155 "]",156 HelperFactory.class.getName(),157 capsString.toString().replace("\"", "\\\""))));158 NodeOptions options = new NodeOptions(config);159 Map<Capabilities, Collection<SessionFactory>> factories = options.getSessionFactories(info -> emptySet());160 Collection<SessionFactory> sessionFactories = factories.get(caps);161 assertThat(sessionFactories).size().isEqualTo(1);162 assertThat(sessionFactories.iterator().next()).isInstanceOf(SessionFactory.class);163 }164 @Test165 public void driversCanBeConfigured() {166 String chromeLocation = "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta";167 String firefoxLocation = "/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin";168 ChromeOptions chromeOptions = new ChromeOptions();169 chromeOptions.setBinary(chromeLocation);170 FirefoxOptions firefoxOptions = new FirefoxOptions();171 firefoxOptions.setBinary(firefoxLocation);172 StringBuilder chromeCaps = new StringBuilder();173 StringBuilder firefoxCaps = new StringBuilder();174 new Json().newOutput(chromeCaps).setPrettyPrint(false).write(chromeOptions);175 new Json().newOutput(firefoxCaps).setPrettyPrint(false).write(firefoxOptions);176 String[] rawConfig = new String[]{177 "[node]",178 "detect-drivers = false",179 "[[node.driver-configuration]]",180 "name = \"Chrome Beta\"",181 "max-sessions = 2",182 String.format("stereotype = \"%s\"", chromeCaps.toString().replace("\"", "\\\"")),183 "[[node.driver-configuration]]",184 "name = \"Firefox Nightly\"",185 "max-sessions = 3",186 String.format("stereotype = \"%s\"", firefoxCaps.toString().replace("\"", "\\\""))187 };188 Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));189 List<Capabilities> reported = new ArrayList<>();190 new NodeOptions(config).getSessionFactories(capabilities -> {191 reported.add(capabilities);192 return Collections.singleton(HelperFactory.create(config, capabilities));193 });194 assertThat(reported).is(supporting("chrome"));195 assertThat(reported).is(supporting("firefox"));196 //noinspection unchecked197 assertThat(reported)198 .filteredOn(capabilities -> capabilities.asMap().containsKey(ChromeOptions.CAPABILITY))199 .anyMatch(200 capabilities ->201 ((Map<String, String>) capabilities.getCapability(ChromeOptions.CAPABILITY))202 .get("binary").equalsIgnoreCase(chromeLocation));203 assertThat(reported)204 .filteredOn(capabilities -> capabilities.asMap().containsKey(ChromeOptions.CAPABILITY))205 .hasSize(2);206 //noinspection unchecked207 assertThat(reported)208 .filteredOn(capabilities -> capabilities.asMap().containsKey(FirefoxOptions.FIREFOX_OPTIONS))209 .anyMatch(210 capabilities ->211 ((Map<String, String>) capabilities.getCapability(FirefoxOptions.FIREFOX_OPTIONS))212 .get("binary").equalsIgnoreCase(firefoxLocation));213 assertThat(reported)214 .filteredOn(capabilities -> capabilities.asMap().containsKey(FirefoxOptions.FIREFOX_OPTIONS))215 .hasSize(3);216 }217 @Test218 public void driversConfigNeedsStereotypeField() {219 String[] rawConfig = new String[]{220 "[node]",221 "detect-drivers = false",222 "[[node.driver-configuration]]",223 "name = \"Chrome Beta\"",224 "max-sessions = 2",225 "cheese = \"paipa\"",226 "[[node.driver-configuration]]",227 "name = \"Firefox Nightly\"",228 "max-sessions = 2",229 "cheese = \"sabana\"",230 };231 Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));232 List<Capabilities> reported = new ArrayList<>();233 try {234 new NodeOptions(config).getSessionFactories(caps -> {235 reported.add(caps);236 return Collections.singleton(HelperFactory.create(config, caps));237 });238 fail("Should have not executed 'getSessionFactories' successfully because driver config " +239 "needs the stereotype field");240 } catch (ConfigException e) {241 // Fall through242 }243 assertThat(reported).isEmpty();244 }245 private Condition<? super List<? extends Capabilities>> supporting(String name) {...

Full Screen

Full Screen

Source:DeploymentTypes.java Github

copy

Full Screen

...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)))...

Full Screen

Full Screen

Source:RelayOptionsTest.java Github

copy

Full Screen

...20import org.junit.Test;21import org.openqa.selenium.Capabilities;22import org.openqa.selenium.grid.config.Config;23import org.openqa.selenium.grid.config.ConfigException;24import org.openqa.selenium.grid.config.TomlConfig;25import org.openqa.selenium.grid.node.SessionFactory;26import org.openqa.selenium.grid.server.NetworkOptions;27import org.openqa.selenium.remote.http.HttpClient;28import org.openqa.selenium.remote.tracing.DefaultTestTracer;29import org.openqa.selenium.remote.tracing.Tracer;30import java.io.StringReader;31import java.util.Collection;32import java.util.Map;33@SuppressWarnings("DuplicatedCode")34public class RelayOptionsTest {35 @Test36 public void basicConfigurationIsParsedSuccessfully() {37 String[] rawConfig = new String[]{38 "[relay]",39 "url = 'http://localhost:9999'",40 "configs = [\"2\", '{\"browserName\": \"chrome\"}']",41 };42 Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));43 NetworkOptions networkOptions = new NetworkOptions(config);44 Tracer tracer = DefaultTestTracer.createTracer();45 HttpClient.Factory httpClientFactory = networkOptions.getHttpClientFactory(tracer);46 Map<Capabilities, Collection<SessionFactory>>47 sessionFactories = new RelayOptions(config).getSessionFactories(tracer, httpClientFactory);48 Capabilities chrome = sessionFactories49 .keySet()50 .stream()51 .filter(capabilities -> "chrome".equals(capabilities.getBrowserName()))52 .findFirst()53 .orElseThrow(() -> new AssertionError("No value returned"));54 assertThat(sessionFactories.get(chrome).size()).isEqualTo(2);55 RelaySessionFactory relaySessionFactory = (RelaySessionFactory) sessionFactories.get(chrome)56 .stream()57 .findFirst()58 .orElseThrow(() -> new AssertionError("No value returned"));59 assertThat(relaySessionFactory.getServiceUrl().toString()).isEqualTo("http://localhost:9999");60 }61 @Test62 public void hostAndPortAreParsedSuccessfully() {63 String[] rawConfig = new String[]{64 "[relay]",65 "host = '127.0.0.1'",66 "port = '9999'",67 "configs = [\"5\", '{\"browserName\": \"firefox\"}']",68 };69 Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));70 NetworkOptions networkOptions = new NetworkOptions(config);71 Tracer tracer = DefaultTestTracer.createTracer();72 HttpClient.Factory httpClientFactory = networkOptions.getHttpClientFactory(tracer);73 Map<Capabilities, Collection<SessionFactory>>74 sessionFactories = new RelayOptions(config).getSessionFactories(tracer, httpClientFactory);75 Capabilities firefox = sessionFactories76 .keySet()77 .stream()78 .filter(capabilities -> "firefox".equals(capabilities.getBrowserName()))79 .findFirst()80 .orElseThrow(() -> new AssertionError("No value returned"));81 assertThat(sessionFactories.get(firefox).size()).isEqualTo(5);82 RelaySessionFactory relaySessionFactory = (RelaySessionFactory) sessionFactories.get(firefox)83 .stream()84 .findFirst()85 .orElseThrow(() -> new AssertionError("No value returned"));86 assertThat(relaySessionFactory.getServiceUrl().toString()).isEqualTo("http://127.0.0.1:9999");87 }88 @Test89 public void missingConfigsThrowsConfigException() {90 String[] rawConfig = new String[]{91 "[relay]",92 "host = '127.0.0.1'",93 "port = '9999'",94 };95 Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));96 NetworkOptions networkOptions = new NetworkOptions(config);97 Tracer tracer = DefaultTestTracer.createTracer();98 HttpClient.Factory httpClientFactory = networkOptions.getHttpClientFactory(tracer);99 assertThatExceptionOfType(ConfigException.class)100 .isThrownBy(() -> new RelayOptions(config).getSessionFactories(tracer, httpClientFactory));101 }102 @Test103 public void incompleteConfigsThrowsConfigException() {104 String[] rawConfig = new String[]{105 "[relay]",106 "host = '127.0.0.1'",107 "port = '9999'",108 "configs = ['{\"browserName\": \"firefox\"}']",109 };110 Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));111 NetworkOptions networkOptions = new NetworkOptions(config);112 Tracer tracer = DefaultTestTracer.createTracer();113 HttpClient.Factory httpClientFactory = networkOptions.getHttpClientFactory(tracer);114 assertThatExceptionOfType(ConfigException.class)115 .isThrownBy(() -> new RelayOptions(config).getSessionFactories(tracer, httpClientFactory));116 }117}...

Full Screen

Full Screen

Source:DistributedCdpTest.java Github

copy

Full Screen

...26import org.openqa.selenium.devtools.DevTools;27import org.openqa.selenium.devtools.HasDevTools;28import org.openqa.selenium.devtools.idealized.Network;29import org.openqa.selenium.grid.config.MapConfig;30import org.openqa.selenium.grid.config.TomlConfig;31import org.openqa.selenium.grid.router.DeploymentTypes.Deployment;32import org.openqa.selenium.grid.server.BaseServerOptions;33import org.openqa.selenium.grid.server.Server;34import org.openqa.selenium.netty.server.NettyServer;35import org.openqa.selenium.remote.Augmenter;36import org.openqa.selenium.remote.RemoteWebDriver;37import org.openqa.selenium.remote.http.Contents;38import org.openqa.selenium.remote.http.HttpResponse;39import org.openqa.selenium.remote.http.Route;40import org.openqa.selenium.support.devtools.NetworkInterceptor;41import org.openqa.selenium.testing.drivers.Browser;42import java.io.IOException;43import java.io.StringReader;44import java.util.HashMap;45import java.util.Map;46import java.util.Objects;47import java.util.concurrent.CountDownLatch;48import static java.util.concurrent.TimeUnit.SECONDS;49import static org.assertj.core.api.Assertions.assertThat;50import static org.assertj.core.api.Assumptions.assumeThat;51public class DistributedCdpTest {52 @BeforeClass53 public static void ensureBrowserIsCdpEnabled() {54 Browser browser = Objects.requireNonNull(Browser.detect());55 assumeThat(browser.supportsCdp()).isTrue();56 }57 @Test58 public void ensureBasicFunctionality() throws InterruptedException {59 Browser browser = Browser.detect();60 Deployment deployment = DeploymentTypes.DISTRIBUTED.start(61 browser.getCapabilities(),62 new TomlConfig(new StringReader(63 "[node]\n" +64 "detect-drivers = true\n" +65 "drivers = " + browser.displayName())));66 Server<?> server = new NettyServer(67 new BaseServerOptions(new MapConfig(ImmutableMap.of())),68 req -> new HttpResponse().setContent(Contents.utf8String("I like cheese")))69 .start();70 WebDriver driver = new RemoteWebDriver(71 deployment.getServer().getUrl(), addBrowserPath(browser.getCapabilities()));72 driver = new Augmenter().augment(driver);73 String serverUri = server.getUrl().toString();74 CountDownLatch latch = new CountDownLatch(1);75 try (DevTools devTools = ((HasDevTools) driver).getDevTools()) {76 devTools.createSessionIfThereIsNotOne();...

Full Screen

Full Screen

Source:StressTest.java Github

copy

Full Screen

...21import org.openqa.selenium.By;22import org.openqa.selenium.WebDriver;23import org.openqa.selenium.grid.config.MapConfig;24import org.openqa.selenium.grid.config.MemoizedConfig;25import org.openqa.selenium.grid.config.TomlConfig;26import org.openqa.selenium.grid.router.DeploymentTypes.Deployment;27import org.openqa.selenium.grid.server.BaseServerOptions;28import org.openqa.selenium.grid.server.Server;29import org.openqa.selenium.netty.server.NettyServer;30import org.openqa.selenium.remote.RemoteWebDriver;31import org.openqa.selenium.remote.http.Contents;32import org.openqa.selenium.remote.http.HttpResponse;33import org.openqa.selenium.testing.Safely;34import org.openqa.selenium.testing.TearDownFixture;35import org.openqa.selenium.testing.drivers.Browser;36import java.io.StringReader;37import java.util.LinkedList;38import java.util.List;39import java.util.Map;40import java.util.Objects;41import java.util.concurrent.CompletableFuture;42import java.util.concurrent.ExecutorService;43import java.util.concurrent.Executors;44import static java.nio.charset.StandardCharsets.UTF_8;45import static java.util.concurrent.TimeUnit.MINUTES;46import static org.assertj.core.api.Assertions.assertThat;47public class StressTest {48 private final ExecutorService executor =49 Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);50 private final List<TearDownFixture> tearDowns = new LinkedList<>();51 private Server<?> server;52 private Browser browser;53 private Server<?> appServer;54 @Before55 public void setupServers() {56 browser = Objects.requireNonNull(Browser.detect());57 Deployment deployment = DeploymentTypes.DISTRIBUTED.start(58 browser.getCapabilities(),59 new TomlConfig(new StringReader(60 "[node]\n" +61 "drivers = " + browser.displayName())));62 tearDowns.add(deployment);63 server = deployment.getServer();64 appServer = new NettyServer(65 new BaseServerOptions(new MemoizedConfig(new MapConfig(Map.of()))),66 req -> {67 try {68 Thread.sleep(2000);69 } catch (InterruptedException e) {70 throw new RuntimeException(e);71 }72 return new HttpResponse()73 .setContent(Contents.string("<h1>Cheese</h1>", UTF_8));...

Full Screen

Full Screen

Source:TomlConfig.java Github

copy

Full Screen

...28import java.util.List;29import java.util.Objects;30import java.util.Optional;31import java.util.Set;32public class TomlConfig implements Config {33 private final Toml toml;34 TomlConfig(Reader reader) {35 try {36 toml = JToml.parse(reader);37 } catch (IOException e) {38 throw new ConfigException("Unable to read TOML.", e);39 }40 }41 public static Config from(Path path) {42 Objects.requireNonNull(path, "Path to read must be set.");43 try (Reader reader = Files.newBufferedReader(path)) {44 return new TomlConfig(reader);45 } catch (IOException e) {46 throw new ConfigException(String.format("Unable to parse: %s", path), e);47 }48 }49 @Override50 public Optional<List<String>> getAll(String section, String option) {51 Objects.requireNonNull(section, "Section to read must be set.");52 Objects.requireNonNull(option, "Option to read must be set.");53 if (!toml.containsKey(section)) {54 return Optional.empty();55 }56 Object raw = toml.get(section);57 if (!(raw instanceof TomlTable)) {58 throw new ConfigException(String.format("Section %s is not a section! %s", section, raw));...

Full Screen

Full Screen

Source:TomlConfigTest.java Github

copy

Full Screen

...18import org.junit.Test;19import java.io.StringReader;20import java.util.Optional;21import static org.assertj.core.api.Assertions.assertThat;22public class TomlConfigTest {23 @Test24 public void shouldUseATableAsASection() {25 String raw = "[cheeses]\nselected=brie";26 Config config = new TomlConfig(new StringReader(raw));27 assertThat(config.get("cheeses", "selected")).isEqualTo(Optional.of("brie"));28 }29}...

Full Screen

Full Screen

TomlConfig

Using AI Code Generation

copy

Full Screen

1TomlConfig config = new TomlConfig("config.toml");2TomlConfig config = new TomlConfig(Paths.get("config.toml"));3TomlConfig config = new TomlConfig(Paths.get("config.toml"), "section");4TomlConfig config = new TomlConfig(Paths.get("config.toml"), "section1", "section2");5TomlConfig config = new TomlConfig(Paths.get("config.toml"), "section1", "section2", "section3");6TomlConfig config = new TomlConfig(Paths.get("config.toml"), "section1", "section2", "section3", "section4");7TomlConfig config = new TomlConfig(Paths.get("config.toml"), "section1", "section2", "section3", "section4", "section5");8TomlConfig config = new TomlConfig(Paths.get("config.toml"), "section1", "section2", "section3", "section4", "section5", "section6");9TomlConfig config = new TomlConfig("config.toml", "section");10TomlConfig config = new TomlConfig("config.toml", "section1", "section2");11TomlConfig config = new TomlConfig("config.toml", "section1", "section2", "section3");12TomlConfig config = new TomlConfig("config.toml", "section1", "section2", "section3", "section4");

Full Screen

Full Screen

TomlConfig

Using AI Code Generation

copy

Full Screen

1TomlConfig config = new TomlConfig("config.toml");2String host = config.get("host").toString();3int port = Integer.parseInt(config.get("port").toString());4String username = config.get("username").toString();5String password = config.get("password").toString();6String browser = config.get("browser").toString();7String url = config.get("url").toString();8String gridurl = config.get("gridurl").toString();9String huburl = config.get("huburl").toString();10String hubport = config.get("hubport").toString();11try {12 DesiredCapabilities capabilities = new DesiredCapabilities();13 capabilities.setBrowserName(browser);14 capabilities.setPlatform(Platform.WINDOWS);15 driver = new RemoteWebDriver(new URL(gridurl), capabilities);16} catch (MalformedURLException e) {17 e.printStackTrace();18}19try {20 DesiredCapabilities capabilities = new DesiredCapabilities();21 capabilities.setBrowserName(browser);22 capabilities.setPlatform(Platform.WINDOWS);23 driver = new RemoteWebDriver(new URL(huburl + ":" + hubport + "/wd/hub"), capabilities);24} catch (MalformedURLException e) {25 e.printStackTrace();26}27if (browser.equalsIgnoreCase("firefox")) {28 System.setProperty("webdriver.gecko.driver", "C:\\Users\\user\\Downloads\\geckodriver-v0.24.0-win64\\geckodriver.exe");29 driver = new FirefoxDriver();30} else if (browser.equalsIgnoreCase("chrome")) {31 System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe");32 driver = new ChromeDriver();33} else if (browser.equalsIgnoreCase("edge")) {34 System.setProperty("webdriver.edge.driver", "C:\\Users\\user\\Downloads\\edgedriver_win64\\msedgedriver.exe");35 driver = new EdgeDriver();36}37driver.get(url);38driver.manage().window().maximize();39driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);40element.sendKeys("Dress");41element.submit();42element1.click();43element2.click();

Full Screen

Full Screen

TomlConfig

Using AI Code Generation

copy

Full Screen

1TomlConfig config = new TomlConfig("path/to/config.toml");2String browser = config.get("browser").orElse("chrome");3String search = config.get("search").orElse("Selenium");4TomlConfig config = new TomlConfig("path/to/config.toml");5String browser = config.get("browser").orElse("chrome");6String search = config.get("search").orElse("Selenium");7TomlConfig config = new TomlConfig("path/to/config.toml");8String browser = config.get("browser").orElse("chrome");9String search = config.get("search").orElse("Selenium");10TomlConfig config = new TomlConfig("path/to/config.toml");11String browser = config.get("browser").orElse("chrome");12String search = config.get("search").orElse("Selenium");13TomlConfig config = new TomlConfig("path/to/config.toml");14String browser = config.get("browser").orElse("chrome");15String search = config.get("search").orElse("Selenium");16TomlConfig config = new TomlConfig("path/to/config.toml");17String browser = config.get("browser").orElse("chrome");18String search = config.get("search").orElse("Selenium");19TomlConfig config = new TomlConfig("path/to/config.toml");20String browser = config.get("browser").orElse("chrome");21String search = config.get("search").orElse("Selenium");

Full Screen

Full Screen

TomlConfig

Using AI Code Generation

copy

Full Screen

1TomlConfig config = new TomlConfig("config.toml");2Toml toml = new Toml().read(config.getConfig());3int timeout = toml.getLong("timeout").intValue();4String browser = toml.getString("browser");5String url = toml.getString("url");6String username = toml.getString("username");7String password = toml.getString("password");8String expectedResult = toml.getString("expectedResult");9driver = new ChromeDriver();10driver.get(url);11driver.manage().window().maximize();12driver.manage().timeouts().implicitlyWait(timeout, TimeUnit.SECONDS);13driver.findElement(By.id("username")).sendKeys(username);14driver.findElement(By.id("password")).sendKeys(password);15driver.findElement(By.id("Login")).click();16String actualResult = driver.findElement(By.id("error")).getText();17Assert.assertEquals(actualResult, expectedResult);18driver.quit();

Full Screen

Full Screen
copy
1public class RetryTest {2 public class Retry implements TestRule {3 private int retryCount;45 public Retry(int retryCount) {6 this.retryCount = retryCount;7 }89 public Statement apply(Statement base, Description description) {10 return statement(base, description);11 }1213 private Statement statement(final Statement base, final Description description) {14 return new Statement() {15 @Override16 public void evaluate() throws Throwable {17 Throwable caughtThrowable = null;1819 // implement retry logic here20 for (int i = 0; i < retryCount; i++) {21 try {22 base.evaluate();23 return;24 } catch (Throwable t) {25 caughtThrowable = t;26 System.err.println(description.getDisplayName() + ": run " + (i+1) + " failed");27 }28 }29 System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures");30 throw caughtThrowable;31 }32 };33 }34 }3536 @Rule37 public Retry retry = new Retry(3);3839 @Test40 public void test1() {41 }4243 @Test44 public void test2() {45 Object o = null;46 o.equals("foo");47 }48}49
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 TomlConfig

Most used methods in TomlConfig

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