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

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

Source:RemoteWebDriverBuilder.java Github

copy

Full Screen

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

Source:RemoteWebDriverBuilderTest.java Github

copy

Full Screen

...67 }68 @Test69 public void mustSpecifyAtLeastOneSetOfOptions() {70 List<List<Capabilities>> caps = new ArrayList<>();71 RemoteWebDriver.builder().oneOf(new FirefoxOptions())72 .address("http://localhost:34576")73 .connectingWith(config -> req -> {74 caps.add(listCapabilities(req));75 return CANNED_SESSION_RESPONSE;76 })77 .build();78 assertThat(caps).hasSize(1);79 List<Capabilities> caps0 = caps.get(0);80 assertThat(caps0.get(0).getBrowserName()).isEqualTo(FIREFOX);81 }82 @Test83 public void settingAGlobalCapabilityCountsAsAnOption() {84 AtomicBoolean match = new AtomicBoolean(false);85 RemoteWebDriver.builder().setCapability("se:cheese", "anari")86 .address("http://localhost:34576")87 .connectingWith(config -> req -> {88 listCapabilities(req).stream()89 .map(caps -> "anari".equals(caps.getCapability("se:cheese")))90 .reduce(Boolean::logicalOr)91 .ifPresent(match::set);92 return CANNED_SESSION_RESPONSE;93 })94 .build();95 assertThat(match.get()).isTrue();96 }97 @Test98 public void shouldForbidGlobalCapabilitiesFromClobberingFirstMatchCapabilities() {99 RemoteWebDriverBuilder builder = RemoteWebDriver.builder()100 .oneOf(new ImmutableCapabilities("se:cheese", "stinking bishop"))101 .setCapability("se:cheese", "cheddar")102 .address("http://localhost:38746");103 assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(builder::build);104 }105 @Test106 public void requireAllOptionsAreW3CCompatible() {107 RemoteWebDriverBuilder builder = RemoteWebDriver.builder()108 .setCapability("cheese", "casu marzu")109 .address("http://localhost:45734");110 assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(builder::build);111 }112 @Test113 public void shouldRejectOldJsonWireProtocolNames() {114 RemoteWebDriverBuilder builder = RemoteWebDriver.builder()115 .oneOf(new ImmutableCapabilities("platform", Platform.getCurrent()))116 .address("http://localhost:35856");117 assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(builder::build);118 }119 @Test120 public void shouldAllowMetaDataToBeSet() {121 AtomicBoolean seen = new AtomicBoolean(false);122 RemoteWebDriver.builder()123 .oneOf(new FirefoxOptions())124 .addMetadata("cloud:options", "merhaba")125 .address("http://localhost:34576")126 .connectingWith(config -> req -> {127 Map<String, Object> payload = new Json().toType(Contents.string(req), MAP_TYPE);128 seen.set("merhaba".equals(payload.getOrDefault("cloud:options", "")));129 return CANNED_SESSION_RESPONSE;130 })131 .build();132 assertThat(seen.get()).isTrue();133 }134 @Test135 public void doesNotAllowFirstMatchToBeUsedAsAMetadataNameAsItIsConfusing() {136 RemoteWebDriverBuilder builder = RemoteWebDriver.builder();137 assertThatExceptionOfType(IllegalArgumentException.class)138 .isThrownBy(() -> builder.addMetadata("firstMatch", "cheese"));139 }140 @Test141 public void doesNotAllowAlwaysMatchToBeUsedAsAMetadataNameAsItIsConfusing() {142 RemoteWebDriverBuilder builder = RemoteWebDriver.builder();143 assertThatExceptionOfType(IllegalArgumentException.class)144 .isThrownBy(() -> builder.addMetadata("alwaysMatch", "cheese"));145 }146 @Test147 public void doesNotAllowCapabilitiesToBeUsedAsAMetadataName() {148 RemoteWebDriverBuilder builder = RemoteWebDriver.builder();149 assertThatExceptionOfType(IllegalArgumentException.class)150 .isThrownBy(() -> builder.addMetadata("capabilities", "cheese"));151 }152 @Test153 public void shouldAllowCapabilitiesToBeSetGlobally() {154 AtomicBoolean seen = new AtomicBoolean(false);155 RemoteWebDriver.builder()156 .oneOf(new FirefoxOptions())157 .setCapability("se:option", "cheese")158 .address("http://localhost:34576")159 .connectingWith(config -> req -> {160 listCapabilities(req).stream()161 .map(caps -> "cheese".equals(caps.getCapability("se:option")))162 .reduce(Boolean::logicalAnd)163 .ifPresent(seen::set);164 return CANNED_SESSION_RESPONSE;165 })166 .build();167 assertThat(seen.get()).isTrue();168 }169 @Test170 public void ifARemoteUrlIsGivenThatIsUsedForTheSession() {171 URI uri = URI.create("http://localhost:7575");172 AtomicReference<URI> seen = new AtomicReference<>();173 RemoteWebDriver.builder()174 .oneOf(new FirefoxOptions())175 .address(uri)176 .connectingWith(config -> req -> {177 seen.set(config.baseUri());178 return CANNED_SESSION_RESPONSE;179 })180 .build();181 assertThat(seen.get()).isEqualTo(uri);182 }183 @Test184 public void shouldUseGivenDriverServiceForUrlIfProvided() throws IOException {185 URI uri = URI.create("http://localhost:9898");186 URL url = uri.toURL();187 DriverService service = new FakeDriverService() {188 @Override189 public URL getUrl() {190 return url;191 }192 };193 AtomicReference<URI> seen = new AtomicReference<>();194 RemoteWebDriver.builder()195 .oneOf(new FirefoxOptions())196 .withDriverService(service)197 .connectingWith(config -> {198 seen.set(config.baseUri());199 return req -> CANNED_SESSION_RESPONSE;200 })201 .build();202 assertThat(seen.get()).isEqualTo(uri);203 }204 @Test205 public void settingBothDriverServiceAndUrlIsAnError() throws IOException {206 RemoteWebDriverBuilder builder = RemoteWebDriver.builder()207 .withDriverService(new FakeDriverService());208 assertThatExceptionOfType(IllegalArgumentException.class)209 .isThrownBy(() -> builder.address("http://localhost:89789"));210 }211 @Test212 public void oneOfWillClearOutTheCurrentlySetCapabilities() {213 AtomicBoolean allOk = new AtomicBoolean();214 RemoteWebDriver.builder()215 .oneOf(new FirefoxOptions())216 .addAlternative(new InternetExplorerOptions())217 .oneOf(new ChromeOptions())218 .address("http://localhost:34576")219 .connectingWith(config -> req -> {220 List<Capabilities> caps = listCapabilities(req);221 allOk.set(caps.size() == 1 && caps.get(0).getBrowserName().equals(CHROME));222 return CANNED_SESSION_RESPONSE;223 })224 .build();225 assertThat(allOk.get()).isTrue();226 }227 @Test228 public void shouldBeAbleToSetClientConfigDirectly() {229 URI uri = URI.create("http://localhost:5763");230 AtomicReference<URI> seen = new AtomicReference<>();231 RemoteWebDriver.builder()232 .address(uri.toString())233 .oneOf(new FirefoxOptions())234 .connectingWith(config -> {235 seen.set(config.baseUri());236 return req -> CANNED_SESSION_RESPONSE;237 })238 .build();239 assertThat(seen.get()).isEqualTo(uri);240 }241 @Test242 public void shouldSetRemoteHostUriOnClientConfigIfSet() {243 URI uri = URI.create("http://localhost:6546");244 ClientConfig config = ClientConfig.defaultConfig().baseUri(uri);245 AtomicReference<URI> seen = new AtomicReference<>();246 RemoteWebDriver.builder()247 .config(config)248 .oneOf(new FirefoxOptions())249 .connectingWith(c -> {250 seen.set(c.baseUri());251 return req -> CANNED_SESSION_RESPONSE;252 })253 .build();254 assertThat(seen.get()).isEqualTo(uri);255 }256 @Test257 public void shouldSetSessionIdFromW3CResponse() {258 RemoteWebDriver driver = (RemoteWebDriver) RemoteWebDriver.builder()259 .oneOf(new FirefoxOptions())260 .address("http://localhost:34576")261 .connectingWith(config -> req -> CANNED_SESSION_RESPONSE)262 .build();263 assertThat(driver.getSessionId()).isEqualTo(SESSION_ID);264 }265 @Test266 public void commandsShouldBeSentWithW3CHeaders() {267 AtomicBoolean allOk = new AtomicBoolean(false);268 RemoteWebDriver.builder()269 .oneOf(new FirefoxOptions())270 .address("http://localhost:34576")271 .connectingWith(config -> req -> {272 allOk.set("no-cache".equals(req.getHeader("Cache-Control")) && JSON_UTF_8.equals(req.getHeader("Content-Type")));273 return CANNED_SESSION_RESPONSE;274 })275 .build();276 assertThat(allOk.get()).isTrue();277 }278 @Test279 public void shouldUseWebDriverInfoToFindAMatchingDriverImplementationForRequestedCapabilitiesIfRemoteUrlNotSet() {280 }281 @Test282 public void shouldAugmentDriverIfPossible() {283 }...

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.chrome.ChromeOptions;4import org.openqa.selenium.devtools.DevTools;5import org.openqa.selenium.devtools.v91.network.Network;6import org.openqa.selenium.devtools.v91.network.model.Headers;7import org.openqa.selenium.devtools.v91.network.model.RequestPattern;8import org.openqa.selenium.devtools.v91.network.model.ResourceType;9import org.openqa.selenium.devtools.v91.page.Page;10import org.openqa.selenium.devtools.v91.runtime.model.RemoteObject;11import org.openqa.selenium.remote.RemoteWebDriver;12import org.openqa.selenium.remote.RemoteWebDriverBuilder;13import java.io.File;14import java.io.IOException;15import java.nio.file.Files;16import java.nio.file.Paths;17import java.util.HashMap;18import java.util.Map;19public class ChromeDevTools {20 public static void main(String[] args) throws IOException {21 File file = new File("src/main/resources/chromedriver.exe");22 System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());23 ChromeOptions options = new ChromeOptions();24 options.addArguments("--incognito");25 options.addArguments("--disable-extensions");26 options.addArguments("--start-maximized");27 options.addArguments("--headless");28 options.addArguments("--disable-gpu");29 options.addArguments("--no-sandbox");30 options.addArguments("--disable-dev-shm-usage");31 options.addArguments("--ignore-certificate-errors");32 RemoteWebDriver driver = (RemoteWebDriver) new RemoteWebDriverBuilder().oneOf(ChromeDriver.class).withOptions(options).build();33 DevTools devTools = driver.getDevTools();34 devTools.createSession();35 devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));36 devTools.send(Network.emulateNetworkConditions(false, 100, 100, 100, Optional.empty()));37 devTools.send(Page.enable());38 devTools.addListener(Page.loadEventFired(), loadEventFired -> {39 devTools.send(Network.getAllCookies());40 devTools.send(Network.getCookies(url));41 devTools.send(Network.getResponseBodyForInterception("1"));42 devTools.send(Network.getResponseBodyForInterception("2"));43 devTools.send(Network.getResponseBodyForInterception("3"));44 devTools.send(Network.getResponseBodyForInterception("4"));45 devTools.send(Network.getResponseBodyForInterception("5"));46 devTools.send(Network.getResponseBodyForInterception("6"));47 devTools.send(Network.getResponseBody

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.RemoteWebDriverBuilder;2public class RemoteWebDriverBuilderExample {3 public static void main(String[] args) {4 RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();5 }6}

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.RemoteWebDriverBuilder;2import org.openqa.selenium.remote.RemoteWebDriverBuilder.Driver;3public class RemoteWebDriverBuilderTest {4 public static void main(String[] args) {5 RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();6 builder.oneOf(Driver.FIREFOX,Driver.CHROME);7 }8}9at org.openqa.selenium.remote.RemoteWebDriverBuilder.oneOf(RemoteWebDriverBuilder.java:220)10at com.selenium4beginners.selenium4.RemoteWebDriverBuilderTest.main(RemoteWebDriverBuilderTest.java:16)

Full Screen

Full Screen

oneOf

Using AI Code Generation

copy

Full Screen

1RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(ChromeDriver.class).build();2RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(FirefoxDriver.class).build();3RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(EdgeDriver.class).build();4RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(InternetExplorerDriver.class).build();5RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(SafariDriver.class).build();6RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(OperaDriver.class).build();7RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(PhantomJSDriver.class).build();8RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(HtmlUnitDriver.class).build();9RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(AndroidDriver.class).build();10RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(IOSDriver.class).build();11RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(RemoteWebDriver.class).build();12RemoteWebDriver driver = new RemoteWebDriverBuilder().oneOf(RemoteWebDriver.class).build();

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