How to use BaseServerFlags class of org.openqa.selenium.grid.server package

Best Selenium code snippet using org.openqa.selenium.grid.server.BaseServerFlags

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.sessionmap.httpd;
19
20import static org.openqa.selenium.grid.web.Routes.matching;
21
22import com.google.auto.service.AutoService;
23
24import com.beust.jcommander.JCommander;
25import com.beust.jcommander.ParameterException;
26
27import org.openqa.selenium.cli.CliCommand;
28import org.openqa.selenium.events.EventBus;
29import org.openqa.selenium.grid.config.AnnotatedConfig;
30import org.openqa.selenium.grid.config.CompoundConfig;
31import org.openqa.selenium.grid.config.ConcatenatingConfig;
32import org.openqa.selenium.grid.config.Config;
33import org.openqa.selenium.grid.config.EnvConfig;
34import org.openqa.selenium.grid.server.BaseServer;
35import org.openqa.selenium.grid.server.BaseServerFlags;
36import org.openqa.selenium.grid.server.BaseServerOptions;
37import org.openqa.selenium.grid.server.EventBusConfig;
38import org.openqa.selenium.grid.server.EventBusFlags;
39import org.openqa.selenium.grid.server.HelpFlags;
40import org.openqa.selenium.grid.log.LoggingOptions;
41import org.openqa.selenium.grid.server.Server;
42import org.openqa.selenium.grid.server.W3CCommandHandler;
43import org.openqa.selenium.grid.sessionmap.SessionMap;
44import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap;
45import org.openqa.selenium.remote.tracing.DistributedTracer;
46import org.openqa.selenium.remote.tracing.GlobalDistributedTracer;
47
48@AutoService(CliCommand.class)
49public class SessionMapServer implements CliCommand {
50
51  @Override
52  public String getName() {
53    return "sessions";
54  }
55
56  @Override
57  public String getDescription() {
58    return "Adds this server as the session map in a selenium grid.";
59  }
60
61  @Override
62  public Executable configure(String... args) {
63
64    HelpFlags help = new HelpFlags();
65    BaseServerFlags serverFlags = new BaseServerFlags(5556);
66    EventBusFlags eventBusFlags = new EventBusFlags();
67
68    JCommander commander = JCommander.newBuilder()
69        .programName(getName())
70        .addObject(help)
71        .addObject(serverFlags)
72        .addObject(eventBusFlags)
73        .build();
74
75    return () -> {
76      try {
77        commander.parse(args);
78      } catch (ParameterException e) {
79        System.err.println(e.getMessage());
80        commander.usage();
81        return;
82      }
83
84      if (help.displayHelp(commander, System.out)) {
85        return;
86      }
87
88      Config config = new CompoundConfig(
89          new EnvConfig(),
90          new ConcatenatingConfig("sessions", '.', System.getProperties()),
91          new AnnotatedConfig(help),
92          new AnnotatedConfig(serverFlags),
93          new AnnotatedConfig(eventBusFlags),
94          new DefaultSessionMapConfig());
95
96      LoggingOptions loggingOptions = new LoggingOptions(config);
97      loggingOptions.configureLogging();
98
99      DistributedTracer tracer = loggingOptions.getTracer();
100      GlobalDistributedTracer.setInstance(tracer);
101
102      EventBusConfig events = new EventBusConfig(config);
103      EventBus bus = events.getEventBus();
104
105      SessionMap sessions = new LocalSessionMap(tracer, bus);
106
107      BaseServerOptions serverOptions = new BaseServerOptions(config);
108
109      Server<?> server = new BaseServer<>(serverOptions);
110      server.addRoute(matching(sessions).using(sessions).decorateWith(W3CCommandHandler::new));
111      server.start();
112    };
113  }
114}
115
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.distributor.httpd;
19
20import com.google.auto.service.AutoService;
21
22import com.beust.jcommander.JCommander;
23import com.beust.jcommander.ParameterException;
24
25import org.openqa.selenium.cli.CliCommand;
26import org.openqa.selenium.grid.config.AnnotatedConfig;
27import org.openqa.selenium.grid.config.CompoundConfig;
28import org.openqa.selenium.grid.config.ConcatenatingConfig;
29import org.openqa.selenium.grid.config.Config;
30import org.openqa.selenium.grid.config.EnvConfig;
31import org.openqa.selenium.grid.distributor.Distributor;
32import org.openqa.selenium.grid.distributor.local.LocalDistributor;
33import org.openqa.selenium.grid.server.BaseServer;
34import org.openqa.selenium.grid.server.BaseServerFlags;
35import org.openqa.selenium.grid.server.BaseServerOptions;
36import org.openqa.selenium.grid.server.HelpFlags;
37import org.openqa.selenium.grid.server.Server;
38import org.openqa.selenium.grid.server.W3CCommandHandler;
39import org.openqa.selenium.grid.web.Routes;
40import org.openqa.selenium.remote.tracing.DistributedTracer;
41
42
43@AutoService(CliCommand.class)
44public class DistributorServer implements CliCommand {
45
46  @Override
47  public String getName() {
48    return "distributor";
49  }
50
51  @Override
52  public String getDescription() {
53    return "Adds this server as the distributor in a selenium grid.";
54  }
55
56  @Override
57  public Executable configure(String... args) {
58
59    HelpFlags help = new HelpFlags();
60    BaseServerFlags serverFlags = new BaseServerFlags(5553);
61
62    JCommander commander = JCommander.newBuilder()
63        .programName(getName())
64        .addObject(help)
65        .addObject(serverFlags)
66        .build();
67
68    return () -> {
69      try {
70        commander.parse(args);
71      } catch (ParameterException e) {
72        System.err.println(e.getMessage());
73        commander.usage();
74        return;
75      }
76
77      if (help.displayHelp(commander, System.out)) {
78        return;
79      }
80
81      Config config = new CompoundConfig(
82          new AnnotatedConfig(help),
83          new AnnotatedConfig(serverFlags),
84          new EnvConfig(),
85          new ConcatenatingConfig("distributor", '.', System.getProperties()));
86
87      DistributedTracer tracer = DistributedTracer.builder()
88          .registerDetectedTracers()
89          .build();
90
91      Distributor distributor = new LocalDistributor(tracer);
92
93      BaseServerOptions serverOptions = new BaseServerOptions(config);
94
95      Server<?> server = new BaseServer<>(tracer, serverOptions);
96      server.addRoute(
97          Routes.matching(distributor)
98              .using(distributor)
99              .decorateWith(W3CCommandHandler.class));
100      server.start();
101    };
102  }
103}
104
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 popular Stackoverflow questions on BaseServerFlags

    No relevant questions found for this class šŸ˜ž

Most used methods in BaseServerFlags

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)