How to use Interface DriverCommand class of org.openqa.selenium.remote package

Best Selenium code snippet using org.openqa.selenium.remote.Interface DriverCommand

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:EventListener.java Github

copy

Full Screen

1/*-------------------------------------------------------------------------------------------------------------------*\2| Copyright (C) 2015 PayPal |3| |4| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |5| with the License. |6| |7| You may obtain a copy of the License at |8| |9| http://www.apache.org/licenses/LICENSE-2.0 |10| |11| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed |12| on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for |13| the specific language governing permissions and limitations under the License. |14\*-------------------------------------------------------------------------------------------------------------------*/15package com.paypal.selion.platform.grid;16import org.openqa.selenium.remote.Command;17/**18 * This class is invoked by {@link EventFiringCommandExecutor} when ever selenium command gets executed.19 */20public interface EventListener {21 /**22 * This method will be called by {@link EventFiringCommandExecutor} BEFORE executing each selenium command.23 *24 * @param command - A {@link org.openqa.selenium.remote.Command} that represents the command being executed by25 * Selenium.26 * In order to filter out specific commands you may extract the actual command via27 * {@link org.openqa.selenium.remote.Command#getName()} and then compare it with the predefined set of28 * commands available as strings in {@link org.openqa.selenium.remote.DriverCommand}29 */30 void beforeEvent(Command command);31 /**32 * This method will be called by {@link EventFiringCommandExecutor} AFTER executing each selenium command.33 *34 * @param command - A {@link org.openqa.selenium.remote.Command} that represents the command being executed by35 * Selenium.36 * In order to filter out specific commands you may extract the actual command via37 * {@link org.openqa.selenium.remote.Command#getName()} and then compare it with the predefined set of38 * commands available as strings in {@link org.openqa.selenium.remote.DriverCommand}39 */40 void afterEvent(Command command);41}...

Full Screen

Full Screen

Source:AddDatabaseStorage.java Github

copy

Full Screen

1/*2Copyright 2007-2010 WebDriver committers3Copyright 2007-2010 Google Inc.45Licensed under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at89 http://www.apache.org/licenses/LICENSE-2.01011Unless required by applicable law or agreed to in writing, software12distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions and15limitations under the License.16*/1718package org.openqa.selenium.remote.html5;1920import java.lang.reflect.Method;21import java.util.List;22import java.util.Map;2324import org.openqa.selenium.html5.DatabaseStorage;25import org.openqa.selenium.html5.ResultSet;26import org.openqa.selenium.html5.ResultSetRows;27import org.openqa.selenium.remote.AugmenterProvider;28import org.openqa.selenium.remote.DriverCommand;29import org.openqa.selenium.remote.ExecuteMethod;30import org.openqa.selenium.remote.InterfaceImplementation;31import org.openqa.selenium.remote.internal.WebElementToJsonConverter;3233import com.google.common.collect.ImmutableMap;34import com.google.common.collect.Iterables;35import com.google.common.collect.Lists;3637public class AddDatabaseStorage implements AugmenterProvider {3839 public Class<?> getDescribedInterface() {40 return DatabaseStorage.class;41 }4243 public InterfaceImplementation getImplementation(Object value) {44 return new InterfaceImplementation() {45 public Object invoke(ExecuteMethod executeMethod, Object self, Method method, Object... args) {46 String databaseName = (String) args[0];47 String query = (String) args[1];48 Object[] arguments = (Object[]) args[2];49 50 query.replaceAll("\"", "\\\"");51 Iterable<Object> convertedArgs = Iterables.transform(52 Lists.newArrayList(arguments), new WebElementToJsonConverter());53 54 Map<String, ?> params = ImmutableMap.of(55 "dbName", databaseName,56 "query", query,57 "args", Lists.newArrayList(convertedArgs));58 59 Map<Object, Object> resultAsMap =60 (Map<Object, Object>) executeMethod.execute(DriverCommand.EXECUTE_SQL, params);61 ResultSet rs = new ResultSet(((Long) resultAsMap.get("insertId")).intValue(),62 ((Long) resultAsMap.get("rowsAffected")).intValue(),63 new ResultSetRows((List<Map<String, Object>>) resultAsMap.get("rows")));64 return rs;65 }66 };67 }68} ...

Full Screen

Full Screen

Source:AddApplicationCache.java Github

copy

Full Screen

1/*2Copyright 2007-2010 WebDriver committers3Copyright 2007-2010 Google Inc.4Licensed 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.remote.html5;15import java.lang.reflect.Method;16import java.util.List;17import java.util.Map;18import org.openqa.selenium.html5.AppCacheEntry;19import org.openqa.selenium.html5.AppCacheStatus;20import org.openqa.selenium.html5.AppCacheType;21import org.openqa.selenium.html5.ApplicationCache;22import org.openqa.selenium.remote.AugmenterProvider;23import org.openqa.selenium.remote.DriverCommand;24import org.openqa.selenium.remote.ExecuteMethod;25import org.openqa.selenium.remote.InterfaceImplementation;26import com.google.common.collect.Lists;27public class AddApplicationCache implements AugmenterProvider {28 public Class<?> getDescribedInterface() {29 return ApplicationCache.class;30 }31 public InterfaceImplementation getImplementation(Object value) {32 return new InterfaceImplementation() {33 34 public Object invoke(ExecuteMethod executeMethod, Object self, Method method, Object... args) {35 if ("getAppCache".equals(method.getName())) {36 List<Object> result = (List<Object>) executeMethod.execute(DriverCommand.GET_APP_CACHE,37 null);38 List<AppCacheEntry> toReturn = Lists.newArrayList();39 for (Object obj : result) {40 Map<String, String> map = (Map<String, String>) obj;41 AppCacheEntry entry = new AppCacheEntry(AppCacheType.valueOf(map.get("type")),42 map.get("url"), map.get("mimeType"));43 toReturn.add(entry);44 }45 return toReturn;46 } else if ("getStatus".equals(method.getName())) {47 String result = (String) executeMethod.execute(DriverCommand.GET_APP_CACHE_STATUS, null);48 return AppCacheStatus.valueOf(result);49 }50 return null;51 }52 };53 }54 55}...

Full Screen

Full Screen

Source:AddLocationContext.java Github

copy

Full Screen

1/*2Copyright 2007-2010 WebDriver committers3Copyright 2007-2010 Google Inc.45Licensed under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at89 http://www.apache.org/licenses/LICENSE-2.01011Unless required by applicable law or agreed to in writing, software12distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions and15limitations under the License.16*/1718package org.openqa.selenium.remote.html5;1920import java.lang.reflect.Method;21import java.util.Map;2223import org.openqa.selenium.html5.Location;24import org.openqa.selenium.html5.LocationContext;25import org.openqa.selenium.remote.AugmenterProvider;26import org.openqa.selenium.remote.DriverCommand;27import org.openqa.selenium.remote.ExecuteMethod;28import org.openqa.selenium.remote.InterfaceImplementation;2930import com.google.common.collect.ImmutableMap;3132public class AddLocationContext implements AugmenterProvider {3334 public Class<?> getDescribedInterface() {35 return LocationContext.class;36 }3738 public InterfaceImplementation getImplementation(Object value) {39 return new InterfaceImplementation() {40 41 public Object invoke(ExecuteMethod executeMethod, Object self, Method method, Object... args) {42 if ("location".equals(method.getName())) {43 Map<Object, Object> map =44 (Map<Object, Object>) executeMethod.execute(DriverCommand.GET_LOCATION, null);45 double latitude = Long.valueOf((Long) map.get("latitude")).doubleValue();46 double longitude = Long.valueOf((Long) map.get("longitude")).doubleValue();47 double altitude = Long.valueOf((Long) map.get("altitude")).doubleValue();48 return new Location(latitude, longitude, altitude);49 } else if ("setLocation".equals(method.getName())) {50 return executeMethod.execute(DriverCommand.SET_LOCATION, ImmutableMap.of("location", args[0]));51 }52 return null;53 }54 };55 }5657} ...

Full Screen

Full Screen

Source:AddBrowserConnection.java Github

copy

Full Screen

1/*2Copyright 2007-2010 WebDriver committers3Copyright 2007-2010 Google Inc.45Licensed under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at89 http://www.apache.org/licenses/LICENSE-2.01011Unless required by applicable law or agreed to in writing, software12distributed under the License is distributed on an "AS IS" BASIS,13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14See the License for the specific language governing permissions and15limitations under the License.16*/1718package org.openqa.selenium.remote.html5;1920import java.lang.reflect.Method;2122import org.openqa.selenium.html5.BrowserConnection;23import org.openqa.selenium.remote.AugmenterProvider;24import org.openqa.selenium.remote.DriverCommand;25import org.openqa.selenium.remote.ExecuteMethod;26import org.openqa.selenium.remote.InterfaceImplementation;2728import com.google.common.collect.ImmutableMap;2930public class AddBrowserConnection implements AugmenterProvider {3132 public Class<?> getDescribedInterface() {33 return BrowserConnection.class;34 }35 36 public InterfaceImplementation getImplementation(Object value) {37 return new InterfaceImplementation() {38 39 public Object invoke(ExecuteMethod executeMethod, Object self, Method method,40 Object... args) {41 if ("setOnline".equals(method.getName())) {42 return executeMethod.execute(DriverCommand.SET_BROWSER_ONLINE,43 ImmutableMap.of("state", args[0]));44 } else if ("isOnline".equals(method.getName())) {45 return executeMethod.execute(DriverCommand.IS_BROWSER_ONLINE, null);46 }47 return null;48 }49 };50 }51} ...

Full Screen

Full Screen

Interface DriverCommand

Using AI Code Generation

copy

Full Screen

1package com.selenium.webdriver;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.firefox.FirefoxDriver;4import org.openqa.selenium.remote.DriverCommand;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.remote.Response;7public class DriverCommandExample {8public static void main(String[] args) {9WebDriver driver = new FirefoxDriver();10String url = driver.getCurrentUrl();11System.out.println(url);12RemoteWebDriver rwd = (RemoteWebDriver)driver;13Response response = rwd.execute(DriverCommand.GET_CURRENT_URL);14System.out.println(response.getValue());15driver.quit();16}17}

Full Screen

Full Screen

Interface DriverCommand

Using AI Code Generation

copy

Full Screen

1package com.packt.webdriver.chapter1;2import org.openqa.selenium.By;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.firefox.FirefoxDriver;7public class ExecuteJavaScript {8public static void main(String... args) {9WebDriver driver = new FirefoxDriver();10WebElement element = driver.findElement(By.name("q"));11element.sendKeys("Packt Publishing");12element.submit();13JavascriptExecutor js = (JavascriptExecutor)driver;14js.executeScript("alert('Welcome to Packt Publishing!');");15}16}

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