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

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

Source:FirefoxOptionsTest.java Github

copy

Full Screen

...62 MARIONETTE, false,63 PAGE_LOAD_STRATEGY, PageLoadStrategy.EAGER,64 ACCEPT_INSECURE_CERTS, true));65 assertTrue(options.isLegacy());66 assertEquals(options.getCapability(PAGE_LOAD_STRATEGY), PageLoadStrategy.EAGER);67 assertEquals(options.getCapability(ACCEPT_INSECURE_CERTS), true);68 }69 @Test70 public void canInitFirefoxOptionsWithCapabilitiesThatContainFirefoxOptions() {71 FirefoxOptions options = new FirefoxOptions().setLegacy(true).merge(72 new ImmutableCapabilities(PAGE_LOAD_STRATEGY, PageLoadStrategy.EAGER));73 Capabilities caps = new ImmutableCapabilities(FIREFOX_OPTIONS, options);74 FirefoxOptions options2 = new FirefoxOptions(caps);75 assertTrue(options2.isLegacy());76 assertEquals(options2.getCapability(PAGE_LOAD_STRATEGY), PageLoadStrategy.EAGER);77 }78 @Test79 public void canInitFirefoxOptionsWithCapabilitiesThatContainFirefoxOptionsAsMap() {80 FirefoxProfile profile = new FirefoxProfile();81 Capabilities caps = new ImmutableCapabilities(82 FIREFOX_OPTIONS, ImmutableMap.of("profile", profile));83 FirefoxOptions options = new FirefoxOptions(caps);84 assertSame(options.getProfile(), profile);85 }86 @Test87 public void binaryPathNeedNotExist() {88 try {89 new FirefoxOptions().setBinary("does/not/exist");90 } catch (Exception e) {91 fail("Did not expect to see any exceptions thrown: " + e);92 }93 }94 @Test95 public void shouldKeepRelativePathToBinaryAsIs() {96 FirefoxOptions options = new FirefoxOptions().setBinary("some/path");97 assertEquals("some/path", options.getCapability(FirefoxDriver.BINARY));98 }99 @Test100 public void shouldConvertPathToBinaryToUseForwardSlashes() {101 FirefoxOptions options = new FirefoxOptions().setBinary("some\\path");102 assertEquals("some/path", options.getCapability(FirefoxDriver.BINARY));103 }104 @Test105 public void shouldKeepWindowsDriveLetterInPathToBinary() {106 FirefoxOptions options = new FirefoxOptions().setBinary("F:\\some\\path");107 assertEquals("F:/some/path", options.getCapability(FirefoxDriver.BINARY));108 }109 @Test110 public void canUseForwardSlashesInWindowsPaths() {111 FirefoxOptions options = new FirefoxOptions().setBinary("F:\\some\\path");112 assertEquals("F:/some/path", options.getCapability(FirefoxDriver.BINARY));113 }114 @Test115 public void shouldKeepWindowsNetworkFileSystemRootInPathToBinary() {116 FirefoxOptions options = new FirefoxOptions().setBinary("\\\\server\\share\\some\\path");117 assertEquals("//server/share/some/path", options.getCapability(FirefoxDriver.BINARY));118 }119 @Test120 public void shouldKeepAFirefoxBinaryAsABinaryIfSetAsOne() throws IOException {121 File fakeExecutable = Files.createTempFile("firefox", ".exe").toFile();122 fakeExecutable.deleteOnExit();123 FirefoxBinary binary = new FirefoxBinary(fakeExecutable);124 FirefoxOptions options = new FirefoxOptions().setBinary(binary);125 assertEquals(binary, options.getCapability(FirefoxDriver.BINARY));126 assertEquals(binary, options.getBinary());127 }128 @Test129 public void stringBasedBinaryRemainsAbsoluteIfSetAsAbsolute() throws IOException {130 Map<String, ?> json = new FirefoxOptions().setBinary("/i/like/cheese").asMap();131 assertEquals("/i/like/cheese", ((Map<?, ?>) json.get(FIREFOX_OPTIONS)).get("binary"));132 }133 @Test134 public void pathBasedBinaryRemainsAbsoluteIfSetAsAbsolute() throws IOException {135 Map<String, ?> json = new FirefoxOptions().setBinary(Paths.get("/i/like/cheese")).asMap();136 assertEquals("/i/like/cheese", ((Map<?, ?>) json.get(FIREFOX_OPTIONS)).get("binary"));137 }138 @Test139 public void shouldPickUpBinaryFromSystemPropertyIfSet() throws IOException {...

Full Screen

Full Screen

Source:FirefoxMutatorTest.java Github

copy

Full Screen

...52 public void shouldInjectBinaryIfNotSpecified() {53 ImmutableCapabilities caps = new ImmutableCapabilities("browserName", "firefox");54 Capabilities seen = new FirefoxMutator(defaultConfig).apply(caps);55 assertEquals(56 seen.getCapability("firefox_binary"),57 defaultConfig.getCapability("firefox_binary"));58 @SuppressWarnings("unchecked")59 Map<String, Object> options = (Map<String, Object>) seen.getCapability(FIREFOX_OPTIONS);60 assertEquals(61 options.get("binary"),62 defaultConfig.getCapability("firefox_binary"));63 }64 @Test65 public void shouldInjectBinaryIfLegacyOptionUnsetButGeckoDriverOptionSet() {66 ImmutableCapabilities caps = new ImmutableCapabilities(67 "browserName", "firefox",68 BINARY, "cheese",69 FIREFOX_OPTIONS, ImmutableMap.of());70 Capabilities seen = new FirefoxMutator(defaultConfig).apply(caps);71 assertEquals("cheese", seen.getCapability(BINARY));72 @SuppressWarnings("unchecked")73 Map<String, Object> options = (Map<String, Object>) seen.getCapability(FIREFOX_OPTIONS);74 assertEquals(defaultConfig.getCapability(BINARY), options.get("binary"));75 }76 @Test77 public void shouldInjectBinaryIfGeckoDriverOptionUnsetButLegacyOptionSet() {78 ImmutableCapabilities caps = new ImmutableCapabilities(79 "browserName", "firefox",80 FIREFOX_OPTIONS, ImmutableMap.of("binary", "cheese"));81 Capabilities seen = new FirefoxMutator(defaultConfig).apply(caps);82 assertEquals(defaultConfig.getCapability(BINARY), seen.getCapability(BINARY));83 @SuppressWarnings("unchecked")84 Map<String, Object> options = (Map<String, Object>) seen.getCapability(FIREFOX_OPTIONS);85 assertEquals("cheese", options.get("binary"));86 }87 @Test88 public void shouldInjectMarionetteValueNoMatterWhat() {89 ImmutableCapabilities caps = new ImmutableCapabilities(90 "browserName", "firefox",91 MARIONETTE, "cheese");92 Capabilities seen = new FirefoxMutator(defaultConfig).apply(caps);93 assertEquals(defaultConfig.getCapability(MARIONETTE), seen.getCapability(MARIONETTE));94 }95 @Test96 public void shouldInjectIfConfigUuidMatches() {97 ImmutableCapabilities defaultConfigWithUuid = new ImmutableCapabilities(98 "browserName", "firefox",99 BINARY, "binary",100 "firefox_profile", "profile",101 MARIONETTE, true,102 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "123");103 ImmutableCapabilities caps = new ImmutableCapabilities(104 "browserName", "firefox",105 MARIONETTE, "cheese",106 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "123");107 Capabilities seen = new FirefoxMutator(defaultConfigWithUuid).apply(caps);108 assertEquals(true, seen.getCapability(MARIONETTE));109 }110 @Test111 public void shouldNotInjectIfConfigUuidDoesNotMatch() {112 ImmutableCapabilities defaultConfigWithUuid = new ImmutableCapabilities(113 "browserName", "firefox",114 BINARY, "binary",115 "firefox_profile", "profile",116 MARIONETTE, true,117 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "uuid");118 ImmutableCapabilities caps = new ImmutableCapabilities(119 "browserName", "firefox",120 MARIONETTE, "cheese",121 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "123");122 Capabilities seen = new FirefoxMutator(defaultConfigWithUuid).apply(caps);123 assertEquals("cheese", seen.getCapability(MARIONETTE));124 }125 @Test126 public void shouldNotInjectIfUuidIsPresentInConfigOnly() {127 ImmutableCapabilities defaultConfigWithUuid = new ImmutableCapabilities(128 "browserName", "firefox",129 BINARY, "binary",130 "firefox_profile", "profile",131 MARIONETTE, true,132 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "uuid");133 ImmutableCapabilities caps = new ImmutableCapabilities(134 "browserName", "firefox",135 MARIONETTE, "cheese");136 Capabilities seen = new FirefoxMutator(defaultConfigWithUuid).apply(caps);137 assertEquals("cheese", seen.getCapability(MARIONETTE));138 }139 @Test140 public void shouldNotInjectIfUuidIsPresentInPayloadOnly() {141 ImmutableCapabilities caps = new ImmutableCapabilities(142 "browserName", "firefox",143 MARIONETTE, "cheese",144 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "123");145 Capabilities seen = new FirefoxMutator(defaultConfig).apply(caps);146 assertEquals("cheese", seen.getCapability(MARIONETTE));147 }148}...

Full Screen

Full Screen

Source:ChromeMutatorTest.java Github

copy

Full Screen

...50 public void shouldInjectBinaryIfNotSpecified() {51 ImmutableCapabilities caps = new ImmutableCapabilities(new ChromeOptions());52 Capabilities seen = new ChromeMutator(defaultConfig).apply(caps);53 @SuppressWarnings("unchecked")54 Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY);55 assertEquals(56 options.get("binary"),57 defaultConfig.getCapability("chrome_binary"));58 }59 @Test60 public void shouldNotInjectNullBinary() {61 ImmutableCapabilities caps = new ImmutableCapabilities(new ChromeOptions());62 Capabilities seen = new ChromeMutator(63 new ImmutableCapabilities("browserName", "chrome")).apply(caps);64 @SuppressWarnings("unchecked")65 Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY);66 assertFalse(options.containsKey("binary"));67 }68 @Test69 public void shouldNotInjectBinaryIfSpecified() {70 ImmutableCapabilities caps = new ImmutableCapabilities(new ChromeOptions().setBinary("cheese"));71 Capabilities seen = new ChromeMutator(defaultConfig).apply(caps);72 @SuppressWarnings("unchecked")73 Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY);74 assertEquals(options.get("binary"), "cheese");75 }76 @Test77 public void shouldInjectIfConfigUuidMatches() {78 ImmutableCapabilities config = new ImmutableCapabilities(79 "browserName", "chrome",80 "chrome_binary", "binary",81 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "123");82 ImmutableCapabilities caps = new ImmutableCapabilities(83 "browserName", "chrome",84 CAPABILITY, ImmutableMap.of(),85 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "123");86 Capabilities seen = new ChromeMutator(config).apply(caps);87 Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY);88 assertEquals(89 options.get("binary"),90 config.getCapability("chrome_binary"));91 }92 @Test93 public void shouldNotInjectIfConfigUuidDoesNotMatch() {94 ImmutableCapabilities config = new ImmutableCapabilities(95 "browserName", "chrome",96 "chrome_binary", "binary",97 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "uuid");98 ImmutableCapabilities caps = new ImmutableCapabilities(99 "browserName", "chrome",100 CAPABILITY, ImmutableMap.of("binary", "cheese"),101 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "123");102 Capabilities seen = new ChromeMutator(config).apply(caps);103 Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY);104 assertEquals(options.get("binary"), "cheese");105 }106 @Test107 public void shouldNotInjectIfUuidIsPresentInConfigOnly() {108 ImmutableCapabilities config = new ImmutableCapabilities(109 "browserName", "chrome",110 "chrome_binary", "binary",111 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "uuid");112 ImmutableCapabilities caps = new ImmutableCapabilities(113 "browserName", "chrome",114 CAPABILITY, ImmutableMap.of("binary", "cheese"));115 Capabilities seen = new ChromeMutator(config).apply(caps);116 Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY);117 assertEquals(options.get("binary"), "cheese");118 }119 @Test120 public void shouldNotInjectIfUuidIsPresentInPayloadOnly() {121 ImmutableCapabilities config = new ImmutableCapabilities(122 "browserName", "chrome",123 "chrome_binary", "binary");124 ImmutableCapabilities caps = new ImmutableCapabilities(125 "browserName", "chrome",126 CAPABILITY, ImmutableMap.of("binary", "cheese"),127 GridNodeConfiguration.CONFIG_UUID_CAPABILITY, "123");128 Capabilities seen = new ChromeMutator(config).apply(caps);129 Map<String, Object> options = (Map<String, Object>) seen.getCapability(CAPABILITY);130 assertEquals(options.get("binary"), "cheese");131 }132}...

Full Screen

Full Screen

Source:InternetExplorerDriver.java Github

copy

Full Screen

...115 InternetExplorerDriverService.Builder builder = new InternetExplorerDriverService.Builder();116 builder.usingPort(port);117 118 if (caps != null) {119 if (caps.getCapability("logFile") != null) {120 String value = (String)caps.getCapability("logFile");121 if (value != null) {122 builder.withLogFile(new File(value));123 }124 }125 126 if (caps.getCapability("logLevel") != null) {127 String value = (String)caps.getCapability("logLevel");128 if (value != null) {129 builder.withLogLevel(InternetExplorerDriverLogLevel.valueOf(value));130 }131 }132 133 if (caps.getCapability("host") != null) {134 String value = (String)caps.getCapability("host");135 if (value != null) {136 builder.withHost(value);137 }138 }139 140 if (caps.getCapability("extractPath") != null) {141 String value = (String)caps.getCapability("extractPath");142 if (value != null) {143 builder.withExtractPath(new File(value));144 }145 }146 147 if (caps.getCapability("silent") != null) {148 Boolean value = (Boolean)caps.getCapability("silent");149 if (value != null) {150 builder.withSilent(value);151 }152 }153 }154 155 return (InternetExplorerDriverService)builder.build();156 }157}...

Full Screen

Full Screen

Source:EdgeDriverInfo.java Github

copy

Full Screen

...4950 @Override51 public boolean isSupporting(Capabilities capabilities) {52 return (BrowserType.EDGE.equals(capabilities.getBrowserName())53 || capabilities.getCapability("ms:edgeOptions") != null54 || capabilities.getCapability("edgeOptions") != null)55 &&56 (capabilities.getCapability(EdgeOptions.USE_CHROMIUM) == null57 || Objects.equals(capabilities.getCapability(EdgeOptions.USE_CHROMIUM), true));58 }5960 @Override61 public boolean isAvailable() {62 try {63 EdgeDriverService.createDefaultService();64 return true;65 } catch (IllegalStateException | WebDriverException e) {66 return false;67 }68 }6970 @Override71 public int getMaximumSimultaneousSessions() { ...

Full Screen

Full Screen

Source:FirefoxMutator.java Github

copy

Full Screen

...34 public ImmutableCapabilities apply(ImmutableCapabilities capabilities) {35 if (config == null || !"firefox".equals(capabilities.getBrowserName())) {36 return capabilities;37 }38 if (!Objects.equals(config.getCapability(CONFIG_UUID_CAPABILITY),39 capabilities.getCapability(CONFIG_UUID_CAPABILITY))) {40 return capabilities;41 }42 Map<String, Object> options = new HashMap<>();43 if (capabilities.getCapability(FIREFOX_OPTIONS) instanceof Map) {44 //noinspection unchecked45 Map<String, Object> originalOptions =46 (Map<String, Object>) capabilities.getCapability(FIREFOX_OPTIONS);47 options.putAll(originalOptions);48 }49 Map<String, Object> toReturn = new HashMap<>();50 toReturn.putAll(capabilities.asMap());51 if (config.getCapability(BINARY) != null) {52 if (!(capabilities.getCapability(BINARY) instanceof String)) {53 toReturn.put(BINARY, config.getCapability(BINARY));54 }55 if (!(options.get("binary") instanceof String)) {56 options.put("binary", config.getCapability(BINARY));57 }58 }59 if (config.getCapability(MARIONETTE) != null) {60 toReturn.put(MARIONETTE, config.getCapability(MARIONETTE));61 }62 if (!options.isEmpty()) {63 toReturn.put(FIREFOX_OPTIONS, options);64 }65 return new ImmutableCapabilities(toReturn);66 }67}...

Full Screen

Full Screen

Source:ChromeDriverInfo.java Github

copy

Full Screen

...37 }38 @Override39 public boolean isSupporting(Capabilities capabilities) {40 return BrowserType.CHROME.equals(capabilities.getBrowserName()) ||41 capabilities.getCapability("chromeOptions") != null ||42 capabilities.getCapability("goog:chromeOptions") != null;43 }44 @Override45 public boolean isAvailable() {46 try {47 ChromeDriverService.createDefaultService();48 return true;49 } catch (IllegalStateException | WebDriverException e) {50 return false;51 }52 }53 @Override54 public int getMaximumSimultaneousSessions() {55 return Runtime.getRuntime().availableProcessors() + 1;56 }...

Full Screen

Full Screen

getCapability

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.ImmutableCapabilities;2import org.openqa.selenium.MutableCapabilities;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.chrome.ChromeOptions;6import org.openqa.selenium.remote.BrowserType;7import org.openqa.selenium.remote.CapabilityType;8import org.openqa.selenium.remote.DesiredCapabilities;9public class Selenium4GetCapabilityExample {10 public static void main(String[] args) {11 ChromeOptions options = new ChromeOptions();12 options.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);13 options.setCapability(CapabilityType.PLATFORM_NAME, "Windows 10");14 options.setCapability(CapabilityType.VERSION, "81.0.4044.138");15 options.setCapability("screenResolution", "1280x1024");16 DesiredCapabilities capabilities = new DesiredCapabilities();17 capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);18 capabilities.setCapability(CapabilityType.PLATFORM_NAME, "Windows 10");19 capabilities.setCapability(CapabilityType.VERSION, "81.0.4044.138");20 capabilities.setCapability("screenResolution", "1280x1024");21 MutableCapabilities mutableCapabilities = new MutableCapabilities();22 mutableCapabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);23 mutableCapabilities.setCapability(CapabilityType.PLATFORM_NAME, "Windows 10");24 mutableCapabilities.setCapability(CapabilityType.VERSION, "81.0.4044.138");25 mutableCapabilities.setCapability("screenResolution", "1280x1024");26 ImmutableCapabilities immutableCapabilities = new ImmutableCapabilities();27 immutableCapabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);28 immutableCapabilities.setCapability(CapabilityType.PLATFORM_NAME, "Windows 10");29 immutableCapabilities.setCapability(CapabilityType.VERSION, "81.0.4044.138");30 immutableCapabilities.setCapability("screenResolution", "1280x1024");31 WebDriver driver = new ChromeDriver(immutableCapabilities);32 System.out.println("ImmutableCapabilities: " + immutableCapabilities.getCapabilities());33 System.out.println("MutableCapabilities: " + mutableCapabilities.getCapabilities());34 System.out.println("DesiredCapabilities: " + capabilities.getCapabilities

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