How to use addAlternative method of org.openqa.selenium.remote.RemoteWebDriverBuilder class

Best Selenium code snippet using org.openqa.selenium.remote.RemoteWebDriverBuilder.addAlternative

Source:RemoteWebDriverBuilder.java Github

copy

Full Screen

...58 * <p>59 * Expected usage is something like:60 * <pre>61 * WebDriver driver = RemoteWebDriver.builder()62 * .addAlternative(new FirefoxOptions())63 * .addAlternative(new ChromeOptions())64 * .addMetadata("cloud:key", "hunter2")65 * .setCapability("proxy", new Proxy())66 * .build();67 * </pre>68 * In this example, we ask for a session where the browser will be either Firefox or Chrome (we69 * don't care which), but where either browser will use the given {@link org.openqa.selenium.Proxy}.70 * In addition, we've added some metadata to the session, setting the "{@code cloud.key}" to be the71 * secret passphrase of our account with the cloud "Selenium as a Service" provider.72 * <p>73 * If no call to {@link #withDriverService(DriverService)} or {@link #url(URL)} is made, the builder74 * will use {@link ServiceLoader} to find all instances of {@link DriverService.Builder} and will75 * call {@link DriverService.Builder#score(Capabilities)} for each alternative until a new session76 * can be created.77 */78@Beta79public class RemoteWebDriverBuilder {80 private final static Set<String> ILLEGAL_METADATA_KEYS = ImmutableSet.of(81 "alwaysMatch",82 "capabilities",83 "firstMatch");84 private final static AcceptedW3CCapabilityKeys OK_KEYS = new AcceptedW3CCapabilityKeys();85 private final List<Map<String, Object>> options = new ArrayList<>();86 private final Map<String, Object> metadata = new TreeMap<>();87 private final Map<String, Object> additionalCapabilities = new TreeMap<>();88 private URL remoteHost;89 private DriverService service;90 RemoteWebDriverBuilder() {91 // Access through RemoteWebDriver.builder92 }93 /**94 * Clears the current set of alternative browsers and instead sets the list of possible choices to95 * the arguments given to this method.96 */97 public RemoteWebDriverBuilder oneOf(Capabilities maybeThis, Capabilities... orOneOfThese) {98 options.clear();99 addAlternative(maybeThis);100 for (Capabilities anOrOneOfThese : orOneOfThese) {101 addAlternative(anOrOneOfThese);102 }103 return this;104 }105 /**106 * Add to the list of possible configurations that might be asked for. It is possible to ask for107 * more than one type of browser per session. For example, perhaps you have an extension that is108 * available for two different kinds of browser, and you'd like to test it).109 */110 public RemoteWebDriverBuilder addAlternative(Capabilities options) {111 Map<String, Object> serialized = validate(Objects.requireNonNull(options));112 this.options.add(serialized);113 return this;114 }115 /**116 * Adds metadata to the outgoing new session request, which can be used by intermediary of end117 * nodes for any purpose they choose (commonly, this is used to request additional features from118 * cloud providers, such as video recordings or to set the timezone or screen size). Neither119 * parameter can be {@code null}.120 */121 public RemoteWebDriverBuilder addMetadata(String key, Object value) {122 if (ILLEGAL_METADATA_KEYS.contains(key)) {123 throw new IllegalArgumentException(key + " is a reserved key");124 }125 metadata.put(Objects.requireNonNull(key), Objects.requireNonNull(value));126 return this;127 }128 /**129 * Sets a capability for every single alternative when the session is created. These capabilities130 * are only set once the session is created, so this will be set on capabilities added via131 * {@link #addAlternative(Capabilities)} or {@link #oneOf(Capabilities, Capabilities...)} even132 * after this method call.133 */134 public RemoteWebDriverBuilder setCapability(String capabilityName, String value) {135 if (!OK_KEYS.test(capabilityName)) {136 throw new IllegalArgumentException("Capability is not valid");137 }138 if (value == null) {139 throw new IllegalArgumentException("Null values are not allowed");140 }141 additionalCapabilities.put(capabilityName, value);142 return this;143 }144 /**145 * @see #url(URL)...

Full Screen

Full Screen

addAlternative

Using AI Code Generation

copy

Full Screen

1final RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();2builder.addAlternative(new FirefoxDriver());3builder.addAlternative(new ChromeDriver());4builder.addAlternative(new InternetExplorerDriver());5builder.addAlternative(new EdgeDriver());6builder.addAlternative(new OperaDriver());7builder.addAlternative(new SafariDriver());8final RemoteWebDriver driver = builder.build();9final RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();10builder.addAlternative(new FirefoxDriver());11builder.addAlternative(new ChromeDriver());12builder.addAlternative(new InternetExplorerDriver());13builder.addAlternative(new EdgeDriver());14builder.addAlternative(new OperaDriver());15builder.addAlternative(new SafariDriver());16final RemoteWebDriver driver = builder.build();17final RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();18builder.addAlternative(new FirefoxDriver());19builder.addAlternative(new ChromeDriver());20builder.addAlternative(new InternetExplorerDriver());21builder.addAlternative(new EdgeDriver());22builder.addAlternative(new OperaDriver());23builder.addAlternative(new SafariDriver());24final RemoteWebDriver driver = builder.build();25final RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();26builder.addAlternative(new FirefoxDriver());27builder.addAlternative(new ChromeDriver());28builder.addAlternative(new InternetExplorerDriver());29builder.addAlternative(new EdgeDriver());30builder.addAlternative(new OperaDriver());31builder.addAlternative(new SafariDriver());32final RemoteWebDriver driver = builder.build();33final RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();34builder.addAlternative(new FirefoxDriver());35builder.addAlternative(new ChromeDriver());36builder.addAlternative(new InternetExplorerDriver());37builder.addAlternative(new EdgeDriver());38builder.addAlternative(new OperaDriver());39builder.addAlternative(new SafariDriver());40final RemoteWebDriver driver = builder.build();41final RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();42builder.addAlternative(new FirefoxDriver());43builder.addAlternative(new ChromeDriver());44builder.addAlternative(new InternetExplorerDriver());45builder.addAlternative(new EdgeDriver());46builder.addAlternative(new OperaDriver());47builder.addAlternative(new SafariDriver());

Full Screen

Full Screen

addAlternative

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.RemoteWebDriverBuilder;2RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder()3 .addAlternative(new RemoteWebDriverBuilder()4 .addAlternative(new ChromeDriver())5 .addAlternative(new FirefoxDriver()));6WebDriver driver = builder.build();7import org.openqa.selenium.remote.RemoteWebDriverBuilder;8RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder()9 .addAlternative(new RemoteWebDriverBuilder()10 .addAlternative(new ChromeDriver())11 .addAlternative(new FirefoxDriver()));12WebDriver driver = builder.build();13import org.openqa.selenium.remote.RemoteWebDriverBuilder;14RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder()15 .addAlternative(new RemoteWebDriverBuilder()16 .addAlternative(new ChromeDriver())17 .addAlternative(new FirefoxDriver()));18WebDriver driver = builder.build();19import org.openqa.selenium.remote.RemoteWebDriverBuilder;20RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder()21 .addAlternative(new RemoteWebDriverBuilder()22 .addAlternative(new ChromeDriver())23 .addAlternative(new FirefoxDriver()));24WebDriver driver = builder.build();25import org.openqa.selenium.remote.RemoteWebDriverBuilder;26RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder()27 .addAlternative(new RemoteWebDriverBuilder()28 .addAlternative(new ChromeDriver())29 .addAlternative(new FirefoxDriver()));30WebDriver driver = builder.build();31import org.openqa.selenium.remote.RemoteWebDriverBuilder;32RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder()33 .addAlternative(new RemoteWebDriverBuilder()34 .addAlternative(new ChromeDriver())35 .addAlternative(new FirefoxDriver()));36WebDriver driver = builder.build();37import org.openqa.selenium.remote.RemoteWebDriverBuilder;38RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder()39 .addAlternative(new RemoteWebDriverBuilder()40 .addAlternative(new ChromeDriver())41 .addAlternative(new FirefoxDriver()));42WebDriver driver = builder.build();43import org.openqa.selenium.remote.RemoteWebDriverBuilder;44RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder()45 .addAlternative(new RemoteWebDriverBuilder()

Full Screen

Full Screen

addAlternative

Using AI Code Generation

copy

Full Screen

1RemoteWebDriver driver = new RemoteWebDriverBuilder()2 .withCapabilities(Capabilities)3 .withUrl(URL)4 .addAlternative(new ChromeOptions())5 .addAlternative(new FirefoxOptions())6 .build();7driver.quit();

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful