How to use getCapability method of org.openqa.selenium.Interface Capabilities class

Best Selenium code snippet using org.openqa.selenium.Interface Capabilities.getCapability

Source:FirefoxDriver.java Github

copy

Full Screen

...96 Capabilities requiredCapabilities) {97 98 FirefoxProfile profile = null;99 Object raw = null;100 if (desiredCapabilities != null && desiredCapabilities.getCapability(PROFILE) != null) {101 raw = desiredCapabilities.getCapability(PROFILE);102 }103 if (requiredCapabilities != null && requiredCapabilities.getCapability(PROFILE) != null) {104 raw = requiredCapabilities.getCapability(PROFILE);105 }106 if (raw != null) {107 if (raw instanceof FirefoxProfile) {108 profile = (FirefoxProfile) raw;109 } else if (raw instanceof String) {110 try {111 profile = FirefoxProfile.fromJson((String) raw);112 } catch (IOException e) {113 throw new WebDriverException(e);114 }115 }116 }117 profile = getProfile(profile);118 119 populateProfile(profile, desiredCapabilities);120 populateProfile(profile, requiredCapabilities);121 122 return profile;123 }124 static void populateProfile(FirefoxProfile profile, Capabilities capabilities) {125 if (capabilities == null) {126 return;127 }128 if (capabilities.getCapability(SUPPORTS_WEB_STORAGE) != null) {129 Boolean supportsWebStorage = (Boolean) capabilities.getCapability(SUPPORTS_WEB_STORAGE);130 profile.setPreference("dom.storage.enabled", supportsWebStorage.booleanValue());131 }132 if (capabilities.getCapability(ACCEPT_SSL_CERTS) != null) {133 Boolean acceptCerts = (Boolean) capabilities.getCapability(ACCEPT_SSL_CERTS);134 profile.setAcceptUntrustedCertificates(acceptCerts);135 }136 if (capabilities.getCapability(LOGGING_PREFS) != null) {137 LoggingPreferences logsPrefs = 138 (LoggingPreferences) capabilities.getCapability(LOGGING_PREFS);139 for (String logtype : logsPrefs.getEnabledLogTypes()) {140 profile.setPreference("webdriver.log." + logtype, 141 logsPrefs.getLevel(logtype).intValue());142 }143 }144 if (capabilities.getCapability(HAS_NATIVE_EVENTS) != null) {145 Boolean nativeEventsEnabled = (Boolean) capabilities.getCapability(HAS_NATIVE_EVENTS);146 profile.setEnableNativeEvents(nativeEventsEnabled);147 }148 }149 private static FirefoxBinary getBinary(Capabilities capabilities) {150 if (capabilities != null && capabilities.getCapability(BINARY) != null) {151 Object raw = capabilities.getCapability(BINARY);152 if (raw instanceof FirefoxBinary) {153 return (FirefoxBinary) raw;154 }155 File file = new File((String) raw);156 return new FirefoxBinary(file);157 }158 return new FirefoxBinary();159 }160 public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile) {161 this(binary, profile, DesiredCapabilities.firefox());162 }163 public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities capabilities) {164 this(binary, profile, capabilities, null);165 }...

Full Screen

Full Screen

Source:AppiumElementLocator.java Github

copy

Full Screen

...72 Capabilities capabilities = ((HasCapabilities) unpackWebDriverFromSearchContext()).73 getCapabilities();74 75 String platform = String76 .valueOf(capabilities.getCapability(77 MobileCapabilityType.PLATFORM_NAME));78 String automation = String79 .valueOf(capabilities.getCapability(80 MobileCapabilityType.AUTOMATION_NAME));81 82 String browser = (String) capabilities.getCapability(CapabilityType.BROWSER_NAME); 83 String app = (String) capabilities.getCapability(MobileCapabilityType.APP);84 85 boolean isBrowser = ((app == null || "".equals(app.trim())) && 86 (browser != null && !"".equals(browser.trim())));87 88 AppiumAnnotations annotations = new AppiumAnnotations(field, 89 platform, automation, isBrowser);90 this.timeOutContainer = timeOutContainer;91 shouldCache = annotations.isLookupCached();92 by = annotations.buildBy();93 }94 95 private WebDriver unpackWebDriverFromSearchContext(){96 WebDriver driver = null;97 if (searchContext instanceof WebDriver){ ...

Full Screen

Full Screen

Source:Capabilities.java Github

copy

Full Screen

...22 * Describes a series of key/value pairs that encapsulate aspects of a browser.23 */24public interface Capabilities {25 default String getBrowserName() {26 return String.valueOf(Optional.ofNullable(getCapability("browserName")).orElse(""));27 }28 default Platform getPlatform() {29 Object rawPlatform = getCapability("platformName");30 if (rawPlatform == null) {31 rawPlatform = getCapability("platform");32 }33 if (rawPlatform == null) {34 return null;35 }36 if (rawPlatform instanceof String) {37 return Platform.fromString((String) rawPlatform);38 } else if (rawPlatform instanceof Platform) {39 return (Platform) rawPlatform;40 }41 throw new IllegalStateException("Platform was neither a string nor a Platform: " + rawPlatform);42 }43 default String getVersion() {44 return String.valueOf(Optional.ofNullable(getCapability("browserVersion")).orElse(45 Optional.ofNullable(getCapability("version")).orElse("")));46 }47 /**48 * @deprecated Use is(SUPPORTS_JAVASCRIPT) instead.49 * @see #is(String)50 * @see org.openqa.selenium.remote.CapabilityType#SUPPORTS_JAVASCRIPT51 */52 @Deprecated53 default boolean isJavascriptEnabled() {54 return is("javascriptEnabled");55 }56 /**57 * @return The capabilities as a Map.58 */59 Map<String, ?> asMap();60 /**61 * @see org.openqa.selenium.remote.CapabilityType62 * @param capabilityName The capability to return.63 * @return The value, or null if not set.64 */65 Object getCapability(String capabilityName);66 /**67 * @see org.openqa.selenium.remote.CapabilityType68 * @param capabilityName The capability to check.69 * @return Whether or not the value is not null and not false.70 */71 default boolean is(String capabilityName) {72 Object cap = getCapability(capabilityName);73 if (cap == null) {74 // If it's not set explicitly, javascriptEnabled is true.75 return "javascriptEnabled".equals(capabilityName);76 }77 return cap instanceof Boolean ? (Boolean) cap : Boolean.parseBoolean(String.valueOf(cap));78 }79 /**80 * Merge two {@link Capabilities} together and return the union of the two as a new81 * {@link Capabilities} instance. Capabilities from {@code other} will override those in82 * {@code this}.83 */84 default Capabilities merge(Capabilities other) {85 HashMap<String, Object> map = new HashMap<>();86 map.putAll(asMap());...

Full Screen

Full Screen

getCapability

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Capabilities;2import org.openqa.selenium.remote.RemoteWebDriver;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6public class GetBrowserNameVersion {7 public static void main(String[] args) {8 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();11 String browserName = caps.getBrowserName();12 String browserVersion = caps.getVersion();13 System.out.println("Browser Name: " + browserName);14 System.out.println("Browser Version: " + browserVersion);15 driver.quit();16 }17}18Selenium WebDriver getBrowserName() method19public String getBrowserName();20import org.openqa.selenium.Capabilities;21import org.openqa.selenium.remote.RemoteWebDriver;22import org.openqa.selenium.remote.DesiredCapabilities;23import org.openqa.selenium.WebDriver;24import org.openqa.selenium.chrome.ChromeDriver;25public class GetBrowserName {26 public static void main(String[] args) {27 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");28 WebDriver driver = new ChromeDriver();29 Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();30 String browserName = caps.getBrowserName();31 System.out.println("Browser Name: " + browserName);32 driver.quit();33 }34}35Selenium WebDriver getVersion() method36public String getVersion();37import org.openqa.selenium.Capabilities;38import org.openqa.selenium.remote.RemoteWebDriver

Full Screen

Full Screen

getCapability

Using AI Code Generation

copy

Full Screen

1Capabilities caps = ((RemoteWebDriver)driver).getCapabilities();2String browserName = caps.getBrowserName();3String browserVersion = caps.getVersion();4String platform = caps.getPlatform().toString();5System.out.println("Browser Name: "+browserName);6System.out.println("Browser Version: "+browserVersion);7System.out.println("Platform: "+platform);

Full Screen

Full Screen

getCapability

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.*;2import org.openqa.selenium.firefox.*;3import org.openqa.selenium.remote.*;4import org.openqa.selenium.remote.RemoteWebDriver;5public class CapabilitiesDemo {6 public static void main(String[] args) {7 WebDriver driver = new FirefoxDriver();8 Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();9 System.out.println(cap.getBrowserName());10 System.out.println(cap.getVersion());11 System.out.println(cap.getPlatform());12 driver.quit();13 }14}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful