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

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

Run Selenium automation tests on LambdaTest cloud grid

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

ConfigException org.openqa.selenium.grid.config

The ConfigException is an exception that occur when the grid is not able start or register node for the given configurable attribute of the Selenium Grid.

Example

It is an example for throwing ConfigException when webdriver.gecko.driver is not found at correct path.

copy
1public synchronized WebDriver setUp(String browser, String 2nodePort, String hubPort) throws MalformedURLException{ 3 4DesiredCapabilities capabilities = new DesiredCapabilities(); 5capabilities.setPlatform(Platform.MAC); 6capabilities.setCapability(CapabilityType.BROWSER_NAME, browser); 7capabilities.setCapability(ForSeleniumServer.PROXYING_EVERYTHING, 8true); 9capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); 10capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true); 11capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, 12true); 13 14if(browser.equals("firefox")) 15 System.setProperty("webdriver.gecko.driver", 16System.getProperty("user.dir")+"//geckoDriver//geckodriver"); 17else if(browser.equals("chrome")) 18 System.setProperty("webdriver.chrome.driver", 19System.getProperty("user.dir")+"//chromeDriver//chromeDriver"); 20driver = new RemoteWebDriver(new 21URL("http://localhost:"+nodePort+"/wd/hub"), capabilities); 22driver.get("https://www.lambdatest.com"); 23driver.manage().window().maximize(); 24driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 25System.out.println(driver.toString()); 26return driver;

Solutions

  • Provide adequate memory to java process
  • Set and Verify the environment variables for driver paths
  • Verify configurations of selenium hub settings params.

Code Snippets

Here are code snippets that can help you understand more how developers are using

copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium.grid.distributor;
19
20import org.openqa.selenium.grid.config.Config;
21import org.openqa.selenium.grid.config.ConfigException;
22
23import java.net.URI;
24import java.net.URISyntaxException;
25import java.util.Optional;
26
27public class DistributorOptions {
28
29  private final Config config;
30
31  public DistributorOptions(Config config) {
32    this.config = config;
33  }
34
35  public URI getDistributorUri() {
36    Optional<URI> host = config.get("distributor", "host").map(str -> {
37      try {
38        return new URI(str);
39      } catch (URISyntaxException e) {
40        throw new ConfigException("Distributor URI is not a valid URI: " + str);
41      }
42    });
43
44    if (host.isPresent()) {
45      return host.get();
46    }
47
48    Optional<Integer> port = config.getInt("distributor", "port");
49    Optional<String> hostname = config.get("distributor", "hostname");
50
51    if (!(port.isPresent() && hostname.isPresent())) {
52      throw new ConfigException("Unable to determine host and port for the distributor");
53    }
54
55    try {
56      return new URI(
57          "http",
58          null,
59          hostname.get(),
60          port.get(),
61          null,
62          null,
63          null);
64    } catch (URISyntaxException e) {
65      throw new ConfigException(
66          "Distributor uri configured through host (%s) and port (%d) is not a valid URI",
67          hostname.get(),
68          port.get());
69    }
70  }
71}
72
Full Screen
copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium.grid.sessionmap;
19
20import org.openqa.selenium.grid.config.Config;
21import org.openqa.selenium.grid.config.ConfigException;
22
23import java.net.URI;
24import java.net.URISyntaxException;
25import java.util.Optional;
26
27public class SessionMapOptions {
28
29  private final Config config;
30
31  public SessionMapOptions(Config config) {
32    this.config = config;
33  }
34
35  public URI getSessionMapUri() {
36    Optional<URI> host = config.get("sessions", "host").map(str -> {
37      try {
38        return new URI(str);
39      } catch (URISyntaxException e) {
40        throw new ConfigException("Sesion map server URI is not a valid URI: " + str);
41      }
42    });
43
44    if (host.isPresent()) {
45      return host.get();
46    }
47
48    Optional<Integer> port = config.getInt("sessions", "port");
49    Optional<String> hostname = config.get("sessions", "hostname");
50
51    if (!(port.isPresent() && hostname.isPresent())) {
52      throw new ConfigException("Unable to determine host and port for the session map server");
53    }
54
55    try {
56      return new URI(
57          "http",
58          null,
59          hostname.get(),
60          port.get(),
61          null,
62          null,
63          null);
64    } catch (URISyntaxException e) {
65      throw new ConfigException(
66          "Session map server uri configured through host (%s) and port (%d) is not a valid URI",
67          hostname.get(),
68          port.get());
69    }
70  }
71}
72
Full Screen
copy
1//addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.0")
2addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.9")
3
Full Screen
copy
1[info] Set current project to helloworld (in build file:/Users/suniltonger/Projects/play/helloworld/helloworld/)
2java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0
3    at java.lang.ClassLoader.defineClass1(Native Method)
4    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
5    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
6    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
7    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
8    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
9    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
10    at java.security.AccessController.doPrivileged(Native Method)
11    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
12    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
13    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
14    at com.typesafe.sbt.web.SbtWeb$$anonfun$com$typesafe$sbt$web$SbtWeb$$load$1.apply(SbtWeb.scala:559)
15    at com.typesafe.sbt.web.SbtWeb$$anonfun$com$typesafe$sbt$web$SbtWeb$$load$1.apply(SbtWeb.scala:559)
16    at scala.Option.fold(Option.scala:157)
17    at com.typesafe.sbt.web.SbtWeb$.com$typesafe$sbt$web$SbtWeb$$load(SbtWeb.scala:573)
18    at com.typesafe.sbt.web.SbtWeb$$anonfun$globalSettings$1$$anonfun$apply$1.apply(SbtWeb.scala:143)
19    at com.typesafe.sbt.web.SbtWeb$$anonfun$globalSettings$1$$anonfun$apply$1.apply(SbtWeb.scala:143)
20    at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:55)
21    at sbt.Project$.setProject(Project.scala:319)
22    at sbt.BuiltinCommands$.doLoadProject(Main.scala:503)
23    at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:484)
24    at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:484)
25    at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
26    at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
27    at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
28    at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
29    at sbt.Command$.process(Command.scala:93)
30    at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
31    at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
32    at sbt.State$$anon$1.process(State.scala:184)
33    at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
34    at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
35    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
36    at sbt.MainLoop$.next(MainLoop.scala:96)
37    at sbt.MainLoop$.run(MainLoop.scala:89)
38    at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68)
39    at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63)
40    at sbt.Using.apply(Using.scala:24)
41    at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63)
42    at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46)
43    at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30)
44    at sbt.MainLoop$.runLogged(MainLoop.scala:22)
45    at sbt.StandardMain$.runManaged(Main.scala:54)
46    at sbt.xMain.run(Main.scala:29)
47    at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
48    at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
49    at xsbt.boot.Launch$.run(Launch.scala:109)
50    at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
51    at xsbt.boot.Launch$.launch(Launch.scala:117)
52    at xsbt.boot.Launch$.apply(Launch.scala:18)
53    at xsbt.boot.Boot$.runImpl(Boot.scala:41)
54    at xsbt.boot.Boot$.main(Boot.scala:17)
55    at xsbt.boot.Boot.main(Boot.scala)
56[error] java.lang.UnsupportedClassVersionError: com/typesafe/config/ConfigException : Unsupported major.minor version 52.0
57[error] Use 'last' for the full log.
58[debug] > load-failed
59
Full Screen
copy
1org.mortbay.jetty:jetty:jar:6.1.16:compile
2
Full Screen
copy
1<dependency>
2    <groupId>org.eclipse.jetty</groupId>
3    <artifactId>jetty-server</artifactId>
4    <version>9.3.0.M0</version>
5</dependency>
6
Full Screen
copy
1  @Override
2  public Integer getInteger(String component, String key, int defaultValue)
3              throws ConfigException {
4      return Integer.parseInt(getString(component, key, String.valueOf(defaultValue)));
5  }
6
Full Screen
copy
1public Optional<String> getString(String component, String key) throws ConfigException { ...
2
3public Optional<Integer> getInteger(String component, String key) throws ConfigException {
4
5int value = getInteger(component, key).orElse(defaultValue);
6
Full Screen
copy
1private <T> T getT(String component, String key, T defaultValue, Function<String, T> parser) {
2    try {
3        return parser.apply(this.getString(component, key, String.valueOf(defaultValue)));
4    } catch (Exception e) {
5        logger.log(Level.SEVERE, e.getMessage(), e);
6        throw new ConfigException(e.getMessage(), e.getCause());
7    }
8}
9
Full Screen
copy
1public Integer getInteger(String component, String key, int defaultValue) throws ConfigException {
2    return getT(component, key, defaultValue, Integer::parseInt);
3}
4
5public Double getDouble(String component, String key, double defaultValue) throws ConfigException {
6    return getT(component, key, defaultValue, Double::parseDouble);
7}
8
9public Boolean getBoolean(String component, String key, boolean defaultValue) throws ConfigException {
10    return getT(component, key, defaultValue, Boolean::parseBoolean);
11}
12
Full Screen
copy
1public <T> T getValue(String component, String key, T defaultValue, Function<String, T> parser) throws ConfigException {
2    try {
3        String value = this.getString( component, key, String.valueOf(defaultValue) );
4        return parser.apply(value);
5      } catch (Exception e) {
6        logger.log(Level.SEVERE, e.getMessage(), e);
7        throw new ConfigException( e.getMessage(), e.getCause() );
8      }
9}
10
11public Integer getInteger(String component, String key, int defaultValue) throws ConfigException {
12    return getValue(component, key, defaultValue, Integer::parseInt );
13}
14
15public Double  getDouble(String component, String key, double defaultValue) throws ConfigException {
16    return getValue(component, key, defaultValue, Double::parseDouble );
17}
18
19public Boolean getBoolean (String component, String key, boolean defaultValue) throws ConfigException {
20    return getValue(component, key, defaultValue, Boolean::parseBoolean);
21}
22
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in ConfigException

    No methods found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)