How to use Interface LocationContext class of org.openqa.selenium.html5 package

Best Selenium code snippet using org.openqa.selenium.html5.Interface LocationContext

Source:OperaDriver.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.opera;18import org.openqa.selenium.Capabilities;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.WebDriverException;21import org.openqa.selenium.html5.LocalStorage;22import org.openqa.selenium.html5.Location;23import org.openqa.selenium.html5.LocationContext;24import org.openqa.selenium.html5.SessionStorage;25import org.openqa.selenium.html5.WebStorage;26import org.openqa.selenium.remote.FileDetector;27import org.openqa.selenium.remote.RemoteWebDriver;28import org.openqa.selenium.remote.html5.RemoteLocationContext;29import org.openqa.selenium.remote.html5.RemoteWebStorage;30import org.openqa.selenium.remote.service.DriverCommandExecutor;31/**32 * A {@link WebDriver} implementation that controls a Blink-based Opera browser running on the local33 * machine. This class is provided as a convenience for easily testing the Chrome browser. The34 * control server which each instance communicates with will live and die with the instance.35 *36 * To avoid unnecessarily restarting the OperaDriver server with each instance, use a37 * {@link RemoteWebDriver} coupled with the desired {@link OperaDriverService}, which is managed38 * separately. For example: <pre>{@code39 *40 * import static org.junit.Assert.assertEquals;41 *42 * import org.junit.*;43 * import org.junit.runner.RunWith;44 * import org.junit.runners.JUnit4;45 * import org.openqa.selenium.opera.OperaDriverService;46 * import org.openqa.selenium.remote.DesiredCapabilities;47 * import org.openqa.selenium.remote.RemoteWebDriver;48 *49 * {@literal @RunWith(JUnit4.class)}50 * public class OperaTest extends TestCase {51 *52 * private static OperaDriverService service;53 * private WebDriver driver;54 *55 * {@literal @BeforeClass}56 * public static void createAndStartService() {57 * service = new OperaDriverService.Builder()58 * .usingDriverExecutable(new File("path/to/my/operadriver.exe"))59 * .usingAnyFreePort()60 * .build();61 * service.start();62 * }63 *64 * {@literal @AfterClass}65 * public static void createAndStopService() {66 * service.stop();67 * }68 *69 * {@literal @Before}70 * public void createDriver() {71 * driver = new RemoteWebDriver(service.getUrl(),72 * DesiredCapabilities.opera());73 * }74 *75 * {@literal @After}76 * public void quitDriver() {77 * driver.quit();78 * }79 *80 * {@literal @Test}81 * public void testGoogleSearch() {82 * driver.get("http://www.google.com");83 * WebElement searchBox = driver.findElement(By.name("q"));84 * searchBox.sendKeys("webdriver");85 * searchBox.quit();86 * assertEquals("webdriver - Google Search", driver.getTitle());87 * }88 * }89 * }</pre>90 *91 * Note that unlike OperaDriver, RemoteWebDriver doesn't directly implement92 * role interfaces such as {@link LocationContext} and {@link WebStorage}.93 * Therefore, to access that functionality, it needs to be94 * {@link org.openqa.selenium.remote.Augmenter augmented} and then cast95 * to the appropriate interface.96 *97 * @see OperaDriverService#createDefaultService98 */99public class OperaDriver extends RemoteWebDriver100 implements LocationContext, WebStorage {101 private RemoteLocationContext locationContext;102 private RemoteWebStorage webStorage;103 /**104 * Creates a new OperaDriver using the {@link OperaDriverService#createDefaultService default}105 * server configuration.106 *107 * @see #OperaDriver(OperaDriverService, OperaOptions)108 */109 public OperaDriver() {110 this(OperaDriverService.createDefaultService(), new OperaOptions());111 }112 /**113 * Creates a new OperaDriver instance. The {@code service} will be started along with the driver,114 * and shutdown upon calling {@link #quit()}.115 *116 * @param service The service to use.117 * @see #OperaDriver(OperaDriverService, OperaOptions)118 */119 public OperaDriver(OperaDriverService service) {120 this(service, new OperaOptions());121 }122 /**123 * Creates a new OperaDriver instance. The {@code capabilities} will be passed to the124 * chromedriver service.125 *126 * @param capabilities The capabilities required from the OperaDriver.127 * @see #OperaDriver(OperaDriverService, Capabilities)128 * @deprecated Use {@link #OperaDriver(OperaOptions)} instead.129 */130 @Deprecated131 public OperaDriver(Capabilities capabilities) {132 this(OperaDriverService.createDefaultService(), capabilities);133 }134 /**135 * Creates a new OperaDriver instance with the specified options.136 *137 * @param options The options to use.138 * @see #OperaDriver(OperaDriverService, OperaOptions)139 */140 public OperaDriver(OperaOptions options) {141 this(OperaDriverService.createDefaultService(), options);142 }143 /**144 * Creates a new OperaDriver instance with the specified options. The {@code service} will be145 * started along with the driver, and shutdown upon calling {@link #quit()}.146 *147 * @param service The service to use.148 * @param options The options to use.149 */150 public OperaDriver(OperaDriverService service, OperaOptions options) {151 this(service, (Capabilities) options);152 }153 /**154 * Creates a new OperaDriver instance. The {@code service} will be started along with the155 * driver, and shutdown upon calling {@link #quit()}.156 *157 * @param service The service to use.158 * @param capabilities The capabilities required from the OperaDriver.159 * @deprecated Use {@link #OperaDriver(OperaDriverService, OperaOptions)} instead.160 */161 @Deprecated162 public OperaDriver(OperaDriverService service, Capabilities capabilities) {163 super(new DriverCommandExecutor(service), capabilities);164 locationContext = new RemoteLocationContext(getExecuteMethod());165 webStorage = new RemoteWebStorage(getExecuteMethod());166 }167 @Override168 public void setFileDetector(FileDetector detector) {169 throw new WebDriverException(170 "Setting the file detector only works on remote webdriver instances obtained " +171 "via RemoteWebDriver");172 }173 @Override174 public LocalStorage getLocalStorage() {175 return webStorage.getLocalStorage();176 }177 @Override178 public SessionStorage getSessionStorage() {179 return webStorage.getSessionStorage();180 }181 @Override182 public Location location() {183 return locationContext.location();184 }185 @Override186 public void setLocation(Location location) {187 locationContext.setLocation(location);188 }189}...

Full Screen

Full Screen

Source:ChromeDriver.java Github

copy

Full Screen

1/*2Copyright 2012 Selenium committers3Copyright 2012 Software Freedom Conservancy4Licensed under the Apache License, Version 2.0 (the "License");5you may not use this file except in compliance with the License.6You may obtain a copy of the License at7 http://www.apache.org/licenses/LICENSE-2.08Unless required by applicable law or agreed to in writing, software9distributed under the License is distributed on an "AS IS" BASIS,10WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11See the License for the specific language governing permissions and12limitations under the License.13*/14package org.openqa.selenium.chrome;15import org.openqa.selenium.Capabilities;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.WebDriverException;18import org.openqa.selenium.html5.LocalStorage;19import org.openqa.selenium.html5.Location;20import org.openqa.selenium.html5.LocationContext;21import org.openqa.selenium.html5.SessionStorage;22import org.openqa.selenium.html5.WebStorage;23import org.openqa.selenium.remote.FileDetector;24import org.openqa.selenium.remote.RemoteWebDriver;25import org.openqa.selenium.remote.html5.RemoteLocationContext;26import org.openqa.selenium.remote.html5.RemoteWebStorage;27import org.openqa.selenium.remote.service.DriverCommandExecutor;28/**29 * A {@link WebDriver} implementation that controls a Chrome browser running on the local machine.30 * This class is provided as a convenience for easily testing the Chrome browser. The control server31 * which each instance communicates with will live and die with the instance.32 * 33 * <p/>34 * To avoid unnecessarily restarting the ChromeDriver server with each instance, use a35 * {@link RemoteWebDriver} coupled with the desired {@link ChromeDriverService}, which is managed36 * separately. For example: <code><pre>37 * 38 * import static org.junit.Assert.assertEquals;39 * 40 * import org.junit.*;41 * import org.junit.runner.RunWith;42 * import org.junit.runners.JUnit4;43 * import org.openqa.selenium.chrome.ChromeDriverService;44 * import org.openqa.selenium.remote.DesiredCapabilities;45 * import org.openqa.selenium.remote.RemoteWebDriver;46 * 47 * {@literal @RunWith(JUnit4.class)}48 * public class ChromeTest extends TestCase {49 * 50 * private static ChromeDriverService service;51 * private WebDriver driver;52 * 53 * {@literal @BeforeClass}54 * public static void createAndStartService() {55 * service = new ChromeDriverService.Builder()56 * .usingChromeDriverExecutable(new File("path/to/my/chromedriver.exe"))57 * .usingAnyFreePort()58 * .build();59 * service.start();60 * }61 * 62 * {@literal @AfterClass}63 * public static void createAndStopService() {64 * service.stop();65 * }66 * 67 * {@literal @Before}68 * public void createDriver() {69 * driver = new RemoteWebDriver(service.getUrl(),70 * DesiredCapabilities.chrome());71 * }72 * 73 * {@literal @After}74 * public void quitDriver() {75 * driver.quit();76 * }77 * 78 * {@literal @Test}79 * public void testGoogleSearch() {80 * driver.get("http://www.google.com");81 * WebElement searchBox = driver.findElement(By.name("q"));82 * searchBox.sendKeys("webdriver");83 * searchBox.quit();84 * assertEquals("webdriver - Google Search", driver.getTitle());85 * }86 * }87 * </pre></code>88 *89 * Note that unlike ChromeDriver, RemoteWebDriver doesn't directly implement90 * role interfaces such as {@link LocationContext} and {@link WebStorage}.91 * Therefore, to access that functionality, it needs to be92 * {@link org.openqa.selenium.remote.Augmenter augmented} and then cast93 * to the appropriate interface.94 *95 * @see ChromeDriverService#createDefaultService96 */97public class ChromeDriver extends RemoteWebDriver98 implements LocationContext, WebStorage {99 private RemoteLocationContext locationContext;100 private RemoteWebStorage webStorage;101 /**102 * Creates a new ChromeDriver using the {@link ChromeDriverService#createDefaultService default}103 * server configuration.104 *105 * @see #ChromeDriver(ChromeDriverService, ChromeOptions)106 */107 public ChromeDriver() {108 this(ChromeDriverService.createDefaultService(), new ChromeOptions());109 }110 /**111 * Creates a new ChromeDriver instance. The {@code service} will be started along with the driver,112 * and shutdown upon calling {@link #quit()}.113 * 114 * @param service The service to use.115 * @see #ChromeDriver(ChromeDriverService, ChromeOptions)116 */117 public ChromeDriver(ChromeDriverService service) {118 this(service, new ChromeOptions());119 }120 /**121 * Creates a new ChromeDriver instance. The {@code capabilities} will be passed to the122 * chromedriver service.123 * 124 * @param capabilities The capabilities required from the ChromeDriver.125 * @see #ChromeDriver(ChromeDriverService, Capabilities)126 */127 public ChromeDriver(Capabilities capabilities) {128 this(ChromeDriverService.createDefaultService(), capabilities);129 }130 /**131 * Creates a new ChromeDriver instance with the specified options.132 *133 * @param options The options to use.134 * @see #ChromeDriver(ChromeDriverService, ChromeOptions)135 */136 public ChromeDriver(ChromeOptions options) {137 this(ChromeDriverService.createDefaultService(), options);138 }139 /**140 * Creates a new ChromeDriver instance with the specified options. The {@code service} will be141 * started along with the driver, and shutdown upon calling {@link #quit()}.142 *143 * @param service The service to use.144 * @param options The options to use.145 */146 public ChromeDriver(ChromeDriverService service, ChromeOptions options) {147 this(service, options.toCapabilities());148 }149 /**150 * Creates a new ChromeDriver instance. The {@code service} will be started along with the151 * driver, and shutdown upon calling {@link #quit()}.152 *153 * @param service The service to use.154 * @param capabilities The capabilities required from the ChromeDriver.155 */156 public ChromeDriver(ChromeDriverService service, Capabilities capabilities) {157 super(new DriverCommandExecutor(service), capabilities);158 locationContext = new RemoteLocationContext(getExecuteMethod());159 webStorage = new RemoteWebStorage(getExecuteMethod());160 }161 @Override162 public void setFileDetector(FileDetector detector) {163 throw new WebDriverException(164 "Setting the file detector only works on remote webdriver instances obtained " +165 "via RemoteWebDriver");166 }167 @Override168 public LocalStorage getLocalStorage() {169 return webStorage.getLocalStorage();170 }171 @Override172 public SessionStorage getSessionStorage() {173 return webStorage.getSessionStorage();174 }175 @Override176 public Location location() {177 return locationContext.location();178 }179 @Override180 public void setLocation(Location location) {181 locationContext.setLocation(location);182 }183}...

Full Screen

Full Screen

Source:ChromiumDriver.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.chromium;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.devtools.Connection;23import org.openqa.selenium.devtools.DevTools;24import org.openqa.selenium.devtools.HasDevTools;25import org.openqa.selenium.html5.LocalStorage;26import org.openqa.selenium.html5.Location;27import org.openqa.selenium.html5.LocationContext;28import org.openqa.selenium.html5.SessionStorage;29import org.openqa.selenium.html5.WebStorage;30import org.openqa.selenium.interactions.HasTouchScreen;31import org.openqa.selenium.interactions.TouchScreen;32import org.openqa.selenium.mobile.NetworkConnection;33import org.openqa.selenium.remote.CommandExecutor;34import org.openqa.selenium.remote.FileDetector;35import org.openqa.selenium.remote.RemoteTouchScreen;36import org.openqa.selenium.remote.RemoteWebDriver;37import org.openqa.selenium.remote.html5.RemoteLocationContext;38import org.openqa.selenium.remote.html5.RemoteWebStorage;39import org.openqa.selenium.remote.http.HttpClient;40import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;41import java.util.Map;42import java.util.Objects;43import java.util.Optional;44/**45 * A {@link WebDriver} implementation that controls a Chromium browser running on the local machine.46 * This class is provided as a convenience for easily testing the Chromium browser. The control server47 * which each instance communicates with will live and die with the instance.48 *49 * To avoid unnecessarily restarting the ChromiumDriver server with each instance, use a50 * {@link RemoteWebDriver} coupled with the desired WebDriverService, which is managed51 * separately.52 *53 * Note that unlike ChromiumDriver, RemoteWebDriver doesn't directly implement54 * role interfaces such as {@link LocationContext} and {@link WebStorage}.55 * Therefore, to access that functionality, it needs to be56 * {@link org.openqa.selenium.remote.Augmenter augmented} and then cast57 * to the appropriate interface.58 */59public class ChromiumDriver extends RemoteWebDriver60 implements HasDevTools, HasTouchScreen, LocationContext, NetworkConnection, WebStorage {61 private final RemoteLocationContext locationContext;62 private final RemoteWebStorage webStorage;63 private final TouchScreen touchScreen;64 private final RemoteNetworkConnection networkConnection;65 private final Optional<Connection> connection;66 protected ChromiumDriver(CommandExecutor commandExecutor, Capabilities capabilities, String capabilityKey) {67 super(commandExecutor, capabilities);68 locationContext = new RemoteLocationContext(getExecuteMethod());69 webStorage = new RemoteWebStorage(getExecuteMethod());70 touchScreen = new RemoteTouchScreen(getExecuteMethod());71 networkConnection = new RemoteNetworkConnection(getExecuteMethod());72 HttpClient.Factory factory = HttpClient.Factory.createDefault();73 connection = ChromiumDevToolsLocator.getChromeConnector(74 factory,75 getCapabilities(),76 capabilityKey);77 }78 @Override79 public void setFileDetector(FileDetector detector) {80 throw new WebDriverException(81 "Setting the file detector only works on remote webdriver instances obtained " +82 "via RemoteWebDriver");83 }84 @Override85 public LocalStorage getLocalStorage() {86 return webStorage.getLocalStorage();87 }88 @Override89 public SessionStorage getSessionStorage() {90 return webStorage.getSessionStorage();91 }92 @Override93 public Location location() {94 return locationContext.location();95 }96 @Override97 public void setLocation(Location location) {98 locationContext.setLocation(location);99 }100 @Override101 public TouchScreen getTouch() {102 return touchScreen;103 }104 @Override105 public ConnectionType getNetworkConnection() {106 return networkConnection.getNetworkConnection();107 }108 @Override109 public ConnectionType setNetworkConnection(ConnectionType type) {110 return networkConnection.setNetworkConnection(type);111 }112 /**113 * Launches Chrome app specified by id.114 *115 * @param id Chrome app id.116 */117 public void launchApp(String id) {118 execute(ChromiumDriverCommand.LAUNCH_APP, ImmutableMap.of("id", id));119 }120 /**121 * Execute a Chrome Devtools Protocol command and get returned result. The122 * command and command args should follow123 * <a href="https://chromedevtools.github.io/devtools-protocol/">chrome124 * devtools protocol domains/commands</a>.125 */126 public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) {127 Objects.requireNonNull(commandName, "Command name must be set.");128 Objects.requireNonNull(parameters, "Parameters for command must be set.");129 @SuppressWarnings("unchecked")130 Map<String, Object> toReturn = (Map<String, Object>) getExecuteMethod().execute(131 ChromiumDriverCommand.EXECUTE_CDP_COMMAND,132 ImmutableMap.of("cmd", commandName, "params", parameters));133 return ImmutableMap.copyOf(toReturn);134 }135 @Override136 public DevTools getDevTools() {137 return connection.map(DevTools::new)138 .orElseThrow(() -> new WebDriverException("Unable to create DevTools connection"));139 }140 @Override141 public void quit() {142 connection.ifPresent(Connection::close);143 super.quit();144 }145}...

Full Screen

Full Screen

Source:UtilsTest.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.remote.server.handler.html5;18import static org.junit.Assert.assertEquals;19import static org.junit.Assert.assertSame;20import static org.junit.Assert.fail;21import static org.mockito.Mockito.mock;22import static org.mockito.Mockito.reset;23import static org.mockito.Mockito.verify;24import static org.mockito.Mockito.when;25import com.google.common.collect.ImmutableMap;26import org.junit.Test;27import org.junit.runner.RunWith;28import org.junit.runners.JUnit4;29import org.openqa.selenium.HasCapabilities;30import org.openqa.selenium.UnsupportedCommandException;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.html5.AppCacheStatus;33import org.openqa.selenium.html5.ApplicationCache;34import org.openqa.selenium.html5.LocalStorage;35import org.openqa.selenium.html5.Location;36import org.openqa.selenium.html5.LocationContext;37import org.openqa.selenium.html5.SessionStorage;38import org.openqa.selenium.html5.WebStorage;39import org.openqa.selenium.remote.CapabilityType;40import org.openqa.selenium.remote.DesiredCapabilities;41import org.openqa.selenium.remote.DriverCommand;42import org.openqa.selenium.remote.ExecuteMethod;43/**44 * Tests for the {@link Utils} class.45 */46@RunWith(JUnit4.class)47public class UtilsTest {48 @Test49 public void returnsInputDriverIfRequestedFeatureIsImplementedDirectly() {50 WebDriver driver = mock(Html5Driver.class);51 assertSame(driver, Utils.getApplicationCache(driver));52 assertSame(driver, Utils.getLocationContext(driver));53 assertSame(driver, Utils.getWebStorage(driver));54 }55 @Test56 public void throwsIfRequestedFeatureIsNotSupported() {57 WebDriver driver = mock(WebDriver.class);58 try {59 Utils.getApplicationCache(driver);60 fail();61 } catch (UnsupportedCommandException expected) {62 // Do nothing.63 }64 try {65 Utils.getLocationContext(driver);66 fail();67 } catch (UnsupportedCommandException expected) {68 // Do nothing.69 }70 try {71 Utils.getWebStorage(driver);72 fail();73 } catch (UnsupportedCommandException expected) {74 // Do nothing.75 }76 }77 @Test78 public void providesRemoteAccessToAppCache() {79 DesiredCapabilities caps = new DesiredCapabilities();80 caps.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);81 CapableDriver driver = mock(CapableDriver.class);82 when(driver.getCapabilities()).thenReturn(caps);83 when(driver.execute(DriverCommand.GET_APP_CACHE_STATUS, null))84 .thenReturn(AppCacheStatus.CHECKING.name());85 ApplicationCache cache = Utils.getApplicationCache(driver);86 assertEquals(AppCacheStatus.CHECKING, cache.getStatus());87 }88 @Test89 public void providesRemoteAccessToLocationContext() {90 DesiredCapabilities caps = new DesiredCapabilities();91 caps.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);92 CapableDriver driver = mock(CapableDriver.class);93 when(driver.getCapabilities()).thenReturn(caps);94 when(driver.execute(DriverCommand.GET_LOCATION, null)).thenReturn(95 ImmutableMap.of("latitude", 1.2, "longitude", 3.4, "altitude", 5.6));96 LocationContext context = Utils.getLocationContext(driver);97 Location location = context.location();98 assertEquals(1.2, location.getLatitude(), 0.001);99 assertEquals(3.4, location.getLongitude(), 0.001);100 assertEquals(5.6, location.getAltitude(), 0.001);101 reset(driver);102 location = new Location(7, 8, 9);103 context.setLocation(location);104 verify(driver).execute(DriverCommand.SET_LOCATION, ImmutableMap.of("location", location));105 }106 @Test107 public void providesRemoteAccessToWebStorage() {108 DesiredCapabilities caps = new DesiredCapabilities();109 caps.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, true);110 CapableDriver driver = mock(CapableDriver.class);111 when(driver.getCapabilities()).thenReturn(caps);112 WebStorage storage = Utils.getWebStorage(driver);113 LocalStorage localStorage = storage.getLocalStorage();114 SessionStorage sessionStorage = storage.getSessionStorage();115 localStorage.setItem("foo", "bar");116 sessionStorage.setItem("bim", "baz");117 verify(driver).execute(DriverCommand.SET_LOCAL_STORAGE_ITEM, ImmutableMap.of(118 "key", "foo", "value", "bar"));119 verify(driver).execute(DriverCommand.SET_SESSION_STORAGE_ITEM, ImmutableMap.of(120 "key", "bim", "value", "baz"));121 }122 interface CapableDriver extends WebDriver, ExecuteMethod, HasCapabilities {123 }124 interface Html5Driver extends WebDriver, ApplicationCache, LocationContext, WebStorage {125 }126}...

Full Screen

Full Screen

Source:Utils.java Github

copy

Full Screen

1/*2Copyright 2012-2014 Software Freedom Conservancy3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13package org.openqa.selenium.remote.server.handler.html5;14import com.google.common.base.Throwables;15import org.openqa.selenium.HasCapabilities;16import org.openqa.selenium.UnsupportedCommandException;17import org.openqa.selenium.WebDriver;18import org.openqa.selenium.WebDriverException;19import org.openqa.selenium.html5.ApplicationCache;20import org.openqa.selenium.html5.DatabaseStorage;21import org.openqa.selenium.html5.LocationContext;22import org.openqa.selenium.html5.WebStorage;23import org.openqa.selenium.remote.CapabilityType;24import org.openqa.selenium.remote.ExecuteMethod;25import org.openqa.selenium.remote.html5.RemoteApplicationCache;26import org.openqa.selenium.remote.html5.RemoteDatabaseStorage;27import org.openqa.selenium.remote.html5.RemoteLocationContext;28import org.openqa.selenium.remote.html5.RemoteWebStorage;29import java.lang.reflect.InvocationTargetException;30/**31 * Provides utility methods for converting a {@link WebDriver} instance to the various HTML532 * role interfaces. Each method will throw an {@link UnsupportedCommandException} if the driver33 * does not support the corresponding HTML5 feature.34 */35class Utils {36 static ApplicationCache getApplicationCache(WebDriver driver) {37 return convert(driver, ApplicationCache.class, CapabilityType.SUPPORTS_APPLICATION_CACHE,38 RemoteApplicationCache.class);39 }40 static LocationContext getLocationContext(WebDriver driver) {41 return convert(driver, LocationContext.class, CapabilityType.SUPPORTS_LOCATION_CONTEXT,42 RemoteLocationContext.class);43 }44 static DatabaseStorage getDatabaseStorage(WebDriver driver) {45 return convert(driver, DatabaseStorage.class, CapabilityType.SUPPORTS_SQL_DATABASE,46 RemoteDatabaseStorage.class);47 }48 static WebStorage getWebStorage(WebDriver driver) {49 return convert(driver, WebStorage.class, CapabilityType.SUPPORTS_WEB_STORAGE,50 RemoteWebStorage.class);51 }52 private static <T> T convert(53 WebDriver driver, Class<T> interfaceClazz, String capability,54 Class<? extends T> remoteImplementationClazz) {55 if (interfaceClazz.isInstance(driver)) {56 return interfaceClazz.cast(driver);57 }58 if (driver instanceof ExecuteMethod59 && driver instanceof HasCapabilities60 && ((HasCapabilities) driver).getCapabilities().is(capability)) {61 try {62 return remoteImplementationClazz63 .getConstructor(ExecuteMethod.class)64 .newInstance((ExecuteMethod) driver);65 } catch (InstantiationException e) {66 throw new WebDriverException(e);67 } catch (IllegalAccessException e) {68 throw new WebDriverException(e);69 } catch (InvocationTargetException e) {70 throw Throwables.propagate(e.getCause());71 } catch (NoSuchMethodException e) {72 throw new WebDriverException(e);73 }74 }75 throw new UnsupportedCommandException(76 "driver (" + driver.getClass().getName() + ") does not support "77 + interfaceClazz.getName());78 }79}...

Full Screen

Full Screen

Interface LocationContext

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.html5.Location;2import org.openqa.selenium.html5.LocationContext;3import org.openqa.selenium.html5.LocationContext;4import org.openqa.selenium.html5.LocationContext;5import org.openqa.selenium.html5.LocationContext;6import org.openqa.selenium.html5.LocationContext;7import org.openqa.selenium.html5.LocationContext;8import org.openqa.selenium.html5.LocationContext;9import org.openqa.selenium.html5.LocationContext;10import org.openqa.selenium.html5.LocationContext;11import org.openqa.selenium.html5.LocationContext;12import org.openqa.selenium.html5.LocationContext;13import org.openqa.selenium.html5.LocationContext;14import org.openqa.selenium.html5.LocationContext;15import org.openqa.selenium.html5.LocationContext;16import org.openqa.selenium.html5.LocationContext;17import org.openqa.selenium.html5.LocationContext;18import org.openqa.selenium.html5.LocationContext;19import org.openqa.selenium.html5.LocationContext;20import org.openqa.selenium.html5.LocationContext;21import org.openqa.selenium.html5.LocationContext;22import org.openqa.selenium.html5.LocationContext;23import org.openqa.selenium.html5.LocationContext;24import org.openqa.selenium.html5.LocationContext;25import org.openqa.selenium.html5.LocationContext;26import org.openqa.selenium.html5.LocationContext;27import org.openqa.selenium.html5.LocationContext;28import org.openqa.selenium.html5.LocationContext;29import org.openqa.selenium.html5.LocationContext;30import org.openqa.selenium.html5.LocationContext;31import org.openqa.selenium.html5.LocationContext;32import org.openqa.selenium.html5.LocationContext;33import org.openqa.selenium.html5.LocationContext;34import org.openqa.selenium.html5.LocationContext;35import org.openqa.selenium.html5.LocationContext;36import org.openqa.selenium.html5.LocationContext;37import org.openqa.selenium.html5.LocationContext;38import org.openqa.selenium.html5.LocationContext;39import org.openqa.selenium.html5.LocationContext;40import org.openqa.selenium.html5.LocationContext;41import org.openqa.selenium.html5.LocationContext;42import org.openqa.selenium.html5.LocationContext;43import org.openqa.selenium.html5.LocationContext;44import org.openqa.selenium.html5.LocationContext;45import org.openqa.selenium.html5.LocationContext;46import org.openqa.selenium.html5.LocationContext;47import org.openqa.selenium.html5.LocationContext;48import org.openqa.selenium.html5.LocationContext;49import org.openqa.selenium.html5.LocationContext;50import org.openqa.selenium.html5.LocationContext;51import org.openqa.selenium.html5.LocationContext;52import org.openqa.selenium.html5.LocationContext;53import org.openqa.selenium.html5.LocationContext;54import org.openqa.selenium.html5.LocationContext;55import org.openqa.selenium.html5.LocationContext;56import org.openqa.selenium

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.

Most used methods in Interface-LocationContext

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