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

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

Run Selenium automation tests on LambdaTest cloud grid

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

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;
19
20import com.beust.jcommander.JCommander;
21import com.beust.jcommander.ParameterException;
22import com.beust.jcommander.internal.DefaultConsole;
23import com.google.common.collect.Sets;
24import org.openqa.selenium.cli.CliCommand;
25import org.openqa.selenium.grid.config.AnnotatedConfig;
26import org.openqa.selenium.grid.config.CompoundConfig;
27import org.openqa.selenium.grid.config.ConcatenatingConfig;
28import org.openqa.selenium.grid.config.Config;
29import org.openqa.selenium.grid.config.ConfigFlags;
30import org.openqa.selenium.grid.config.EnvConfig;
31import org.openqa.selenium.grid.config.HasRoles;
32import org.openqa.selenium.grid.config.MemoizedConfig;
33import org.openqa.selenium.grid.log.LoggingOptions;
34import org.openqa.selenium.grid.server.HelpFlags;
35
36import java.io.PrintStream;
37import java.util.LinkedHashSet;
38import java.util.ServiceLoader;
39import java.util.Set;
40import java.util.stream.StreamSupport;
41
42public abstract class TemplateGridCommand implements CliCommand {
43
44  @Override
45  public final Executable configure(PrintStream out, PrintStream err, String... args) {
46    HelpFlags helpFlags = new HelpFlags();
47    ConfigFlags configFlags = new ConfigFlags();
48
49    Set<Object> allFlags = new LinkedHashSet<>();
50
51    allFlags.add(helpFlags);
52    allFlags.add(configFlags);
53
54    StreamSupport.stream(ServiceLoader.load(HasRoles.class).spliterator(), true)
55      .filter(flags -> !Sets.intersection(getConfigurableRoles(), flags.getRoles()).isEmpty())
56      .forEach(allFlags::add);
57
58    allFlags.addAll(getFlagObjects());
59
60    JCommander.Builder builder = JCommander.newBuilder().programName(getName());
61    allFlags.forEach(builder::addObject);
62    JCommander commander = builder.build();
63    commander.setConsole(new DefaultConsole(out));
64
65    return () -> {
66      try {
67        commander.parse(args);
68      } catch (ParameterException e) {
69        err.println(e.getMessage());
70        commander.usage();
71        return;
72      }
73
74      if (helpFlags.displayHelp(commander, out)) {
75        return;
76      }
77
78      Set<Config> allConfigs = new LinkedHashSet<>();
79      allConfigs.add(new EnvConfig());
80      allConfigs.add(new ConcatenatingConfig(getSystemPropertiesConfigPrefix(), '.', System.getProperties()));
81      allFlags.forEach(flags -> allConfigs.add(new AnnotatedConfig(flags)));
82      allConfigs.add(configFlags.readConfigFiles());
83      allConfigs.add(getDefaultConfig());
84
85      Config config = new MemoizedConfig(new CompoundConfig(allConfigs.toArray(new Config[0])));
86
87      if (configFlags.dumpConfig(config, out)) {
88        return;
89      }
90
91      if (configFlags.dumpConfigHelp(config, getConfigurableRoles(), out)) {
92        return;
93      }
94
95      LoggingOptions loggingOptions = new LoggingOptions(config);
96      loggingOptions.configureLogging();
97
98      execute(config);
99    };
100  }
101
102  protected abstract String getSystemPropertiesConfigPrefix();
103
104  protected abstract Config getDefaultConfig();
105
106  protected abstract void execute(Config config);
107}
108
Full Screen
copy
1Activates various annotations to be detected in bean classes: Spring's @Required and
2@Autowired, as well as JSR 250's @PostConstruct, @PreDestroy and @Resource (if available),
3JAX-WS's @WebServiceRef (if available), EJB 3's @EJB (if available), and JPA's
4@PersistenceContext and @PersistenceUnit (if available). Alternatively, you may
5choose to activate the individual BeanPostProcessors for those annotations.
6
7Note: This tag does not activate processing of Spring's @Transactional or EJB 3's
8@TransactionAttribute annotation. Consider the use of the <tx:annotation-driven>
9tag for that purpose.
10
Full Screen
copy
1Scans the classpath for annotated components that will be auto-registered as
2Spring beans. By default, the Spring-provided @Component, @Repository, @Service, @Controller, @RestController, @ControllerAdvice, and @Configuration stereotypes    will be detected.
3
4Note: This tag implies the effects of the 'annotation-config' tag, activating @Required,
5@Autowired, @PostConstruct, @PreDestroy, @Resource, @PersistenceContext and @PersistenceUnit
6annotations in the component classes, which is usually desired for autodetected components
7(without external configuration). Turn off the 'annotation-config' attribute to deactivate
8this default behavior, for example in order to use custom BeanPostProcessor definitions
9for handling those annotations.
10
11Note: You may use placeholders in package paths, but only resolved against system
12properties (analogous to resource paths). A component scan results in new bean definitions
13being registered; Spring's PropertySourcesPlaceholderConfigurer will apply to those bean
14definitions just like to regular bean definitions, but it won't apply to the component
15scan settings themselves.
16
Full Screen
copy
1<context:component-scan basePackages="" annotation-config="false"/>
2
Full Screen
copy
1<context:annotation-config/> <!-- is used to activate the annotation for beans -->
2<context:component-scan base-package="x.y.MyClass" /> <!-- is for the Spring IOC container to look for the beans in the base package. -->
3
Full Screen
copy
1<context:annotation-config/> <!-- activates the annotations --> 
2<context:component-scan base-package="x.y.MyClass" /> <!-- activates the annotations + register the beans by looking inside the base-package -->
3
Full Screen
copy
1<context:component-scan /> implicitly enables <context:annotation-config/>
2
Full Screen
copy
1<bean id="serviceBeanA" class="com.something.CarServiceImpl" />
2<bean id="serviceBeanB" class="com.something.PersonServiceImpl" />
3<bean id="repositoryBeanA" class="com.something.CarRepository" />
4<bean id="repositoryBeanB" class="com.something.PersonRepository" />
5
Full Screen
copy
1<context:component-scan base-package="org.package"/> 
2
Full Screen
copy
1package com.xxx;
2public class B {
3  public B() {
4    System.out.println("creating bean B: " + this);
5  }
6}
7
8package com.xxx;
9public class C {
10  public C() {
11    System.out.println("creating bean C: " + this);
12  }
13}
14
15package com.yyy;
16import com.xxx.B;
17import com.xxx.C;
18public class A { 
19  private B bbb;
20  private C ccc;
21  public A() {
22    System.out.println("creating bean A: " + this);
23  }
24  public void setBbb(B bbb) {
25    System.out.println("setting A.bbb with " + bbb);
26    this.bbb = bbb;
27  }
28  public void setCcc(C ccc) {
29    System.out.println("setting A.ccc with " + ccc);
30    this.ccc = ccc; 
31  }
32}
33
Full Screen
copy
1<bean id="bBean" class="com.xxx.B" />
2<bean id="cBean" class="com.xxx.C" />
3<bean id="aBean" class="com.yyy.A">
4  <property name="bbb" ref="bBean" />
5  <property name="ccc" ref="cBean" />
6</bean>
7
Full Screen
copy
1package com.yyy;
2import org.springframework.beans.factory.annotation.Autowired;
3import com.xxx.B;
4import com.xxx.C;
5public class A { 
6  private B bbb;
7  private C ccc;
8  public A() {
9    System.out.println("creating bean A: " + this);
10  }
11  @Autowired
12  public void setBbb(B bbb) {
13    System.out.println("setting A.bbb with " + bbb);
14    this.bbb = bbb;
15  }
16  @Autowired
17  public void setCcc(C ccc) {
18    System.out.println("setting A.ccc with " + ccc);
19    this.ccc = ccc;
20  }
21}
22
Full Screen
copy
1<property name="bbb" ref="bBean" />
2<property name="ccc" ref="cBean" />
3
Full Screen
copy
1<bean id="bBean" class="com.xxx.B" />
2<bean id="cBean" class="com.xxx.C" />
3<bean id="aBean" class="com.yyy.A" />
4
Full Screen
copy
1<context:annotation-config />
2<bean id="bBean" class="com.xxx.B" />
3<bean id="cBean" class="com.xxx.C" />
4<bean id="aBean" class="com.yyy.A" />
5
Full Screen
copy
1package com.xxx;
2import org.springframework.stereotype.Component;
3@Component
4public class B {
5  public B() {
6    System.out.println("creating bean B: " + this);
7  }
8}
9
10package com.xxx;
11import org.springframework.stereotype.Component;
12@Component
13public class C {
14  public C() {
15    System.out.println("creating bean C: " + this);
16  }
17}
18
19package com.yyy;
20import org.springframework.beans.factory.annotation.Autowired;
21import org.springframework.stereotype.Component;
22import com.xxx.B;
23import com.xxx.C;
24@Component
25public class A { 
26  private B bbb;
27  private C ccc;
28  public A() {
29    System.out.println("creating bean A: " + this);
30  }
31  @Autowired
32  public void setBbb(B bbb) {
33    System.out.println("setting A.bbb with " + bbb);
34    this.bbb = bbb;
35  }
36  @Autowired
37  public void setCcc(C ccc) {
38    System.out.println("setting A.ccc with " + ccc);
39    this.ccc = ccc;
40  }
41}
42
Full Screen
copy
1<context:component-scan base-package="com.xxx,com.yyy" />
2
Full Screen
copy
1<context:component-scan base-package="com.xxx" />
2<bean id="aBean" class="com.yyy.A" />
3
Full Screen
copy
1<context:annotation-config />
2<context:component-scan base-package="com.xxx" />
3<bean id="aBean" class="com.yyy.A" />
4
Full Screen
copy
1<context:annotation-config />
2<context:component-scan base-package="com.xxx" />
3<bean id="aBean" class="com.yyy.A" />
4<bean id="bla" class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
5<bean id="bla1" class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
6<bean id="bla2" class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
7<bean id="bla3" class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
8
Full Screen
copy
1@EqualsAndHashCode(callSuper = false, of = { "field1", "field2", "field3" })
2
Full Screen
copy
1Activates various annotations to be detected in bean classes: Spring's @Required and
2@Autowired, as well as JSR 250's @PostConstruct, @PreDestroy and @Resource (if available),
3JAX-WS's @WebServiceRef (if available), EJB 3's @EJB (if available), and JPA's
4@PersistenceContext and @PersistenceUnit (if available). Alternatively, you may
5choose to activate the individual BeanPostProcessors for those annotations.
6
7Note: This tag does not activate processing of Spring's @Transactional or EJB 3's
8@TransactionAttribute annotation. Consider the use of the <tx:annotation-driven>
9tag for that purpose.
10
Full Screen
copy
1Scans the classpath for annotated components that will be auto-registered as
2Spring beans. By default, the Spring-provided @Component, @Repository, @Service, @Controller, @RestController, @ControllerAdvice, and @Configuration stereotypes    will be detected.
3
4Note: This tag implies the effects of the 'annotation-config' tag, activating @Required,
5@Autowired, @PostConstruct, @PreDestroy, @Resource, @PersistenceContext and @PersistenceUnit
6annotations in the component classes, which is usually desired for autodetected components
7(without external configuration). Turn off the 'annotation-config' attribute to deactivate
8this default behavior, for example in order to use custom BeanPostProcessor definitions
9for handling those annotations.
10
11Note: You may use placeholders in package paths, but only resolved against system
12properties (analogous to resource paths). A component scan results in new bean definitions
13being registered; Spring's PropertySourcesPlaceholderConfigurer will apply to those bean
14definitions just like to regular bean definitions, but it won't apply to the component
15scan settings themselves.
16
Full Screen
copy
1<context:component-scan basePackages="" annotation-config="false"/>
2
Full Screen
copy
1<context:annotation-config/> <!-- is used to activate the annotation for beans -->
2<context:component-scan base-package="x.y.MyClass" /> <!-- is for the Spring IOC container to look for the beans in the base package. -->
3
Full Screen
copy
1<context:annotation-config/> <!-- activates the annotations --> 
2<context:component-scan base-package="x.y.MyClass" /> <!-- activates the annotations + register the beans by looking inside the base-package -->
3
Full Screen
copy
1<context:component-scan /> implicitly enables <context:annotation-config/>
2
Full Screen
copy
1<bean id="serviceBeanA" class="com.something.CarServiceImpl" />
2<bean id="serviceBeanB" class="com.something.PersonServiceImpl" />
3<bean id="repositoryBeanA" class="com.something.CarRepository" />
4<bean id="repositoryBeanB" class="com.something.PersonRepository" />
5
Full Screen
copy
1<context:component-scan base-package="org.package"/> 
2
Full Screen
copy
1package com.xxx;
2public class B {
3  public B() {
4    System.out.println("creating bean B: " + this);
5  }
6}
7
8package com.xxx;
9public class C {
10  public C() {
11    System.out.println("creating bean C: " + this);
12  }
13}
14
15package com.yyy;
16import com.xxx.B;
17import com.xxx.C;
18public class A { 
19  private B bbb;
20  private C ccc;
21  public A() {
22    System.out.println("creating bean A: " + this);
23  }
24  public void setBbb(B bbb) {
25    System.out.println("setting A.bbb with " + bbb);
26    this.bbb = bbb;
27  }
28  public void setCcc(C ccc) {
29    System.out.println("setting A.ccc with " + ccc);
30    this.ccc = ccc; 
31  }
32}
33
Full Screen
copy
1<bean id="bBean" class="com.xxx.B" />
2<bean id="cBean" class="com.xxx.C" />
3<bean id="aBean" class="com.yyy.A">
4  <property name="bbb" ref="bBean" />
5  <property name="ccc" ref="cBean" />
6</bean>
7
Full Screen
copy
1package com.yyy;
2import org.springframework.beans.factory.annotation.Autowired;
3import com.xxx.B;
4import com.xxx.C;
5public class A { 
6  private B bbb;
7  private C ccc;
8  public A() {
9    System.out.println("creating bean A: " + this);
10  }
11  @Autowired
12  public void setBbb(B bbb) {
13    System.out.println("setting A.bbb with " + bbb);
14    this.bbb = bbb;
15  }
16  @Autowired
17  public void setCcc(C ccc) {
18    System.out.println("setting A.ccc with " + ccc);
19    this.ccc = ccc;
20  }
21}
22
Full Screen
copy
1<property name="bbb" ref="bBean" />
2<property name="ccc" ref="cBean" />
3
Full Screen
copy
1<bean id="bBean" class="com.xxx.B" />
2<bean id="cBean" class="com.xxx.C" />
3<bean id="aBean" class="com.yyy.A" />
4
Full Screen
copy
1<context:annotation-config />
2<bean id="bBean" class="com.xxx.B" />
3<bean id="cBean" class="com.xxx.C" />
4<bean id="aBean" class="com.yyy.A" />
5
Full Screen
copy
1package com.xxx;
2import org.springframework.stereotype.Component;
3@Component
4public class B {
5  public B() {
6    System.out.println("creating bean B: " + this);
7  }
8}
9
10package com.xxx;
11import org.springframework.stereotype.Component;
12@Component
13public class C {
14  public C() {
15    System.out.println("creating bean C: " + this);
16  }
17}
18
19package com.yyy;
20import org.springframework.beans.factory.annotation.Autowired;
21import org.springframework.stereotype.Component;
22import com.xxx.B;
23import com.xxx.C;
24@Component
25public class A { 
26  private B bbb;
27  private C ccc;
28  public A() {
29    System.out.println("creating bean A: " + this);
30  }
31  @Autowired
32  public void setBbb(B bbb) {
33    System.out.println("setting A.bbb with " + bbb);
34    this.bbb = bbb;
35  }
36  @Autowired
37  public void setCcc(C ccc) {
38    System.out.println("setting A.ccc with " + ccc);
39    this.ccc = ccc;
40  }
41}
42
Full Screen
copy
1<context:component-scan base-package="com.xxx,com.yyy" />
2
Full Screen
copy
1<context:component-scan base-package="com.xxx" />
2<bean id="aBean" class="com.yyy.A" />
3
Full Screen
copy
1<context:annotation-config />
2<context:component-scan base-package="com.xxx" />
3<bean id="aBean" class="com.yyy.A" />
4
Full Screen
copy
1<context:annotation-config />
2<context:component-scan base-package="com.xxx" />
3<bean id="aBean" class="com.yyy.A" />
4<bean id="bla" class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
5<bean id="bla1" class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
6<bean id="bla2" class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
7<bean id="bla3" class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
8
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 Configs

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)