Best Selenium code snippet using org.openqa.selenium.grid.config.TomlConfig.from
Source:EndToEndTest.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.router;18import com.google.common.collect.ImmutableMap;19import com.google.common.collect.ImmutableSet;20import org.junit.After;21import org.junit.Before;22import org.junit.Test;23import org.junit.runner.RunWith;24import org.junit.runners.Parameterized;25import org.junit.runners.Parameterized.Parameter;26import org.openqa.selenium.Capabilities;27import org.openqa.selenium.ImmutableCapabilities;28import org.openqa.selenium.SessionNotCreatedException;29import org.openqa.selenium.WebDriver;30import org.openqa.selenium.grid.commands.EventBusCommand;31import org.openqa.selenium.grid.commands.Hub;32import org.openqa.selenium.grid.commands.Standalone;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);235 waitUntilReady(router);236 return new TestData(237 router,238 router::stop,239 nodeServer::stop,240 distributorServer::stop,241 sessionMapServer::stop,242 newSessionQueueServer::stop,243 eventServer::stop);244 }245 private static void waitUntilReady(Server<?> server) {246 HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl());247 new FluentWait<>(client)248 .withTimeout(Duration.ofSeconds(5))249 .until(c -> {250 HttpResponse response = c.execute(new HttpRequest(GET, "/status"));251 Map<String, Object> status = Values.get(response, MAP_TYPE);252 return Boolean.TRUE.equals(status.get("ready"));253 });254 }255 private static Config setRandomPort(Config config) {256 return new MemoizedConfig(257 new CompoundConfig(258 new MapConfig(ImmutableMap.of("server", ImmutableMap.of("port", PortProber.findFreePort()))),259 config));260 }261 // Hahahaha. Java naming.262 public static class TestSessionFactoryFactory {263 public static SessionFactory create(Config config, Capabilities stereotype) {264 BaseServerOptions serverOptions = new BaseServerOptions(config);265 String hostname = serverOptions.getHostname().orElse("localhost");266 int port = serverOptions.getPort();267 URI serverUri;268 try {269 serverUri = new URI("http", null, hostname, port, null, null, null);270 } catch (URISyntaxException e) {271 throw new RuntimeException(e);272 }273 return new TestSessionFactory(stereotype, (id, caps) -> new SpoofSession(serverUri, caps));274 }275 }276 private static class SpoofSession extends Session implements HttpHandler {277 private SpoofSession(URI serverUri, Capabilities capabilities) {278 super(new SessionId(UUID.randomUUID()), serverUri, new ImmutableCapabilities(), capabilities, Instant.now());279 }280 @Override281 public HttpResponse execute(HttpRequest req) throws UncheckedIOException {282 return new HttpResponse();283 }284 }285 @Test286 public void success() {287 // The node added only has a single node. Make sure we can start and stop sessions.288 Capabilities caps = new ImmutableCapabilities("browserName", "cheese", "type", "cheddar");289 WebDriver driver = new RemoteWebDriver(server.getUrl(), caps);290 driver.get("http://www.google.com");291 // Kill the session, and wait until the grid says it's ready292 driver.quit();293 }294 @Test295 public void exerciseDriver() {296 // The node added only has a single node. Make sure we can start and stop sessions.297 Capabilities caps = new ImmutableCapabilities("browserName", "cheese", "type", "cheddar");298 WebDriver driver = new RemoteWebDriver(server.getUrl(), caps);299 driver.get("http://www.google.com");300 // The node is still open. Now create a second session. This should fail301 try {302 WebDriver disposable = new RemoteWebDriver(server.getUrl(), caps);303 disposable.quit();304 fail("Should not have been able to create driver");305 } catch (SessionNotCreatedException expected) {306 // Fall through307 }308 // Kill the session, and wait until the grid says it's ready309 driver.quit();310 HttpClient client = clientFactory.createClient(server.getUrl());311 new FluentWait<>("").withTimeout(ofSeconds(200)).until(obj -> {312 try {313 HttpResponse response = client.execute(new HttpRequest(GET, "/status"));314 System.out.println(Contents.string(response));315 Map<String, Object> status = Values.get(response, MAP_TYPE);316 return Boolean.TRUE.equals(status.get("ready"));317 } catch (UncheckedIOException e) {318 e.printStackTrace();319 return false;320 }321 });322 // And now we're good to go.323 driver = new RemoteWebDriver(server.getUrl(), caps);324 driver.get("http://www.google.com");325 driver.quit();326 }327 @Test328 public void shouldAllowPassthroughForW3CMode() {329 HttpRequest request = new HttpRequest(POST, "/session");330 request.setContent(asJson(331 ImmutableMap.of(332 "capabilities", ImmutableMap.of(333 "alwaysMatch", ImmutableMap.of("browserName", "cheese")))));334 HttpClient client = clientFactory.createClient(server.getUrl());335 HttpResponse response = client.execute(request);336 assertEquals(200, response.getStatus());337 Map<String, Object> topLevel = json.toType(string(response), MAP_TYPE);338 // There should not be a numeric status field339 assertFalse(string(request), topLevel.containsKey("status"));340 // And the value should have all the good stuff in it: the session id and the capabilities341 Map<?, ?> value = (Map<?, ?>) topLevel.get("value");342 assertThat(value.get("sessionId")).isInstanceOf(String.class);343 Map<?, ?> caps = (Map<?, ?>) value.get("capabilities");344 assertEquals("cheese", caps.get("browserName"));345 }346 @Test347 public void shouldAllowPassthroughForJWPMode() {348 HttpRequest request = new HttpRequest(POST, "/session");349 request.setContent(asJson(350 ImmutableMap.of(351 "desiredCapabilities", ImmutableMap.of(352 "browserName", "cheese"))));353 HttpClient client = clientFactory.createClient(server.getUrl());354 HttpResponse response = client.execute(request);355 assertEquals(200, response.getStatus());356 Map<String, Object> topLevel = json.toType(string(response), MAP_TYPE);357 // There should be a numeric status field358 assertEquals(topLevel.toString(), 0L, topLevel.get("status"));359 // The session id360 assertTrue(string(request), topLevel.containsKey("sessionId"));361 // And the value should be the capabilities.362 Map<?, ?> value = (Map<?, ?>) topLevel.get("value");363 assertEquals(string(request), "cheese", value.get("browserName"));364 }365 @Test366 public void shouldDoProtocolTranslationFromW3CLocalEndToJWPRemoteEnd() {367 }368 @Test369 public void shouldDoProtocolTranslationFromJWPLocalEndToW3CRemoteEnd() {370 }371 private static class TestData {372 public final Server<?> server;373 public final TearDownFixture[] fixtures;374 public TestData(Server<?> server, TearDownFixture... fixtures) {375 this.server = server;376 this.fixtures = fixtures;377 }378 }379}...
Source:TomlConfig.java
...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 }...
Source:TomlConfigTest.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.config;18import org.junit.Test;19import java.io.StringReader;20import java.util.Arrays;21import java.util.Collections;22import java.util.List;23import java.util.Optional;24import static org.assertj.core.api.Assertions.assertThat;25public class TomlConfigTest {26 @Test27 public void shouldUseATableAsASection() {28 String raw = "[cheeses]\nselected=brie";29 Config config = new TomlConfig(new StringReader(raw));30 assertThat(config.get("cheeses", "selected")).isEqualTo(Optional.of("brie"));31 }32 @Test33 public void shouldContainConfigFromArrayOfTables() {34 String[] rawConfig = new String[]{35 "[cheeses]",36 "default = manchego",37 "[[cheeses.type]]",38 "name = \"soft cheese\"",39 "default = \"brie\"",40 "[[cheeses.type]]",41 "name = \"Medium-hard cheese\"",42 "default = \"Emmental\""43 };44 Config config = new TomlConfig(new StringReader(String.join("\n", rawConfig)));45 assertThat(config.get("cheeses", "default")).isEqualTo(Optional.of("manchego"));46 List<String> expected = Arrays.asList(47 "name=soft cheese", "default=brie",48 "name=Medium-hard cheese", "default=Emmental");49 assertThat(50 config.getAll("cheeses", "type").orElse(Collections.emptyList()))51 .containsAll(expected);52 assertThat(53 config.getAll("cheeses", "type").orElse(Collections.emptyList()).subList(0, 2))54 .containsAll(expected.subList(0, 2));55 }56}...
Source:Configs.java
...21public class Configs {22 private Configs() {23 // This class is not intended to be instantiated24 }25 public static Config from(Path path) {26 Objects.requireNonNull(path, "Path to read must be set.");27 if (!Files.exists(path)) {28 throw new ConfigException("Path to read from does not exist: " + path);29 }30 String fileName = path.getFileName().toString();31 if (fileName.endsWith(".tml") || fileName.endsWith(".toml")) {32 return TomlConfig.from(path);33 }34 if (fileName.endsWith(".json")) {35 return JsonConfig.from(path);36 }37 throw new ConfigException(38 "Unable to determine file type. The file extension must be one of '.toml' or '.json' " + path);39 }40}...
from
Using AI Code Generation
1public static Map<String, Object> toMap(Toml toml) {2 Map<String, Object> map = new HashMap<>();3 toml.forEach((key, value) -> {4 if (value instanceof Toml) {5 map.put(key, toMap((Toml) value));6 } else if (value instanceof List) {7 List<Object> list = new ArrayList<>((List) value);8 list.replaceAll(o -> o instanceof Toml ? toMap((Toml) o) : o);9 map.put(key, list);10 } else {11 map.put(key, value);12 }13 });14 return map;15}16public static void main(String[] args) throws IOException {17 TomlConfig config = new TomlConfig(Paths.get("/path/to/config.toml"));18 Map<String, Object> map = toMap(config.getToml());19 System.out.println(map);20}
from
Using AI Code Generation
1public static TomlConfig create(Path path) {2 try {3 return new TomlConfig(path);4 } catch (IOException e) {5 throw new UncheckedIOException(e);6 }7}8public static TomlConfig create(String... lines) {9 return create(Arrays.stream(lines).collect(Collectors.joining("10")));11}12public static TomlConfig create(String contents) {13 try {14 Path tempFile = Files.createTempFile("selenium", ".toml");15 Files.write(tempFile, contents.getBytes(UTF_8));16 return new TomlConfig(tempFile);17 } catch (IOException e) {18 throw new UncheckedIOException(e);19 }20}21public static TomlConfig create(Reader reader) {22 try {23 Path tempFile = Files.createTempFile("selenium", ".toml");24 Files.copy(reader, tempFile, StandardCopyOption.REPLACE_EXISTING);25 return new TomlConfig(tempFile);26 } catch (IOException e) {27 throw new UncheckedIOException(e);28 }29}30public static TomlConfig create(InputStream stream) {31 return create(new InputStreamReader(stream, UTF_8));32}33public static TomlConfig create(URL url) {34 try {35 return new TomlConfig(url);36 } catch (IOException e) {37 throw new UncheckedIOException(e);38 }39}40public static TomlConfig create(Map<String, Object> map) {41 return new TomlConfig(map);42}43public static TomlConfig create(Config parent, String prefix) {44 return new TomlConfig(parent, prefix);45}46public static TomlConfig create(Config parent, String prefix, Map<String, Object> map) {47 return new TomlConfig(parent, prefix, map);48}
from
Using AI Code Generation
1public static Map<String, Object> toMap(Toml toml) {2 return toml.toMap();3}4public static Map<String, Object> toMap(Map<String, Object> map) {5 return map;6}7public static Map<String, Object> toMap(Config config) {8 return config.asMap();9}10public static Map<String, Object> toMap(MergedConfig config) {11 return config.asMap();12}13public static Map<String, Object> toMap(MissingConfig config) {14 return config.asMap();15}16public static Map<String, Object> toMap(CombinedConfig config) {17 return config.asMap();18}19public static Map<String, Object> toMap(PrefixConfig config) {20 return config.asMap();21}22public static Map<String, Object> toMap(SecretConfig config) {23 return config.asMap();24}25public static Map<String, Object> toMap(MemoizingConfig config) {26 return config.asMap();27}28public static Map<String, Object> toMap(CompositeConfig config) {29 return config.asMap();30}31public static Map<String, Object> toMap(SimpleConfig config) {32 return config.asMap();33}34public static Map<String, Object> toMap(FileBackedConfig config) {35 return config.asMap();36}37public static Map<String, Object> toMap(Config config) {38 return config.asMap();39}
from
Using AI Code Generation
1public String get(String key) {2 return toml.getString(key);3 }4 public String get(String key, String defaultValue) {5 return toml.getString(key, defaultValue);6 }7 public List<String> getList(String key) {8 return toml.getList(key);9 }10 public List<String> getList(String key, List<String> defaultValue) {11 return toml.getList(key, defaultValue);12 }13 public Map<String, String> getMap(String key) {14 return toml.getMap(key);15 }16 public Map<String, String> getMap(String key, Map<String, String> defaultValue) {17 return toml.getMap(key, defaultValue);18 }19 public int getInt(String key) {20 return toml.getInt(key);21 }22 public int getInt(String key, int defaultValue) {23 return toml.getInt(key, defaultValue);24 }25 public boolean getBool(String key) {26 return toml.getBoolean(key);27 }28 public boolean getBool(String key, boolean defaultValue) {29 return toml.getBoolean(key, defaultValue);30 }31 public Duration getDuration(String key) {32 return toml.getDuration(key);33 }34 public Duration getDuration(String key, Duration defaultValue) {35 return toml.getDuration(key, defaultValue);36 }37 public URL getUrl(String key) {38 return toml.getUrl(key);39 }40 public URL getUrl(String key, URL defaultValue) {41 return toml.getUrl(key, defaultValue);42 }43 public Path getPath(String key) {44 return toml.getPath(key);45 }46 public Path getPath(String key, Path defaultValue) {47 return toml.getPath(key, defaultValue);48 }49 public URI getUri(String key) {50 return toml.getUri(key);51 }52 public URI getUri(String key, URI defaultValue) {53 return toml.getUri(key, defaultValue);54 }55 public File getFile(String key) {56 return toml.getFile(key);57 }58 public File getFile(String key, File defaultValue) {59 return toml.getFile(key, defaultValue);60 }61 public InetAddress getInetAddress(String key) {62 return toml.getInetAddress(key);63 }64 public InetAddress getInetAddress(String key, InetAddress defaultValue) {65 return toml.getInetAddress(key, defaultValue);66 }67 public Class<?> getClass(String key) {68 return toml.getClass(key);69 }70 public Class<?> getClass(String key, Class<?> defaultValue) {
from
Using AI Code Generation
1private static final String CONFIG_FILE = "config.toml";2private static final String CONFIG_DIR = "config";3private static final String DEFAULT_CONFIG = CONFIG_DIR + "/" + CONFIG_FILE;4private static final String DEFAULT_CONFIG_PATH = "/" + DEFAULT_CONFIG;5private static final String CONFIG_PATH = System.getProperty("config", DEFAULT_CONFIG_PATH);6private static final Config DEFAULT_CONFIG = new TomlConfig(CONFIG_PATH);7private static final String CONFIG_FILE = "config.toml";8private static final String CONFIG_DIR = "config";9private static final String DEFAULT_CONFIG = CONFIG_DIR + "/" + CONFIG_FILE;10private static final String DEFAULT_CONFIG_PATH = "/" + DEFAULT_CONFIG;11private static final String CONFIG_PATH = System.getProperty("config", DEFAULT_CONFIG_PATH);12private static final Config DEFAULT_CONFIG = new TomlConfig(CONFIG_PATH);13private static final String CONFIG_FILE = "config.toml";14private static final String CONFIG_DIR = "config";15private static final String DEFAULT_CONFIG = CONFIG_DIR + "/" + CONFIG_FILE;16private static final String DEFAULT_CONFIG_PATH = "/" + DEFAULT_CONFIG;17private static final String CONFIG_PATH = System.getProperty("config", DEFAULT_CONFIG_PATH);18private static final Config DEFAULT_CONFIG = new TomlConfig(CONFIG_PATH);19private static final String CONFIG_FILE = "config.toml";20private static final String CONFIG_DIR = "config";21private static final String DEFAULT_CONFIG = CONFIG_DIR + "/" + CONFIG_FILE;22private static final String DEFAULT_CONFIG_PATH = "/" + DEFAULT_CONFIG;23private static final String CONFIG_PATH = System.getProperty("config", DEFAULT_CONFIG_PATH);24private static final Config DEFAULT_CONFIG = new TomlConfig(CONFIG_PATH);
from
Using AI Code Generation
1 private static Map<String, Object> toMap(Toml toml) {2 Map<String, Object> map = new HashMap<>();3 for (String key : toml.keySet()) {4 Object value = toml.get(key);5 if (value instanceof TomlTable) {6 map.put(key, toMap((TomlTable) value));7 } else if (value instanceof TomlArray) {8 map.put(key, toList((TomlArray) value));9 } else {10 map.put(key, value);11 }12 }13 return map;14 }15 private static List<Object> toList(TomlArray array) {16 List<Object> list = new ArrayList<>(array.size());17 for (Object value : array) {18 if (value instanceof TomlTable) {19 list.add(toMap((TomlTable) value));20 } else if (value instanceof TomlArray) {21 list.add(toList((TomlArray) value));22 } else {23 list.add(value);24 }25 }26 return list;27 }28}29import org.openqa.selenium.grid.config.TomlConfig;30import org.openqa.selenium.grid.config.Toml;31import org.openqa.selenium.grid.config.Config;32import org.openqa.selenium.grid.config.TomlConfig;33import org.openqa.selenium.grid.config.TomlConfigException;34import java.io.File;35import java.io.IOException;36import java.util.Map;37public class TomlConfigExample {38 public static void main(String[] args) throws IOException, TomlConfigException {39 String path = "path/to/file.toml";40 File file = new File(path);41 Toml toml = Toml.parse(file);42 Map<String, Object> map = TomlConfig.toMap(toml);43 map.put("newKey", "newValue");44 Config config = new TomlConfig(map);45 config.writeTo(file);46 }47}
from
Using AI Code Generation
1 String text = "name = \"my name\"";2 Config config = TomlConfig.create(text);3 String name = config.get("name").map(ConfigValue::asString).orElse("default");4 System.out.println(name);5 String text = "name = \"my name\"";6 Config config = TomlConfig.create(text);7 String name = config.get("name").map(ConfigValue::asString).orElse("default");8 System.out.println(name);9 String text = "name = \"my name\"";10 Config config = TomlConfig.create(text);11 String name = config.get("name").map(ConfigValue::asString).orElse("default");12 System.out.println(name);13 String text = "name = \"my name\"";14 Config config = TomlConfig.create(text);15 String name = config.get("name").map(ConfigValue::asString).orElse("default");16 System.out.println(name);17 String text = "name = \"my name\"";18 Config config = TomlConfig.create(text);19 String name = config.get("name").map(ConfigValue::asString).orElse("default");20 System.out.println(name);21 String text = "name = \"my name\"";22 Config config = TomlConfig.create(text);23 String name = config.get("name").map(ConfigValue::asString).orElse("default");24 System.out.println(name);25 String text = "name = \"my name\"";26 Config config = TomlConfig.create(text);27 String name = config.get("name").map(ConfigValue::asString).orElse("default");28 System.out.println(name);29 String text = "name = \"my name\"";30 Config config = TomlConfig.create(text);31 String name = config.get("name").map(ConfigValue::asString).orElse("default");32 System.out.println(name);
from
Using AI Code Generation
1 public static Map<String, Object> toMap(Toml toml) {2 return toml.toMap();3 }4}5import java.util.Map;6import org.openqa.selenium.grid.config.TomlConfig;7Map<String, Object> tomlMap = TomlConfig.toMap(toml);8symbol: method toMap(Toml)9I'm not sure how to resolve this issue. I'm sure it has something to do with the way I'm importing the toml library. Here's my code:10package org.openqa.selenium.grid.config;11import com.moandjiezana.toml.Toml;12public class TomlConfig extends Config {13 private Toml toml;14 public TomlConfig(Toml toml) {15 this.toml = toml;16 }17 public Object get(String key) {18 return toml.get(key);19 }20}21I'm not sure how to resolve this issue. I'm sure it has something to do with the way I'm importing the toml library. Here's my code:22package org.openqa.selenium.grid.config;23import com.moandjiezana.toml.Toml;24public class TomlConfig extends Config {25 private Toml toml;26 public TomlConfig(Toml toml) {
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.
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.
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.
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.
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.
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.
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.
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.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!