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

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

Source:RemoteWebDriver.java Github

copy

Full Screen

...499 String errorMessage = "Error communicating with the remote browser. " +500 "It may have died.";501 if (command.getName().equals(DriverCommand.NEW_SESSION)) {502 errorMessage = "Could not start a new session. Possible causes are " +503 "invalid address of the remote server or browser start-up failure.";504 }505 UnreachableBrowserException ube = new UnreachableBrowserException(errorMessage, e);506 if (getSessionId() != null) {507 ube.addInfo(WebDriverException.SESSION_ID, getSessionId().toString());508 }509 if (getCapabilities() != null) {510 ube.addInfo("Capabilities", getCapabilities().toString());511 }512 throw ube;513 } finally {514 Thread.currentThread().setName(currentName);515 }516 try {517 errorHandler.throwIfResponseFailed(response, System.currentTimeMillis() - start);...

Full Screen

Full Screen

Source:RemoteWebDriverBuilder.java Github

copy

Full Screen

...76 * don't care which), but where either browser will use the given {@link org.openqa.selenium.Proxy}.77 * In addition, we've added some metadata to the session, setting the "{@code cloud.key}" to be the78 * secret passphrase of our account with the cloud "Selenium as a Service" provider.79 * <p>80 * If no call to {@link #withDriverService(DriverService)} or {@link #address(URI)} is made, the81 * builder will use {@link ServiceLoader} to find all instances of {@link WebDriverInfo} and will82 * call {@link WebDriverInfo#createDriver(Capabilities)} for the first supported set of83 * capabilities.84 */85@Beta86public class RemoteWebDriverBuilder {87 private static final Logger LOG = Logger.getLogger(RemoteWebDriverBuilder.class.getName());88 private static final Set<String> ILLEGAL_METADATA_KEYS = ImmutableSet.of(89 "alwaysMatch",90 "capabilities",91 "desiredCapabilities",92 "firstMatch");93 private final List<Capabilities> requestedCapabilities = new ArrayList<>();94 private final Map<String, Object> additionalCapabilities = new TreeMap<>();95 private final Map<String, Object> metadata = new TreeMap<>();96 private Function<ClientConfig, HttpHandler> handlerFactory =97 config -> {98 HttpClient.Factory factory = HttpClient.Factory.createDefault();99 HttpClient client = factory.createClient(config);100 return client.with(101 next -> req -> {102 try {103 return client.execute(req);104 } finally {105 if (req.getMethod() == DELETE) {106 HttpSessionId.getSessionId(req.getUri()).ifPresent(id -> {107 if (("/session/" + id).equals(req.getUri())) {108 try {109 client.close();110 } catch (UncheckedIOException e) {111 LOG.log(WARNING, "Swallowing exception while closing http client", e);112 }113 factory.cleanupIdleClients();114 }115 });116 }117 }118 });119 };120 private ClientConfig clientConfig = ClientConfig.defaultConfig();121 private URI remoteHost = null;122 private DriverService driverService;123 private Credentials credentials = null;124 RemoteWebDriverBuilder() {125 // Access through RemoteWebDriver.builder126 }127 /**128 * Clears the current set of alternative browsers and instead sets the list of possible choices to129 * the arguments given to this method.130 */131 public RemoteWebDriverBuilder oneOf(Capabilities maybeThis, Capabilities... orOneOfThese) {132 Require.nonNull("Capabilities to use", maybeThis);133 if (!requestedCapabilities.isEmpty()) {134 LOG.log(getDebugLogLevel(), "Removing existing requested capabilities: " + requestedCapabilities);135 requestedCapabilities.clear();136 }137 addAlternative(maybeThis);138 for (Capabilities caps : orOneOfThese) {139 Require.nonNull("Capabilities to use", caps);140 addAlternative(caps);141 }142 return this;143 }144 /**145 * Add to the list of possible configurations that might be asked for. It is possible to ask for146 * more than one type of browser per session. For example, perhaps you have an extension that is147 * available for two different kinds of browser, and you'd like to test it).148 */149 public RemoteWebDriverBuilder addAlternative(Capabilities options) {150 Require.nonNull("Capabilities to use", options);151 requestedCapabilities.add(new ImmutableCapabilities(options));152 return this;153 }154 /**155 * Adds metadata to the outgoing new session request, which can be used by intermediary of end156 * nodes for any purpose they choose (commonly, this is used to request additional features from157 * cloud providers, such as video recordings or to set the timezone or screen size). Neither158 * parameter can be {@code null}.159 */160 public RemoteWebDriverBuilder addMetadata(String key, Object value) {161 Require.nonNull("Metadata key", key);162 Require.nonNull("Metadata value", value);163 if (ILLEGAL_METADATA_KEYS.contains(key)) {164 throw new IllegalArgumentException(String.format("Cannot add %s as metadata key", key));165 }166 Object previous = metadata.put(key, value);167 if (previous != null) {168 LOG.log(169 getDebugLogLevel(),170 String.format("Overwriting metadata %s. Previous value %s, new value %s", key, previous, value));171 }172 return this;173 }174 /**175 * Sets a capability for every single alternative when the session is created. These capabilities176 * are only set once the session is created, so this will be set on capabilities added via177 * {@link #addAlternative(Capabilities)} or {@link #oneOf(Capabilities, Capabilities...)} even178 * after this method call.179 */180 public RemoteWebDriverBuilder setCapability(String capabilityName, Object value) {181 Require.nonNull("Capability name", capabilityName);182 Require.nonNull("Capability value", value);183 Object previous = additionalCapabilities.put(capabilityName, value);184 if (previous != null) {185 LOG.log(186 getDebugLogLevel(),187 String.format("Overwriting capability %s. Previous value %s, new value %s", capabilityName, previous, value));188 }189 return this;190 }191 /**192 * @see #address(URI)193 */194 public RemoteWebDriverBuilder address(String uri) {195 Require.nonNull("Address", uri);196 try {197 return address(new URI(uri));198 } catch (URISyntaxException e) {199 throw new IllegalArgumentException("Unable to create URI from " + uri);200 }201 }202 /**203 * @see #address(URI)204 */205 public RemoteWebDriverBuilder address(URL url) {206 Require.nonNull("Address", url);207 try {208 return address(url.toURI());209 } catch (URISyntaxException e) {210 throw new IllegalArgumentException("Unable to create URI from " + url);211 }212 }213 /**214 * Set the URI of the remote server. If this URI is not set, then it assumed that a local running215 * remote webdriver session is needed. It is an error to call this method and also216 * {@link #withDriverService(DriverService)}.217 */218 public RemoteWebDriverBuilder address(URI uri) {219 Require.nonNull("URI", uri);220 if (driverService != null || (clientConfig.baseUri() != null && !clientConfig.baseUri().equals(uri))) {221 throw new IllegalArgumentException(222 "Attempted to set the base uri on both this builder and the http client config. " +223 "Please set in only one place. " + uri);224 }225 remoteHost = uri;226 return this;227 }228 public RemoteWebDriverBuilder authenticateAs(UsernameAndPassword usernameAndPassword) {229 Require.nonNull("User name and password", usernameAndPassword);230 this.credentials = usernameAndPassword;231 return this;232 }233 /**234 * Allows precise control of the {@link ClientConfig} to use with remote235 * instances. If {@link ClientConfig#baseUri(URI)} has been called, then236 * that will be used as the base URI for the session.237 */238 public RemoteWebDriverBuilder config(ClientConfig config) {239 Require.nonNull("HTTP client config", config);240 if (config.baseUri() != null) {241 if (remoteHost != null || driverService != null) {242 throw new IllegalArgumentException("Base URI has already been set. Cannot also set it via client config");243 }244 }245 this.clientConfig = config;246 return this;247 }248 /**249 * Use the given {@link DriverService} to set up the webdriver instance. It is an error to set250 * both this and also call {@link #address(URI)}.251 */252 public RemoteWebDriverBuilder withDriverService(DriverService service) {253 Require.nonNull("Driver service", service);254 if (clientConfig.baseUri() != null || remoteHost != null) {255 throw new IllegalArgumentException("Base URI has already been set. Cannot also set driver service.");256 }257 this.driverService = service;258 return this;259 }260 @VisibleForTesting261 RemoteWebDriverBuilder connectingWith(Function<ClientConfig, HttpHandler> handlerFactory) {262 Require.nonNull("Handler factory", handlerFactory);263 this.handlerFactory = handlerFactory;264 return this;...

Full Screen

Full Screen

Source:RemoteWebDriverBuilderTest.java Github

copy

Full Screen

...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 }284 @SuppressWarnings("unchecked")...

Full Screen

Full Screen

Source:CreateWebDriverFromRunningServiceActionTest.java Github

copy

Full Screen

...43 @BeforeEach44 void setUp() {45 when(params.getUrl()).thenReturn("http://www");46 when(builder.addAlternative(any())).thenReturn(builder);47 when(builder.address(any(String.class))).thenReturn(builder);48 when(builder.build()).thenReturn(webDriver);49 testSubject = new CreateWebDriverFromRunningServiceAction() {50 @Override51 protected RemoteWebDriverBuilder getBuilder() {52 return builder;53 }54 };55 }56 private void verifyAll() {57 verify(builder, times(1)).addAlternative(any());58 verify(builder, times(1)).address(any(String.class));59 verify(params, times(1)).getOptions();60 verify(params, times(1)).getUrl();61 }62 @Test63 void applyChrome() {64 assertEquals(webDriver, testSubject.applyChrome(params));65 verifyAll();66 }67 @Test68 void applyEdge() {69 assertEquals(webDriver, testSubject.applyEdge(params));70 verifyAll();71 }72 @Test...

Full Screen

Full Screen

Source:CreateWebDriverFromRunningServiceAction.java Github

copy

Full Screen

...66 }67 private WebDriver doBuild(RemoteWebDriverBuilder builder, RunningServiceParams input) {68 return builder69 .addAlternative(input.getOptions())70 .address(input.getUrl())71 .build();72 }73 /**74 * For Unit testing purpose75 *76 * @return the instance of the builder77 */78 protected RemoteWebDriverBuilder getBuilder() {79 return builder();80 }81}...

Full Screen

Full Screen

address

Using AI Code Generation

copy

Full Screen

1driver.quit();2driver.quit();3driver.quit();4driver.quit();5driver.quit();6driver.quit();7driver.quit();

Full Screen

Full Screen

address

Using AI Code Generation

copy

Full Screen

1RemoteWebDriverBuilder builder = new RemoteWebDriverBuilder();2builder.withCapabilities(new DesiredCapabilities());3builder.withCapabilities(new DesiredCapabilities());4builder.withCapabilities(new DesiredCapabilities());5builder.withCapabilities(new DesiredCapabilities());6builder.withCapabilities(new DesiredCapabilities());7builder.withCapabilities(new DesiredCapabilities());8builder.withCapabilities(new DesiredCapabilities());9builder.withCapabilities(new DesiredCapabilities());10builder.withCapabilities(new DesiredCapabilities());11builder.withCapabilities(new DesiredCapabilities());12builder.withCapabilities(new DesiredCapabilities());13builder.withCapabilities(new DesiredCapabilities());14builder.withCapabilities(new DesiredCapabilities());15builder.withCapabilities(new DesiredCapabilities());16builder.withCapabilities(new DesiredCapabilities());17builder.withCapabilities(new DesiredCapabilities());18builder.withCapabilities(new DesiredCapabilities());19builder.withCapabilities(new DesiredCapabilities());20builder.withCapabilities(new DesiredCapabilities());21builder.withCapabilities(new DesiredCapabilities());22RemoteWebDriver driver = builder.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