How to use builder method of org.openqa.selenium.remote.RemoteWebDriver class

Best Selenium code snippet using org.openqa.selenium.remote.RemoteWebDriver.builder

Source:RemoteWebDriverBuilderTest.java Github

copy

Full Screen

...61 // Primula is a canned cheese. Boom boom!62 "capabilities", new ImmutableCapabilities("se:cheese", "primula")))));63 @Test64 public void justCallingBuildWithoutSettingAnyOptionsIsAnError() {65 RemoteWebDriverBuilder builder = RemoteWebDriver.builder();66 assertThatExceptionOfType(SessionNotCreatedException.class).isThrownBy(builder::build);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() {...

Full Screen

Full Screen

Source:InternetExplorerDriver.java Github

copy

Full Screen

...187 "You appear to be running %s. The IE driver only runs on Windows.", current));188 }189 }190 private InternetExplorerDriverService setupService(Capabilities caps, int port) {191 InternetExplorerDriverService.Builder builder = new InternetExplorerDriverService.Builder();192 builder.usingPort(port);193 if (caps != null) {194 if (caps.getCapability(LOG_FILE) != null) {195 String value = (String) caps.getCapability(LOG_FILE);196 if (value != null) {197 builder.withLogFile(new File(value));198 }199 }200 if (caps.getCapability(LOG_LEVEL) != null) {201 String value = (String) caps.getCapability(LOG_LEVEL);202 if (value != null) {203 builder.withLogLevel(InternetExplorerDriverLogLevel.valueOf(value));204 }205 }206 if (caps.getCapability(HOST) != null) {207 String value = (String) caps.getCapability(HOST);208 if (value != null) {209 builder.withHost(value);210 }211 }212 if (caps.getCapability(EXTRACT_PATH) != null) {213 String value = (String) caps.getCapability(EXTRACT_PATH);214 if (value != null) {215 builder.withExtractPath(new File(value));216 }217 }218 if (caps.getCapability(SILENT) != null) {219 Boolean value = (Boolean) caps.getCapability(SILENT);220 if (value != null) {221 builder.withSilent(value);222 }223 }224 }225 return builder.build();226 }227}...

Full Screen

Full Screen

Source:ChromeDriver.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.chrome;18import com.google.common.collect.ImmutableMap;19import org.openqa.selenium.Capabilities;20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.WebDriverException;22import org.openqa.selenium.html5.LocalStorage;23import org.openqa.selenium.html5.Location;24import org.openqa.selenium.html5.LocationContext;25import org.openqa.selenium.html5.SessionStorage;26import org.openqa.selenium.html5.WebStorage;27import org.openqa.selenium.interactions.HasTouchScreen;28import org.openqa.selenium.interactions.TouchScreen;29import org.openqa.selenium.mobile.NetworkConnection;30import org.openqa.selenium.remote.FileDetector;31import org.openqa.selenium.remote.RemoteTouchScreen;32import org.openqa.selenium.remote.RemoteWebDriver;33import org.openqa.selenium.remote.html5.RemoteLocationContext;34import org.openqa.selenium.remote.html5.RemoteWebStorage;35import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;36/**37 * A {@link WebDriver} implementation that controls a Chrome browser running on the local machine.38 * This class is provided as a convenience for easily testing the Chrome browser. The control server39 * which each instance communicates with will live and die with the instance.40 *41 * To avoid unnecessarily restarting the ChromeDriver server with each instance, use a42 * {@link RemoteWebDriver} coupled with the desired {@link ChromeDriverService}, which is managed43 * separately. For example: <pre>{@code44 *45 * import static org.junit.Assert.assertEquals;46 *47 * import org.junit.*;48 * import org.junit.runner.RunWith;49 * import org.junit.runners.JUnit4;50 * import org.openqa.selenium.chrome.ChromeDriverService;51 * import org.openqa.selenium.remote.DesiredCapabilities;52 * import org.openqa.selenium.remote.RemoteWebDriver;53 *54 * {@literal @RunWith(JUnit4.class)}55 * public class ChromeTest extends TestCase {56 *57 * private static ChromeDriverService service;58 * private WebDriver driver;59 *60 * {@literal @BeforeClass}61 * public static void createAndStartService() {62 * service = new ChromeDriverService.Builder()63 * .usingDriverExecutable(new File("path/to/my/chromedriver.exe"))64 * .usingAnyFreePort()65 * .build();66 * service.start();67 * }68 *69 * {@literal @AfterClass}70 * public static void createAndStopService() {71 * service.stop();72 * }73 *74 * {@literal @Before}75 * public void createDriver() {76 * driver = new RemoteWebDriver(service.getUrl(),77 * DesiredCapabilities.chrome());78 * }79 *80 * {@literal @After}81 * public void quitDriver() {82 * driver.quit();83 * }84 *85 * {@literal @Test}86 * public void testGoogleSearch() {87 * driver.get("http://www.google.com");88 * WebElement searchBox = driver.findElement(By.name("q"));89 * searchBox.sendKeys("webdriver");90 * searchBox.quit();91 * assertEquals("webdriver - Google Search", driver.getTitle());92 * }93 * }94 * }</pre>95 *96 * Note that unlike ChromeDriver, RemoteWebDriver doesn't directly implement97 * role interfaces such as {@link LocationContext} and {@link WebStorage}.98 * Therefore, to access that functionality, it needs to be99 * {@link org.openqa.selenium.remote.Augmenter augmented} and then cast100 * to the appropriate interface.101 *102 * @see ChromeDriverService#createDefaultService103 */104public class ChromeDriver extends RemoteWebDriver105 implements LocationContext, WebStorage, HasTouchScreen, NetworkConnection {106 private RemoteLocationContext locationContext;107 private RemoteWebStorage webStorage;108 private TouchScreen touchScreen;109 private RemoteNetworkConnection networkConnection;110 /**111 * Creates a new ChromeDriver using the {@link ChromeDriverService#createDefaultService default}112 * server configuration.113 *114 * @see #ChromeDriver(ChromeDriverService, ChromeOptions)115 */116 public ChromeDriver() {117 this(ChromeDriverService.createDefaultService(), new ChromeOptions());118 }119 /**120 * Creates a new ChromeDriver instance. The {@code service} will be started along with the driver,121 * and shutdown upon calling {@link #quit()}.122 *123 * @param service The service to use.124 * @see RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)125 * @deprecated Use {@link RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)}126 */127 @Deprecated128 public ChromeDriver(ChromeDriverService service) {129 this(service, new ChromeOptions());130 }131 /**132 * Creates a new ChromeDriver instance. The {@code capabilities} will be passed to the133 * chromedriver service.134 *135 * @param capabilities The capabilities required from the ChromeDriver.136 * @see #ChromeDriver(ChromeDriverService, Capabilities)137 */138 public ChromeDriver(Capabilities capabilities) {139 this(ChromeDriverService.createDefaultService(), capabilities);140 }141 /**142 * Creates a new ChromeDriver instance with the specified options.143 *144 * @param options The options to use.145 * @see #ChromeDriver(ChromeDriverService, ChromeOptions)146 */147 public ChromeDriver(ChromeOptions options) {148 this(ChromeDriverService.createDefaultService(), options);149 }150 /**151 * Creates a new ChromeDriver instance with the specified options. The {@code service} will be152 * started along with the driver, and shutdown upon calling {@link #quit()}.153 *154 * @param service The service to use.155 * @param options The options to use.156 * @deprecated Use {@link RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)}157 */158 @Deprecated159 public ChromeDriver(ChromeDriverService service, ChromeOptions options) {160 this(service, options.toCapabilities());161 }162 /**163 * Creates a new ChromeDriver instance. The {@code service} will be started along with the164 * driver, and shutdown upon calling {@link #quit()}.165 *166 * @param service The service to use.167 * @param capabilities The capabilities required from the ChromeDriver.168 * @deprecated Use {@link RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)}169 */170 @Deprecated171 public ChromeDriver(ChromeDriverService service, Capabilities capabilities) {172 super(new ChromeDriverCommandExecutor(service), capabilities);173 locationContext = new RemoteLocationContext(getExecuteMethod());174 webStorage = new RemoteWebStorage(getExecuteMethod());175 touchScreen = new RemoteTouchScreen(getExecuteMethod());176 networkConnection = new RemoteNetworkConnection(getExecuteMethod());177 }178 @Override179 public void setFileDetector(FileDetector detector) {180 throw new WebDriverException(181 "Setting the file detector only works on remote webdriver instances obtained " +182 "via RemoteWebDriver");183 }184 @Override185 public LocalStorage getLocalStorage() {186 return webStorage.getLocalStorage();187 }188 @Override189 public SessionStorage getSessionStorage() {190 return webStorage.getSessionStorage();191 }192 @Override193 public Location location() {194 return locationContext.location();195 }196 @Override197 public void setLocation(Location location) {198 locationContext.setLocation(location);199 }200 @Override201 public TouchScreen getTouch() {202 return touchScreen;203 }204 @Override205 public ConnectionType getNetworkConnection() {206 return networkConnection.getNetworkConnection();207 }208 @Override209 public ConnectionType setNetworkConnection(ConnectionType type) {210 return networkConnection.setNetworkConnection(type);211 }212 /**213 * Launches Chrome app specified by id.214 *215 * @param id chrome app id216 */217 public void launchApp(String id) {218 execute(ChromeDriverCommand.LAUNCH_APP, ImmutableMap.of("id", id));219 }220 221}...

Full Screen

Full Screen

Source:EdgeDriver.java Github

copy

Full Screen

...61 * public static void createAndStartService() {62 * // Setting this property to false in order to launch Chromium Edge63 * // Otherwise, old Edge will be launched by default64 * System.setProperty("webdriver.edge.edgehtml", "false");65 * EdgeDriverService.Builder<?, ?> builder =66 * StreamSupport.stream(ServiceLoader.load(DriverService.Builder.class).spliterator(), false)67 * .filter(b -> b instanceof EdgeDriverService.Builder)68 * .map(b -> (EdgeDriverService.Builder) b)69 * .filter(b -> b.isLegacy() == Boolean.getBoolean("webdriver.edge.edgehtml"))70 * .findFirst().orElseThrow(WebDriverException::new);71 * service = builder.build();72 * try {73 * service.start();74 * }75 * catch (IOException e) {76 * throw new RuntimeException(e);77 * }78 * }79 *80 * {@Literal @AfterAll}81 * public static void createAndStopService() {82 * service.stop();83 * }84 *85 * {@Literal @BeforeEach}86 * public void createDriver() {87 * driver = new RemoteWebDriver(service.getUrl(),88 * new EdgeOptions());89 * }90 *91 * {@Literal @AfterEach}92 * public void quitDriver() {93 * driver.quit();94 * }95 *96 * {@Literal @Test}97 * public void testBingSearch() {98 * driver.get("http://www.bing.com");99 * WebElement searchBox = driver.findElement(By.name("q"));100 * searchBox.sendKeys("webdriver");101 * searchBox.submit();102 * assertEquals("webdriver - Bing", driver.getTitle());103 * }104 * }}</pre>105 */106public class EdgeDriver extends ChromiumDriver {107 /**108 * Boolean system property that defines whether the msedgedriver executable (Chromium Edge)109 * should be used.110 */111 public static final String DRIVER_USE_EDGE_EDGEHTML = "webdriver.edge.edgehtml";112 public EdgeDriver() { this(new EdgeOptions()); }113 public EdgeDriver(EdgeOptions options) {114 super(toExecutor(options), options, EdgeOptions.CAPABILITY);115 }116 @Deprecated117 public EdgeDriver(Capabilities capabilities) {118 super(toExecutor(new EdgeOptions()), capabilities, EdgeOptions.CAPABILITY);119 }120 private static CommandExecutor toExecutor(EdgeOptions options) {121 Objects.requireNonNull(options, "No options to construct executor from");122 boolean isLegacy = System.getProperty(DRIVER_USE_EDGE_EDGEHTML) == null || Boolean.getBoolean(DRIVER_USE_EDGE_EDGEHTML);123 EdgeDriverService.Builder<?, ?> builder =124 StreamSupport.stream(ServiceLoader.load(DriverService.Builder.class).spliterator(), false)125 .filter(b -> b instanceof EdgeDriverService.Builder)126 .map(b -> (EdgeDriverService.Builder) b)127 .filter(b -> b.isLegacy() == isLegacy)128 .findFirst().orElseThrow(WebDriverException::new);129 if (isLegacy)130 return new DriverCommandExecutor(builder.build());131 return new ChromiumDriverCommandExecutor(builder.build());132 }133}...

Full Screen

Full Screen

Source:AutoConfigureNode.java Github

copy

Full Screen

...44 StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false)45 .filter(WebDriverInfo::isAvailable)46 .collect(Collectors.toList());47 // Same48 List<DriverService.Builder> builders = new ArrayList<>();49 ServiceLoader.load(DriverService.Builder.class).forEach(builders::add);50 infos.forEach(info -> {51 Capabilities caps = info.getCanonicalCapabilities();52 builders.stream()53 .filter(builder -> builder.score(caps) > 0)54 .peek(builder -> log.info(String.format("Adding %s %d times", caps, info.getMaximumSimultaneousSessions())))55 .forEach(builder -> {56 for (int i = 0; i < info.getMaximumSimultaneousSessions(); i++) {57 node.add(caps, c -> {58 try {59 DriverService service = builder.build();60 service.start();61 RemoteWebDriver driver = new RemoteWebDriver(service.getUrl(), c);62 return new SessionSpy(httpClientFactory, service, driver);63 } catch (IOException | URISyntaxException e) {64 throw new RuntimeException(e);65 }66 });67 }68 });69 });70 }71 private static class SessionSpy extends Session implements CommandHandler {72 private final ReverseProxyHandler handler;73 private final DriverService service;...

Full Screen

Full Screen

Source:WebDriverProvider.java Github

copy

Full Screen

...28 return new FirefoxDriver();29 }30 }31 private ChromeDriverService getChromeService(){32 ChromeDriverService.Builder builder = new ChromeDriverService.Builder();33 return builder34 .usingAnyFreePort()35 .withSilent(true)36 .withVerbose(false)37 .build();38 }39 public WebDriver createInstance(Type type, URL webDriverUrl){40 if(webDriverUrl == null){41 return createInstance(type);42 }43 return createRemoteInstance(type, webDriverUrl);44 }45 private WebDriver createRemoteInstance(Type type, URL webDriverUrl) {46 CommandExecutor commandExecutor = new HttpCommandExecutor(webDriverUrl);47 switch (type) {...

Full Screen

Full Screen

Source:RemoteWebDriverScreenshotTest.java Github

copy

Full Screen

1// Copyright 2011 Software Freedom Conservancy2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.13package org.openqa.selenium.remote.server;14import static org.junit.Assert.assertFalse;15import static org.junit.Assert.assertTrue;16import static org.junit.Assert.fail;17import static org.openqa.selenium.OutputType.BASE64;18import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;19import org.junit.Test;20import org.openqa.selenium.By;21import org.openqa.selenium.NoSuchElementException;22import org.openqa.selenium.TakesScreenshot;23import org.openqa.selenium.WebDriver;24import org.openqa.selenium.remote.Augmenter;25import org.openqa.selenium.remote.CapabilityType;26import org.openqa.selenium.remote.DesiredCapabilities;27import org.openqa.selenium.remote.RemoteWebDriver;28import org.openqa.selenium.remote.ScreenshotException;29import org.openqa.selenium.testing.Ignore;30import org.openqa.selenium.testing.JUnit4TestBase;31import org.openqa.selenium.testing.drivers.WebDriverBuilder;32@Ignore(HTMLUNIT)33public class RemoteWebDriverScreenshotTest extends JUnit4TestBase {34 @Test35 public void testShouldBeAbleToGrabASnapshotOnException() {36 if (!(driver instanceof RemoteWebDriver)) {37 System.out.println("Skipping test: driver is not a remote webdriver");38 return;39 }40 driver.get(pages.simpleTestPage);41 try {42 driver.findElement(By.id("doesnayexist"));43 fail();44 } catch (NoSuchElementException e) {45 assertTrue(((ScreenshotException) e.getCause()).getBase64EncodedScreenshot().length() > 0);46 }47 }48 @Test49 public void testCanAugmentWebDriverInstanceIfNecessary() {50 if (!(driver instanceof RemoteWebDriver)) {51 System.out.println("Skipping test: driver is not a remote webdriver");52 return;53 }54 RemoteWebDriver remote = (RemoteWebDriver) driver;55 Boolean screenshots = (Boolean) remote.getCapabilities()56 .getCapability(CapabilityType.TAKES_SCREENSHOT);57 if (screenshots == null || !screenshots) {58 System.out.println("Skipping test: remote driver cannot take screenshots");59 }60 driver.get(pages.formPage);61 WebDriver toUse = new Augmenter().augment(driver);62 String screenshot = ((TakesScreenshot) toUse).getScreenshotAs(BASE64);63 assertTrue(screenshot.length() > 0);64 }65 @Test66 public void testShouldBeAbleToDisableSnapshotOnException() {67 if (!(driver instanceof RemoteWebDriver)) {68 System.out.println("Skipping test: driver is not a remote webdriver");69 return;70 }71 DesiredCapabilities caps = new DesiredCapabilities();72 caps.setCapability("webdriver.remote.quietExceptions", true);73 WebDriver noScreenshotDriver = new WebDriverBuilder().setDesiredCapabilities(caps).get();74 noScreenshotDriver.get(pages.simpleTestPage);75 try {76 noScreenshotDriver.findElement(By.id("doesnayexist"));77 fail();78 } catch (NoSuchElementException e) {79 Throwable t = e;80 while (t != null) {81 assertFalse(t instanceof ScreenshotException);82 t = t.getCause();83 }84 }85 }86}...

Full Screen

Full Screen

Source:RemoteBrowserFactory.java Github

copy

Full Screen

...48 class ClientFactory implements Factory {49 private final Factory defaultClientFactory = Factory.createDefault();50 private final Duration timeoutCommand = timeoutConfiguration.getCommand();51 @Override52 public Builder builder() {53 return defaultClientFactory.builder().readTimeout(timeoutCommand);54 }55 @Override56 public HttpClient createClient(URL url) {57 return this.builder().createClient(url);58 }59 @Override60 public void cleanupIdleClients() {61 defaultClientFactory.cleanupIdleClients();62 }63 }64}...

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1package com.howtodoinjava.demo.selenium;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.remote.RemoteWebDriver;8import java.net.MalformedURLException;9import java.net.URL;10{11 public static void main(String[] args) throws MalformedURLException12 {

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1package com.seleniumeasy.tests;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.chrome.ChromeOptions;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.RemoteWebDriver;9import org.openqa.selenium.support.ui.ExpectedConditions;10import org.openqa.selenium.support.ui.WebDriverWait;11import java.net.MalformedURLException;12import java.net.URL;13import java.util.concurrent.TimeUnit;14public class SeleniumEasyTests {15 public static void main(String[] args) throws MalformedURLException {

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.RemoteWebDriver;3import java.net.MalformedURLException;4import java.net.URL;5public class RemoteWebDriverBuilder {6 public static void main(String[] args) throws MalformedURLException {7 DesiredCapabilities capabilities = new DesiredCapabilities();8 capabilities.setBrowserName("firefox");9 RemoteWebDriver driver = new RemoteWebDriver.Builder()10 .usingAnyFreePort()11 .withCapabilities(capabilities)12 .build();13 System.out.println(driver.getTitle());14 driver.quit();15 }16}17import org.openqa.selenium.remote.DesiredCapabilities;18import org.openqa.selenium.remote.RemoteWebDriver;19import java.net.MalformedURLException;20import java.net.URL;21public class RemoteWebDriverBuilder {22 public static void main(String[] args) throws MalformedURLException {23 DesiredCapabilities capabilities = new DesiredCapabilities();24 capabilities.setBrowserName("firefox");25 RemoteWebDriver driver = new RemoteWebDriver.Builder()26 .usingAnyFreePort()27 .withCapabilities(capabilities)28 .build();29 System.out.println(driver.getTitle());30 driver.quit();31 }32}33import org.openqa.selenium.remote.DesiredCapabilities;34import org.openqa.selenium.remote.RemoteWebDriver;35import java.net.MalformedURLException;36import java.net.URL;37public class RemoteWebDriverBuilder {38 public static void main(String[] args) throws MalformedURLException {39 DesiredCapabilities capabilities = new DesiredCapabilities();40 capabilities.setBrowserName("firefox");41 RemoteWebDriver driver = new RemoteWebDriver.Builder()42 .usingAnyFreePort()43 .withCapabilities(capabilities)44 .build();45 System.out.println(driver.getTitle());46 driver.quit();47 }48}

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1public class RemoteWebDriverBuilder {2 public static void main(String[] args) {3 .withCapabilities(new DesiredCapabilities())4 .withCommandTimeout(5)5 .withConnectionTimeout(5)6 .withProxy(new Proxy())7 .withFileDetector(new LocalFileDetector())8 .withSessionId("some session id")9 .withPlatform(Platform.LINUX)10 .withBrowserName("firefox")11 .withVersion("4.0")12 .build();13 }14 private URL url;15 private Capabilities capabilities;16 private int commandTimeout;17 private int connectionTimeout;18 private Proxy proxy;19 private FileDetector fileDetector;20 private SessionId sessionId;21 private Platform platform;22 private String browserName;23 private String version;24 public RemoteWebDriverBuilder withUrl(String url) {25 try {26 this.url = new URL(url);27 } catch (MalformedURLException e) {28 e.printStackTrace();29 }30 return this;31 }32 public RemoteWebDriverBuilder withCapabilities(Capabilities capabilities) {33 this.capabilities = capabilities;34 return this;35 }36 public RemoteWebDriverBuilder withCommandTimeout(int commandTimeout) {37 this.commandTimeout = commandTimeout;38 return this;39 }40 public RemoteWebDriverBuilder withConnectionTimeout(int connectionTimeout) {41 this.connectionTimeout = connectionTimeout;42 return this;43 }44 public RemoteWebDriverBuilder withProxy(Proxy proxy) {45 this.proxy = proxy;46 return this;47 }48 public RemoteWebDriverBuilder withFileDetector(FileDetector fileDetector) {49 this.fileDetector = fileDetector;50 return this;51 }52 public RemoteWebDriverBuilder withSessionId(String sessionId) {53 this.sessionId = new SessionId(sessionId);54 return this;55 }56 public RemoteWebDriverBuilder withPlatform(Platform platform) {57 this.platform = platform;58 return this;59 }60 public RemoteWebDriverBuilder withBrowserName(String browserName) {61 this.browserName = browserName;62 return this;63 }64 public RemoteWebDriverBuilder withVersion(String version) {65 this.version = version;66 return this;67 }68 public RemoteWebDriver build() {69 return new RemoteWebDriver(url, capabilities, commandTimeout, connectionTimeout, proxy, fileDetector, sessionId, platform, browserName, version);70 }71}

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1package com.example.selenium;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5import java.net.MalformedURLException;6import java.net.URL;7public class BuilderExample {8 public static void main(String[] args) {9 DesiredCapabilities capabilities = new DesiredCapabilities();10 capabilities.setBrowserName("chrome");11 capabilities.setVersion("66.0");12 capabilities.setCapability("enableVNC", true);13 capabilities.setCapability("enableVideo", false);14 WebDriver driver = new RemoteWebDriver(15 );16 }17}18package com.example.selenium;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.remote.DesiredCapabilities;21import org.openqa.selenium.remote.RemoteWebDriver;22import java.net.MalformedURLException;23import java.net.URL;24public class BuilderExample {25 public static void main(String[] args) {26 DesiredCapabilities capabilities = new DesiredCapabilities();27 capabilities.setBrowserName("chrome");28 capabilities.setVersion("66.0");29 capabilities.setCapability("enableVNC", true);30 capabilities.setCapability("enableVideo", false);31 WebDriver driver = new RemoteWebDriver(32 );33 }34}35package com.example.selenium;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.remote.DesiredCapabilities;38import org.openqa.selenium.remote.RemoteWebDriver;39import java.net.MalformedURLException;40import java.net.URL;41public class BuilderExample {42 public static void main(String[] args) {43 DesiredCapabilities capabilities = new DesiredCapabilities();44 capabilities.setBrowserName("chrome");45 capabilities.setVersion("66.0");46 capabilities.setCapability("enableVNC", true);47 capabilities.setCapability("enableVideo", false);48 WebDriver driver = new RemoteWebDriver(49 );50 }51}

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1RemoteWebDriver driver = new RemoteWebDriver.Builder()2 .withCapabilities(capabilities)3 .usingDriverExecutable(new File("C:\\Users\\user\\Downloads\\chromedriver_win32\\chromedriver.exe"))4 .usingAnyFreePort()5 .build();6System.out.println(driver.getTitle());7driver.close();8driver.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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful