How to use InfoCommand class of org.openqa.selenium.grid.commands package

Best Selenium code snippet using org.openqa.selenium.grid.commands.InfoCommand

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.commands;
19
20import com.beust.jcommander.JCommander;
21import com.beust.jcommander.ParameterException;
22import com.google.auto.service.AutoService;
23import com.google.common.io.Resources;
24
25import java.io.BufferedReader;
26import java.io.IOException;
27import java.io.PrintStream;
28import java.io.StringReader;
29import java.nio.charset.StandardCharsets;
30import org.openqa.selenium.cli.CliCommand;
31import org.openqa.selenium.cli.WrappedPrintWriter;
32import org.openqa.selenium.grid.server.HelpFlags;
33
34import java.io.PrintWriter;
35import java.util.Collections;
36
37@AutoService(CliCommand.class)
38public class InfoCommand implements CliCommand {
39
40  public String getName() {
41    return "info";
42  }
43
44  public String getDescription() {
45    return "Prints information for commands and topics.";
46  }
47
48  public Executable configure(PrintStream out, PrintStream err, String... args) {
49    HelpFlags help = new HelpFlags();
50    InfoFlags topic = new InfoFlags();
51
52    JCommander commander = JCommander.newBuilder()
53      .programName("selenium")
54      .addObject(help)
55      .addObject(topic)
56      .build();
57
58    return () -> {
59      try {
60        commander.parse(args);
61      } catch (ParameterException e) {
62        err.println(e.getMessage());
63        commander.usage();
64        return;
65      }
66
67      if (help.displayHelp(commander, out)) {
68        return;
69      }
70
71      String toDisplay;
72      String title;
73      switch (topic.topic) {
74        case "security":
75          title = "About Security";
76          toDisplay = "security.txt";
77          break;
78
79        case "tracing":
80          title = "About Tracing";
81          toDisplay = "tracing.txt";
82          break;
83
84        case "help":
85        case "info":
86        default:
87          title = "Info";
88          toDisplay = "info.txt";
89          break;
90      }
91
92      String path = getClass().getPackage().getName().replaceAll("\\.", "/") + "/" + toDisplay;
93      String content = readContent(path);
94
95      PrintWriter outWriter = new WrappedPrintWriter(out, 72, 0);
96
97      outWriter.printf("\n%s\n%s\n\n", title, String.join("", Collections.nCopies(title.length(), "=")));
98      outWriter.print(content);
99      outWriter.println("\n\n");
100    };
101  }
102
103  private String readContent(String path) throws IOException {
104    String unformattedText = Resources.toString(Resources.getResource(path), StandardCharsets.UTF_8);
105    StringBuilder formattedText = new StringBuilder();
106    try (BufferedReader reader = new BufferedReader(new StringReader(unformattedText))) {
107      boolean inCode = false;
108
109      for (String line = reader.readLine(); line != null; line = reader.readLine()) {
110        if (line.isEmpty()) {
111          if (inCode) {
112            formattedText.append("\n");
113          } else {
114            formattedText.append("\n\n");
115          }
116        } else if ("```".equals(line)) {
117          inCode = !inCode;
118        } else {
119          formattedText.append(line);
120          if (inCode || line.startsWith("* ")) {
121            formattedText.append("\n");
122          } else {
123            formattedText.append(" ");
124          }
125        }
126      }
127    }
128
129    return formattedText.toString();
130  }
131}
132
Full Screen
copy
1Component.text("My Clickable Text").color(NamedTextColor.GREEN).clickEvent(new ClickEvent(<paramaters>)
2
Full Screen
copy
1<dependency>
2        <groupId>org.spigotmc</groupId>
3        <artifactId>spigot-api</artifactId>
4        <version>1.12.2-R0.1-SNAPSHOT</version><!--change this value depending on the version-->
5        <type>jar</type>
6        <scope>provided</scope>
7</dependency>
8
Full Screen
copy
1import net.md_5.bungee.api.chat.ClickEvent;
2import net.md_5.bungee.api.chat.TextComponent;
3
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

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)