List of usage examples for org.openqa.selenium ImmutableCapabilities ImmutableCapabilities
public ImmutableCapabilities(Map<?, ?> capabilities)
From source file:org.openqa.grid.selenium.node.ChromeMutator.java
License:Apache License
@Override public ImmutableCapabilities apply(ImmutableCapabilities capabilities) { if (config == null || !"chrome".equals(capabilities.getBrowserName())) { return capabilities; }//from w w w. j a v a2 s. c o m if (!Objects.equals(config.getCapability(CONFIG_UUID_CAPABILITY), capabilities.getCapability(CONFIG_UUID_CAPABILITY))) { return capabilities; } Map<String, Object> toReturn = new HashMap<>(); toReturn.putAll(capabilities.asMap()); Map<String, Object> options = new HashMap<>(); if (capabilities.getCapability(CAPABILITY) instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> asMap = (Map<String, Object>) capabilities.getCapability(CAPABILITY); options.putAll(asMap); } if (!(options.get("binary") instanceof String)) { options.put("binary", config.getCapability("chrome_binary")); } toReturn.put(CAPABILITY, options); return new ImmutableCapabilities(toReturn); }
From source file:org.openqa.grid.selenium.node.ChromeMutatorTest.java
License:Apache License
@Test public void shouldInjectBinaryIfNotSpecified() { ImmutableCapabilities caps = new ImmutableCapabilities(new ChromeOptions()); ImmutableCapabilities seen = new ChromeMutator(defaultConfig).apply(caps); @SuppressWarnings("unchecked") Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY); assertEquals(options.get("binary"), defaultConfig.getCapability("chrome_binary")); }
From source file:org.openqa.grid.selenium.node.ChromeMutatorTest.java
License:Apache License
@Test public void shouldNotInjectBinaryIfSpecified() { ImmutableCapabilities caps = new ImmutableCapabilities(new ChromeOptions().setBinary("cheese")); ImmutableCapabilities seen = new ChromeMutator(defaultConfig).apply(caps); @SuppressWarnings("unchecked") Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY); assertEquals(options.get("binary"), "cheese"); }
From source file:org.openqa.grid.selenium.node.FirefoxMutator.java
License:Apache License
@Override public ImmutableCapabilities apply(ImmutableCapabilities capabilities) { if (config == null || !"firefox".equals(capabilities.getBrowserName())) { return capabilities; }/*from w w w.j av a 2 s . co m*/ if (!Objects.equals(config.getCapability(CONFIG_UUID_CAPABILITY), capabilities.getCapability(CONFIG_UUID_CAPABILITY))) { return capabilities; } Map<String, Object> options = new HashMap<>(); if (capabilities.getCapability(FIREFOX_OPTIONS) instanceof Map) { //noinspection unchecked Map<String, Object> originalOptions = (Map<String, Object>) capabilities.getCapability(FIREFOX_OPTIONS); options.putAll(originalOptions); } Map<String, Object> toReturn = new HashMap<>(); toReturn.putAll(capabilities.asMap()); if (config.getCapability(BINARY) != null) { if (!(capabilities.getCapability(BINARY) instanceof String)) { toReturn.put(BINARY, config.getCapability(BINARY)); } if (!(options.get("binary") instanceof String)) { options.put("binary", config.getCapability(BINARY)); } } if (config.getCapability(MARIONETTE) != null) { toReturn.put(MARIONETTE, config.getCapability(MARIONETTE)); } if (!options.isEmpty()) { toReturn.put(FIREFOX_OPTIONS, options); } return new ImmutableCapabilities(toReturn); }