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

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

Source:CompletionCommand.java Github

copy

Full Screen

...20import com.beust.jcommander.Parameters;21import com.beust.jcommander.internal.DefaultConsole;22import com.google.auto.service.AutoService;23import org.openqa.selenium.cli.CliCommand;24import org.openqa.selenium.grid.config.DescribedOption;25import org.openqa.selenium.grid.config.Role;26import org.openqa.selenium.grid.server.HelpFlags;27import java.io.PrintStream;28import java.util.AbstractMap;29import java.util.Collections;30import java.util.Comparator;31import java.util.Map;32import java.util.ServiceLoader;33import java.util.Set;34import java.util.stream.Collectors;35import java.util.stream.StreamSupport;36import static java.util.stream.Collectors.joining;37import static org.openqa.selenium.grid.config.StandardGridRoles.ALL_ROLES;38@AutoService(CliCommand.class)39public class CompletionCommand implements CliCommand {40 @Override41 public String getName() {42 return "completion";43 }44 @Override45 public String getDescription() {46 return "Generate shell autocompletions";47 }48 @Override49 public Set<Role> getConfigurableRoles() {50 return ALL_ROLES;51 }52 @Override53 public Set<Object> getFlagObjects() {54 return Collections.singleton(new HelpFlags());55 }56 @Override57 public Executable configure(PrintStream out, PrintStream err, String... args) {58 HelpFlags help = new HelpFlags();59 Zsh zsh = new Zsh();60 JCommander commander = JCommander.newBuilder()61 .programName("selenium")62 .addObject(help)63 .addCommand(zsh)64 .build();65 commander.setConsole(new DefaultConsole(out));66 return () -> {67 try {68 commander.parse(args);69 } catch (ParameterException e) {70 err.println(e.getMessage());71 commander.usage();72 return;73 }74 if (help.displayHelp(commander, out)) {75 return;76 }77 if (args.length == 0) {78 commander.parse();79 }80 switch (commander.getParsedCommand()) {81 case "zsh":82 outputZshCompletions(out);83 break;84 default:85 err.println("Unrecognised shell: " + commander.getParsedCommand());86 System.exit(1);87 break;88 }89 };90 }91 private void outputZshCompletions(PrintStream out) {92 Map<CliCommand, Set<DescribedOption>> allCommands = listKnownCommands();93 // My kingdom for multiline strings94 out.println("#compdef selenium");95 out.println("local context state state_descr line");96 out.println("typeset -A opt_args");97 out.println("_selenium() {");98 out.println(" _arguments -C \\");99 out.println(" '(- :)--ext[Amend the classpath for Grid]: :->arg' \\");100 out.println(" '(-): :->command' \\");101 out.println(" '(-)*:: :->arg' && return");102 out.println(" case $state in");103 out.println(" (command)");104 out.println(" local cmds");105 out.println(" cmds=(");106 allCommands.keySet().stream()107 .sorted(Comparator.comparing(CliCommand::getName))108 .forEach(cmd -> {109 out.println(String.format(" '%s:%s'", cmd.getName(), cmd.getDescription().replace("'", "\\'")));110 });111 out.println(" )");112 out.println(" _describe 'commands' cmds");113 out.println(" ;;");114 out.println(" (arg)");115 out.println(" case ${words[1]} in");116 allCommands.keySet().stream()117 .sorted(Comparator.comparing(CliCommand::getName))118 .forEach(cmd -> {119 String shellName = cmd.getName().replace('-', '_');120 out.println(String.format(" (%s)", cmd.getName()));121 out.println(String.format(" _selenium_%s", shellName));122 out.println(" ;;");123 });124 out.println(" esac");125 out.println(" ;;");126 out.println(" esac");127 out.println("}\n\n");128 allCommands.forEach((cmd, options) -> {129 out.println(String.format("_selenium_%s() {", cmd.getName().replace('-', '_')));130 out.println(" args=(");131 options.stream()132 .filter(opt -> !opt.flags().isEmpty())133 .sorted(Comparator.comparing(opt -> opt.flags().iterator().next()))134 .forEach(opt -> {135 String quotedDesc = opt.description.replace("'", "\\''").replace(":", "\\:");136 if (opt.flags().size() == 1) {137 out.println(String.format(" '%s[%s]%s'", opt.flags().iterator().next(), quotedDesc, getZshType(opt)));138 } else {139 out.print(" '");140 out.print(opt.flags.stream().collect(joining(" ", "(", ")")));141 out.print("'");142 out.print(opt.flags.stream().collect(joining(",", "{", "}")));143 out.print("'");144 out.print(String.format("[%s]", quotedDesc));145 out.print(getZshType(opt));146 out.print("'\n");147 }148 });149 out.println(" )");150 out.println(" _arguments $args && return");151 out.println("}\n\n");152 });153 out.println("_selenium");154 }155 private String getZshType(DescribedOption option) {156 switch (option.type) {157 case "boolean":158 return ":(true false)";159 case "int":160 return ":int";161 case "list of strings":162 case "string":163 return ": ";164 case "uri":165 case "url":166 return ":urls: ";167 case "path":168 return ":filename:_files";169 default:170 throw new IllegalStateException("Unknown type: " + option.type);171 }172 }173 private Map<CliCommand, Set<DescribedOption>> listKnownCommands() {174 return StreamSupport.stream(ServiceLoader.load(CliCommand.class).spliterator(), true)175 .map(command -> new AbstractMap.SimpleEntry<>(176 command,177 DescribedOption.findAllMatchingOptions(command.getConfigurableRoles())))178 .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));179 }180 @Parameters(commandNames = "zsh", commandDescription = "Create autocompletions for zsh")181 private static class Zsh {}182}...

Full Screen

Full Screen

Source:ConfigFlags.java Github

copy

Full Screen

...70 public boolean dumpConfigHelp(Config config, Set<Role> currentRoles, PrintStream dumpTo) {71 if (!dumpConfigHelp) {72 return false;73 }74 Map<String, Set<DescribedOption>> allOptions = DescribedOption.findAllMatchingOptions(currentRoles).stream()75 .collect(Collectors.toMap(76 DescribedOption::section,77 ImmutableSortedSet::of,78 (l, r) -> ImmutableSortedSet.<DescribedOption>naturalOrder().addAll(l).addAll(r).build()));79 StringBuilder demoToml = new StringBuilder();80 allOptions.forEach((section, options) -> {81 demoToml.append("[").append(section).append("]\n");82 options.forEach(option -> {83 if (!option.optionName.isEmpty()) {84 demoToml.append("# ").append(option.description).append("\n");85 }86 demoToml.append("# Type: ").append(option.type).append("\n");87 demoToml.append(option.optionName).append(" = ").append(option.example(config)).append("\n\n");88 });89 demoToml.append("\n");90 });91 dumpTo.print(demoToml);92 return true;...

Full Screen

Full Screen

DescribedOption

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.grid.config;2import static java.nio.charset.StandardCharsets.UTF_8;3import static java.util.Collections.emptyList;4import static java.util.Collections.emptyMap;5import static java.util.Collections.singletonList;6import static java.util.logging.Level.FINE;7import static java.util.logging.Level.FINER;8import static java.util.logging.Level.FINEST;9import static java.util.logging.Level.INFO;10import static java.util.logging.Level.SEVERE;11import static java.util.logging.Level.WARNING;12import static java.util.stream.Collectors.joining;13import static java.util.stream.Collectors.toList;14import static org.openqa.selenium.grid.config.StandardGridRoles.NODE_ROLE;15import static org.openqa.selenium.grid.config.StandardGridRoles.SERVER_ROLE;16import static org.openqa.selenium.grid.config.StandardGridRoles.getRoles;17import com.beust.jcommander.JCommander;18import com.beust.jcommander.Parameter;19import com.beust.jcommander.ParameterException;20import com.google.auto.service.AutoService;21import com.google.common.collect.ImmutableList;22import com.google.common.collect.ImmutableMap;23import com.google.common.collect.ImmutableSet;24import com.google.common.collect.ImmutableSortedSet;25import com.google.common.collect.Maps;26import com.google.common.collect.Sets;27import com.google.common.io.CharStreams;28import com.google.common.io.Files;29import com.google.common.io.Resources;30import com.google.common.reflect.ClassPath;31import com.google.common.reflect.ClassPath.ClassInfo;32import com.google.common.reflect.ClassPath.ResourceInfo;33import com.google.common.reflect.Reflection;34import com.google.common.util.concurrent.Uninterruptibles;35import com.google.gson.Gson;36import com.google.gson

Full Screen

Full Screen

DescribedOption

Using AI Code Generation

copy

Full Screen

1public class DescribedOption {2public DescribedOption(String name, String description) {3 this.name = name;4 this.description = description;5}6public String getName() {7 return name;8}9public String getDescription() {10 return description;11}12private final String name;13private final String description;14}15public class DescribedOptions implements Iterable<DescribedOption> {16public DescribedOptions(DescribedOption... options) {17 this.options = Arrays.asList(options);18}19public DescribedOptions(Collection<DescribedOption> options) {20 this.options = new ArrayList<>(options);21}22public List<DescribedOption> getOptions() {23 return Collections.unmodifiableList(options);24}25public Iterator<DescribedOption> iterator() {26 return options.iterator();27}28private final List<DescribedOption> options;29}30public class OptionSet implements Iterable<Option> {31public OptionSet(Option... options) {32 this.options = Arrays.asList(options);33}34public OptionSet(Collection<Option> options) {35 this.options = new ArrayList<>(options);36}37public List<Option> getOptions() {38 return Collections.unmodifiableList(options);39}40public Iterator<Option> iterator() {41 return options.iterator();42}43private final List<Option> options;44}45public class Option {46public Option(String name, String description, boolean required) {47 this.name = name;48 this.description = description;49 this.required = required;50}51public String getName() {52 return name;53}54public String getDescription() {55 return description;56}57public boolean isRequired() {58 return required;59}60private final String name;61private final String description;62private final boolean required;63}64public class OptionParser {65public OptionParser(DescribedOptions options, String... args) {66 this.options = options;67 this.args = args;68}69public Map<String, String> parse() {70 Map<String, String> result = new HashMap<>();71 Iterator<String> argIterator = Arrays.asList(args).iterator();72 while (argIterator.hasNext()) {73 String arg = argIterator.next();74 if (arg.startsWith("--")) {75 String key = arg.substring(2);

Full Screen

Full Screen

DescribedOption

Using AI Code Generation

copy

Full Screen

1DescribedOption option = new DescribedOption("name", "description");2option.addChoice("choice1", "description of choice1");3option.addChoice("choice2", "description of choice2");4option.addChoice("choice3", "description of choice3");5option.addChoice("choice4", "description of choice4");6option.addChoice("choice5", "description of choice5");7option.addChoice("choice6", "description of choice6");8option.addChoice("choice7", "description of choice7");9option.addChoice("choice8", "description of choice8");10option.addChoice("choice9", "description of choice9");11option.addChoice("choice10", "description of choice10");12option.addChoice("choice11", "description of choice11");13option.addChoice("choice12", "description of choice12");14option.addChoice("choice13", "description of choice13");15option.addChoice("choice14", "description of choice14");16option.addChoice("choice15", "description of choice15");17option.addChoice("choice16", "description of choice16");18option.addChoice("choice17", "description of choice17");19option.addChoice("choice18", "description of choice18");20option.addChoice("choice19", "description of choice19");21option.addChoice("choice20", "description of choice20");22option.addChoice("choice21", "description of choice21");23option.addChoice("choice22", "description of choice22");24option.addChoice("choice23", "description of choice23");25option.addChoice("choice24", "description of choice24");26option.addChoice("choice25", "description of choice25");27option.addChoice("choice26", "description of choice26");28option.addChoice("choice27", "description of choice27");29option.addChoice("choice28", "description of choice28");30option.addChoice("choice29", "description of choice29");31option.addChoice("choice30", "description of choice30");32option.addChoice("choice31", "description of choice31");33option.addChoice("choice32", "description of choice32");34option.addChoice("choice33", "description of choice33");35option.addChoice("choice34", "description of choice34");36option.addChoice("choice35", "description of choice35");37option.addChoice("choice36", "description of choice36");38option.addChoice("choice37", "description of choice37");

Full Screen

Full Screen

DescribedOption

Using AI Code Generation

copy

Full Screen

1public class MyConfig extends Config {2 public MyConfig(Path path) {3 super(path);4 }5 public String getBrowser() {6 return get("browser", "chrome");7 }8}9public class MyConfigTest {10 public void testMyConfig() {11 MyConfig config = new MyConfig(Paths.get("src/test/resources/config.json"));12 assertThat(config.getBrowser()).isEqualTo("chrome");13 }14}15{16}17{18}19{20}21{22}23{24}25{26}27{28}29{30}31{32}33{34}35{36}37{38}39{40}41{42}43{44}45{46}47{48}49{50}51{52}53{54}55{56}57{58}59{60}61{62}63{

Full Screen

Full Screen

Selenium 4 Tutorial:

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.

Chapters:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

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

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful