How to use copyOf method of org.openqa.selenium.ImmutableCapabilities class

Best Selenium code snippet using org.openqa.selenium.ImmutableCapabilities.copyOf

Source:NodeStatus.java Github

copy

Full Screen

...47 this.nodeId = Objects.requireNonNull(nodeId);48 this.externalUri = Objects.requireNonNull(externalUri);49 Preconditions.checkArgument(maxSessionCount > 0, "Max session count must be greater than 0.");50 this.maxSessionCount = maxSessionCount;51 this.stereotypes = ImmutableMap.copyOf(Objects.requireNonNull(stereotypes));52 this.snapshot = ImmutableSet.copyOf(Objects.requireNonNull(snapshot));53 }54 public boolean hasCapacity() {55 return !stereotypes.isEmpty();56 }57 public boolean hasCapacity(Capabilities caps) {58 return stereotypes.getOrDefault(caps, 0) > 0;59 }60 public UUID getNodeId() {61 return nodeId;62 }63 public URI getUri() {64 return externalUri;65 }66 public int getMaxSessionCount() {67 return maxSessionCount;68 }69 public Map<Capabilities, Integer> getStereotypes() {70 return stereotypes;71 }72 public Set<Active> getCurrentSessions() {73 return snapshot;74 }75 @Override76 public boolean equals(Object o) {77 if (!(o instanceof NodeStatus)) {78 return false;79 }80 NodeStatus that = (NodeStatus) o;81 return Objects.equals(this.nodeId, that.nodeId) &&82 Objects.equals(this.externalUri, that.externalUri) &&83 this.maxSessionCount == that.maxSessionCount &&84 Objects.equals(this.stereotypes, that.stereotypes) &&85 Objects.equals(this.snapshot, that.snapshot);86 }87 @Override88 public int hashCode() {89 return Objects.hash(nodeId, externalUri, maxSessionCount, stereotypes, snapshot);90 }91 private Map<String, Object> toJson() {92 return ImmutableMap.of(93 "id", nodeId,94 "uri", externalUri,95 "maxSessions", maxSessionCount,96 "stereotypes", asCapacity(stereotypes),97 "sessions", snapshot);98 }99 private List<Map<String, Object>> asCapacity(Map<Capabilities, Integer> toConvert) {100 ImmutableList.Builder<Map<String, Object>> toReturn = ImmutableList.builder();101 toConvert.forEach((caps, count) -> {102 toReturn.add(ImmutableMap.of(103 "capabilities", caps,104 "count", count));105 });106 return toReturn.build();107 }108 public static NodeStatus fromJson(Map<String, Object> raw) {109 List<Active> sessions = ((Collection<?>) raw.get("sessions")).stream()110 .map(item -> {111 @SuppressWarnings("unchecked")112 Map<String, Object> converted = (Map<String, Object>) item;113 return converted;114 })115 .map(Active::fromJson)116 .collect(toImmutableList());117 try {118 return new NodeStatus(119 UUID.fromString((String) raw.get("id")),120 new URI((String) raw.get("uri")),121 ((Number) raw.get("maxSessions")).intValue(),122 readCapacityNamed(raw, "stereotypes"),123 sessions);124 } catch (URISyntaxException e) {125 throw new JsonException(e);126 }127 }128 private static Map<Capabilities, Integer> readCapacityNamed(129 Map<String, Object> raw,130 String name) {131 ImmutableMap.Builder<Capabilities, Integer> capacity = ImmutableMap.builder();132 ((Collection<?>) raw.get(name)).forEach(obj -> {133 Map<?, ?> cap = (Map<?, ?>) obj;134 capacity.put(135 new ImmutableCapabilities((Map<?, ?>) cap.get("capabilities")),136 ((Number) cap.get("count")).intValue());137 });138 return capacity.build();139 }140 public static class Active {141 private final Capabilities stereotype;142 private final SessionId id;143 private final Capabilities currentCapabilities;144 public Active(Capabilities stereotype, SessionId id, Capabilities currentCapabilities) {145 this.stereotype = ImmutableCapabilities.copyOf(Objects.requireNonNull(stereotype));146 this.id = Objects.requireNonNull(id);147 this.currentCapabilities =148 ImmutableCapabilities.copyOf(Objects.requireNonNull(currentCapabilities));149 }150 public Capabilities getStereotype() {151 return stereotype;152 }153 public SessionId getSessionId() {154 return id;155 }156 public Capabilities getCurrentCapabilities() {157 return currentCapabilities;158 }159 @Override160 public boolean equals(Object o) {161 if (!(o instanceof Active)) {162 return false;...

Full Screen

Full Screen

Source:Session.java Github

copy

Full Screen

...39 public Session(SessionId id, URI uri, Capabilities stereotype, Capabilities capabilities, Instant startTime) {40 this.id = Require.nonNull("Session ID", id);41 this.uri = Require.nonNull("Where the session is running", uri);42 this.startTime = Require.nonNull("Start time", startTime);43 this.stereotype = ImmutableCapabilities.copyOf(Require.nonNull("Stereotype", stereotype));44 this.capabilities = ImmutableCapabilities.copyOf(45 Require.nonNull("Session capabilities", capabilities));46 }47 public SessionId getId() {48 return id;49 }50 public URI getUri() {51 return uri;52 }53 public Capabilities getStereotype() {54 return stereotype;55 }56 public Capabilities getCapabilities() {57 return capabilities;58 }59 public Instant getStartTime() {60 return startTime;61 }62 private Map<String, Object> toJson() {63 // Deliberately shaped like the return value for the W3C New Session command's return value.64 return ImmutableMap.of(65 "capabilities", getCapabilities(),66 "sessionId", getId().toString(),67 "stereotype", getStereotype(),68 "start", getStartTime(),69 "uri", getUri());70 }71 private static Session fromJson(JsonInput input) {72 SessionId id = null;73 URI uri = null;74 Capabilities caps = null;75 Capabilities stereotype = null;76 Instant start = null;77 input.beginObject();78 while (input.hasNext()) {79 switch (input.nextName()) {80 case "capabilities":81 caps = ImmutableCapabilities.copyOf(input.read(Capabilities.class));82 break;83 case "sessionId":84 id = input.read(SessionId.class);85 break;86 case "start":87 start = input.read(Instant.class);88 break;89 case "stereotype":90 stereotype = input.read(Capabilities.class);91 break;92 case "uri":93 uri = input.read(URI.class);94 break;95 default:...

Full Screen

Full Screen

Source:Browser.java Github

copy

Full Screen

...42 private static final Logger log = Logger.getLogger(Browser.class.getName());43 private final Capabilities canonicalCapabilities;44 private final boolean supportsCdp;45 private Browser(Capabilities canonicalCapabilities, boolean supportsCdp) {46 this.canonicalCapabilities = ImmutableCapabilities.copyOf(canonicalCapabilities);47 this.supportsCdp = supportsCdp;48 }49 public static Browser detect() {50 String browserName = System.getProperty("selenium.browser");51 if (browserName == null) {52 log.info("No browser detected, returning null");53 return null;54 }55 if ("ff".equals(browserName.toLowerCase()) || "firefox".equals(browserName.toLowerCase())) {56 if (System.getProperty("webdriver.firefox.marionette") == null ||57 Boolean.getBoolean("webdriver.firefox.marionette")) {58 return MARIONETTE;59 } else {60 return FIREFOX;...

Full Screen

Full Screen

Source:CreateSessionRequest.java Github

copy

Full Screen

...33 public CreateSessionRequest(34 Set<Dialect> downstreamDialects,35 Capabilities capabilities,36 Map<String, Object> metadata) {37 this.downstreamDialects = ImmutableSet.copyOf(Objects.requireNonNull(downstreamDialects));38 this.capabilities = ImmutableCapabilities.copyOf(Objects.requireNonNull(capabilities));39 this.metadata = ImmutableMap.copyOf(Objects.requireNonNull(metadata));40 }41 public Set<Dialect> getDownstreamDialects() {42 return downstreamDialects;43 }44 public Capabilities getCapabilities() {45 return capabilities;46 }47 public Map<String, Object> getMetadata() {48 return metadata;49 }50 private static CreateSessionRequest fromJson(JsonInput input) {51 Set<Dialect> downstreamDialects = null;52 Capabilities capabilities = null;53 Map<String, Object> metadata = null;...

Full Screen

Full Screen

Source:NewSessionPipeline.java Github

copy

Full Screen

...66 mutators.add(Objects.requireNonNull(mutator, "Mutator must not be null"));67 return this;68 }69 public NewSessionPipeline create() {70 return new NewSessionPipeline(ImmutableList.copyOf(factories), fallback, mutators);71 }72 }73}...

Full Screen

Full Screen

Source:BaseActiveSession.java Github

copy

Full Screen

...45 }46 this.session = new Session(47 Require.nonNull("Session id", id),48 uri,49 ImmutableCapabilities.copyOf(Require.nonNull("Stereotype", stereotype)),50 ImmutableCapabilities.copyOf(Require.nonNull("Capabilities", capabilities)),51 Require.nonNull("Start time", startTime));52 this.downstream = Require.nonNull("Downstream dialect", downstream);53 this.upstream = Require.nonNull("Upstream dialect", upstream);54 }55 @Override56 public SessionId getId() {57 return session.getId();58 }59 @Override60 public Capabilities getStereotype() {61 return session.getStereotype();62 }63 @Override64 public Capabilities getCapabilities() {...

Full Screen

Full Screen

Source:BrowserType.java Github

copy

Full Screen

...40 private final Class<? extends WebDriver> webDriverClass;41 private final ImmutableCapabilities baseCapabilities;42 BrowserType(Class<? extends WebDriver> webDriverClass, Capabilities baseCapabilities) {43 this.webDriverClass = webDriverClass;44 this.baseCapabilities = ImmutableCapabilities.copyOf(baseCapabilities);45 }46 /**47 * Looks up the named {@link BrowserType}, ignoring case.48 *49 * @param string the desired browser type as {@link String}50 * @return the desired {@link BrowserType} if known51 * @throws IllegalArgumentException if the given string does not equal any {@link BrowserType#name()}52 */53 public static BrowserType forName(String string) {54 return stream(values())55 .filter(browserType -> browserType.name().equalsIgnoreCase(string))56 .findAny()57 .orElseThrow(() -> new UnsupportedBrowserTypeException(string));58 }...

Full Screen

Full Screen

Source:WebDriverFactory.java Github

copy

Full Screen

...28 new ChromeOptions().addArguments("--incognito"));29 }30 public static WebDriver localNode(String address) throws MalformedURLException {31 return new RemoteWebDriver(new URL(address),32 ImmutableCapabilities.copyOf(DesiredCapabilities.chrome()));33 }34 public static WebDriver remote(Settings settings) throws IOException {35 DesiredCapabilities capabilities = new DesiredCapabilities();36 capabilities.setBrowserName("chrome");37 capabilities.setPlatform(Platform.MAC);38 capabilities.setVersion("90.0.4430.93");39 return new RemoteWebDriver(new URL(settings.getSauceLabsUrl()), capabilities);40 }41 public static WebDriver remoteFromFile() throws IOException {42 Settings settings = SettingsFactory.fromJson(Paths.get("src", "test", "resources", "application.json"));43 return remote(settings);44 }45}...

Full Screen

Full Screen

copyOf

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.ImmutableCapabilities;2public class ImmutableCapabilitiesTest {3 public static void main(String[] args) {4 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "chrome");5 ImmutableCapabilities copy = capabilities.copyOf();6 System.out.println("Capabilities: " + capabilities);7 System.out.println("Copy: " + copy);8 }9}10Capabilities: {browserName=chrome}11Copy: {browserName=chrome}12import org.openqa.selenium.ImmutableCapabilities;13import org.openqa.selenium.remote.DesiredCapabilities;14public class DesiredCapabilitiesTest {15 public static void main(String[] args) {16 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "chrome");17 DesiredCapabilities desiredCapabilities = new DesiredCapabilities(capabilities);18 System.out.println(desiredCapabilities);19 }20}21Capabilities {browserName: chrome}22import org.openqa.selenium.ImmutableCapabilities;23import org.openqa.selenium.chrome.ChromeOptions;24public class ChromeOptionsTest {25 public static void main(String[] args) {26 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "chrome");27 ChromeOptions chromeOptions = new ChromeOptions();28 chromeOptions.merge(capabilities);29 System.out.println(chromeOptions);30 }31}32Capabilities {browserName: chrome}33import org.openqa.selenium.ImmutableCapabilities;34import org.openqa.selenium.firefox.FirefoxOptions;35public class FirefoxOptionsTest {36 public static void main(String[] args) {37 ImmutableCapabilities capabilities = new ImmutableCapabilities("browserName", "firefox");

Full Screen

Full Screen

copyOf

Using AI Code Generation

copy

Full Screen

1 ImmutableCapabilities capabilities = new ImmutableCapabilities();2 ImmutableCapabilities copy = capabilities.copyOf(capabilities);3 System.out.println(copy.toString());4 MutableCapabilities mutableCapabilities = new MutableCapabilities();5 MutableCapabilities copyOfMutableCapabilities = mutableCapabilities.copyOf(mutableCapabilities);6 System.out.println(copyOfMutableCapabilities.toString());7 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();8 DesiredCapabilities copyOfDesiredCapabilities = desiredCapabilities.copyOf(desiredCapabilities);9 System.out.println(copyOfDesiredCapabilities.toString());10 RemoteWebDriver remoteWebDriver = new RemoteWebDriver();11 RemoteWebDriver copyOfRemoteWebDriver = remoteWebDriver.copyOf(remoteWebDriver);12 System.out.println(copyOfRemoteWebDriver.toString());13 RemoteWebElement remoteWebElement = new RemoteWebElement();14 RemoteWebElement copyOfRemoteWebElement = remoteWebElement.copyOf(remoteWebElement);15 System.out.println(copyOfRemoteWebElement.toString());16 EventFiringWebDriver eventFiringWebDriver = new EventFiringWebDriver(new ChromeDriver());17 EventFiringWebDriver copyOfEventFiringWebDriver = eventFiringWebDriver.copyOf(eventFiringWebDriver);18 System.out.println(copyOfEventFiringWebDriver.toString());19 EventFiringWebDriver eventFiringWebDriver1 = new EventFiringWebDriver(new ChromeDriver());20 EventFiringWebDriver copyOfEventFiringWebDriver1 = eventFiringWebDriver1.copyOf(eventFiringWebDriver1);21 System.out.println(copyOfEventFiringWebDriver1.toString());22 EventFiringWebDriver eventFiringWebDriver2 = new EventFiringWebDriver(new ChromeDriver());23 EventFiringWebDriver copyOfEventFiringWebDriver2 = eventFiringWebDriver2.copyOf(eventFiringWebDriver2);24 System.out.println(copyOfEventFiringWebDriver2.toString());

Full Screen

Full Screen

copyOf

Using AI Code Generation

copy

Full Screen

1ChromeOptions chromeOptions = new ChromeOptions();2chromeOptions.setCapability("browserName", "chrome");3chromeOptions.setCapability("browserVersion", "latest");4chromeOptions.setCapability("selenoid:options", ImmutableMap.of(5));6chromeOptions.setCapability("enableVNC", true);7chromeOptions.setCapability("enableVideo", false);8chromeOptions.setCapability("screenResolution", "800x600x24");9FirefoxOptions firefoxOptions = new FirefoxOptions();10firefoxOptions.setCapability("browserName", "firefox");11firefoxOptions.setCapability("browserVersion", "latest");12firefoxOptions.setCapability("selenoid:options", ImmutableMap.of(13));14firefoxOptions.setCapability("enableVNC", true);15firefoxOptions.setCapability("enableVideo", false);16firefoxOptions.setCapability("screenResolution", "800x600x24");17EdgeOptions edgeOptions = new EdgeOptions();18edgeOptions.setCapability("browserName", "edge");19edgeOptions.setCapability("browserVersion", "latest");20edgeOptions.setCapability("selenoid:options", ImmutableMap.of(21));22edgeOptions.setCapability("enableVNC", true);23edgeOptions.setCapability("enableVideo", false);24edgeOptions.setCapability("screenResolution", "800x600x24");25OperaOptions operaOptions = new OperaOptions();26operaOptions.setCapability("browserName", "opera");27operaOptions.setCapability("browserVersion", "latest");28operaOptions.setCapability("selenoid:options", ImmutableMap.of(29));

Full Screen

Full Screen

copyOf

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.ImmutableCapabilities;2import org.openqa.selenium.MutableCapabilities;3import org.openqa.selenium.chrome.ChromeOptions;4import org.testng.annotations.Test;5import static org.testng.Assert.assertEquals;6import static org.testng.Assert.assertNotEquals;7import static org.testng.Assert.assertNotSame;8import static org.testng.Assert.assertSame;9import static org.testng.Assert.assertTrue;10public class CopyOfTest {11 public void copyOfTest() {12 MutableCapabilities originalCaps = new ChromeOptions();13 originalCaps.setCapability("testName", "copyOfTest");14 originalCaps.setCapability("platform", "Windows 10");15 originalCaps.setCapability("browserName", "Chrome");16 originalCaps.setCapability("browserVersion", "latest");17 originalCaps.setCapability("sauce:options", new MutableCapabilities());18 System.out.println("originalCaps = " + originalCaps);19 ImmutableCapabilities newCaps = new ImmutableCapabilities(originalCaps);20 newCaps = newCaps.copyOf();21 newCaps.setCapability("newCapability", "newValue");22 System.out.println("newCaps = " + newCaps);23 System.out.println("originalCaps = " + originalCaps);24 assertNotEquals(newCaps, originalCaps);25 assertEquals(newCaps.getCapability("testName"), originalCaps.getCapability("testName"));26 assertEquals(newCaps.getCapability("platform"), originalCaps.getCapability("platform"));27 assertEquals(newCaps.getCapability("browserName"), originalCaps.getCapability("browserName"));28 assertEquals(newCaps.getCapability("browserVersion"), originalCaps.getCapability("browserVersion"));29 assertEquals(newCaps.getCapability("sauce

Full Screen

Full Screen

copyOf

Using AI Code Generation

copy

Full Screen

1MutableCapabilities caps = new MutableCapabilities();2caps.setCapability("browserName", "firefox");3caps.setCapability("platform", "Windows 10");4caps.setCapability("version", "45.0");5ImmutableCapabilities capsCopy = ImmutableCapabilities.copyOf(caps);6System.out.println(capsCopy);7caps.setCapability("screenResolution", "1280x1024");8System.out.println(caps);9System.out.println(capsCopy);10System.out.println(capsCopy);11System.out.println(caps);12System.out.println(capsCopy);13caps.setCapability("screenResolution", "1280x1024");14System.out.println(caps);15System.out.println(capsCopy);16System.out.println(capsCopy);17System.out.println(caps);18System.out.println(capsCopy);19caps.setCapability("screenResolution", "1280x1024");20System.out.println(caps);21System.out.println(capsCopy);22System.out.println(capsCopy);23System.out.println(caps);24System.out.println(capsCopy);25caps.setCapability("screenResolution", "1280x1024");

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 method in ImmutableCapabilities

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful