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

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

Source:Visit.java Github

copy

Full Screen

...230 public String getBrowserName() {231 return browserName;232 }233 @JsonIgnore234 public String getPlatformName() {235 return platformName;236 }237 @JsonIgnore238 public String getBrowserVersion() {239 return browserVersion;240 }241 @JsonIgnore242 public List<Map<String, byte[]>> publish() {243 return this.artifacts;244 }245 @JsonIgnore246 public Visit publish(ZipOutputStream zipOutputStream, FileTime now) throws IOException {247 for (Map<String, byte[]> artifacts : this.artifacts) {248 for (Map.Entry<String, byte[]> artifact : artifacts.entrySet()) {...

Full Screen

Full Screen

Source:Capabilities.java Github

copy

Full Screen

...28 default String getBrowserName() {29 return String.valueOf(Optional.ofNullable(getCapability("browserName")).orElse(""));30 }31 /**32 * @deprecated Use {@link #getPlatformName()}33 */34 @Deprecated35 default Platform getPlatform() {36 return getPlatformName();37 }38 default Platform getPlatformName() {39 return Stream.of("platform", "platformName")40 .map(this::getCapability)41 .filter(Objects::nonNull)42 .map(cap -> {43 if (cap instanceof Platform) {44 return (Platform) cap;45 }46 try {47 return Platform.fromString((String.valueOf(cap)));48 } catch (WebDriverException e) {49 return null;50 }51 })52 .filter(Objects::nonNull)...

Full Screen

Full Screen

Source:TestRunnerInfo.java Github

copy

Full Screen

...17 return runnerInfo;18 }19 public DeviceInterface runnerInfoStatus() {20 try {21 AppiumDriverManager.getDriver().getPlatformName();22 viewFactory = new ViewFactory(AppiumDriverManager.getDriver());23 runnerInfo = viewFactory.getMobilePlatform(AppiumDriverManager.getDriver().24 getCapabilities().getCapability("platformName").toString(),25 AppiumDriverManager.getDriver());26 driver.set(AppiumDriverManager.getDriver());27 return runnerInfo;28 } catch (Exception e) {29 driver.set(DriverManager.getDriver());30 return new WebFlow(DriverManager.getDriver());31 }32 }33 public String getPlatform(WebDriver driver) {34 if (propertyReader.readProperty("PLATFORM").equals("Android") || propertyReader.readProperty("PLATFORM").equals("IOS") || propertyReader.readProperty("PLATFORM").equals("Mobile")) {35 Capabilities cap = ((RemoteWebDriver) driver).getCapabilities();...

Full Screen

Full Screen

Source:IDriverSettings.java Github

copy

Full Screen

...3import aquality.selenium.utils.JsonFile;4import org.openqa.selenium.Capabilities;5public interface IDriverSettings {6 Capabilities getCapabilities();7 PlatformName getPlatformName();8 boolean hasApplicationPath();9 String getApplicationPath();10 JsonFile getSettingsFile();11}...

Full Screen

Full Screen

getPlatformName

Using AI Code Generation

copy

Full Screen

1String platformName = ((RemoteWebDriver)driver).getCapabilities().getPlatformName();2System.out.println("Platform Name: " + platformName);3String browserName = ((RemoteWebDriver)driver).getCapabilities().getBrowserName();4System.out.println("Browser Name: " + browserName);5String browserVersion = ((RemoteWebDriver)driver).getCapabilities().getVersion();6System.out.println("Browser Version: " + browserVersion);7public DesiredCapabilities(String browserName)8package com.selenium4beginners.java.selenium;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.chrome.ChromeDriver;11import org.openqa.selenium.remote.DesiredCapabilities;12public class GetBrowserVersionUsingDesiredCapabilities {13 public static void main(String[] args) {14 DesiredCapabilities cap = new DesiredCapabilities();15 cap.setBrowserName("chrome");16 String browserName = cap.getBrowserName();17 System.out.println("Browser Name: " + browserName);18 String browserVersion = cap.getVersion();19 System.out.println("Browser Version: " + browserVersion);20 }21}22In the above code, we are creating an object of the DesiredCapabilities class and setting the browser name using the setBrowserName() method. Then we are using the getBrowserName() and getVersion() methods of the DesiredCapabilities class to get the browser name and browser version respectively

Full Screen

Full Screen

getPlatformName

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Capabilities;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.RemoteWebDriver;4import org.openqa.selenium.remote.CapabilityType;5import java.net.URL;6import java.net.MalformedURLException;7import java.util.concurrent.TimeUnit;8import org.openqa.selenium.By;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.chrome.ChromeDriver;11import org.openqa.selenium.chrome.ChromeOptions;12public class RemoteWebDriverDemo {13 public static void main(String[] args) {14 String projectPath = System.getProperty("user.dir");15 System.setProperty("webdriver.chrome.driver", projectPath + "/drivers/chromedriver/chromedriver.exe");16 ChromeOptions options = new ChromeOptions();17 options.setCapability(CapabilityType.BROWSER_NAME, "chrome");18 options.setCapability(CapabilityType.PLATFORM_NAME, "Windows 10");19 options.setCapability(CapabilityType.VERSION, "88.0.4324.96");20 ChromeDriver driver = new ChromeDriver(options);21 driver.findElement(By.name("q")).sendKeys("Selenium");22 driver.findElement(By.name("btnK")).click();23 driver.quit();24 }25}26import org.openqa.selenium.Capabilities;27import org.openqa.selenium.remote.DesiredCapabilities;28import org.openqa.selenium.remote.RemoteWebDriver;29import org.openqa.selenium.remote.CapabilityType;30import java.net.URL;31import java.net.MalformedURLException;32import java.util.concurrent.TimeUnit;33import org.openqa.selenium.By;34import org.openqa.selenium.WebElement;35import org.openqa.selenium.chrome.ChromeDriver;36import org.openqa.selenium.chrome.ChromeOptions;37public class RemoteWebDriverDemo {38 public static void main(String[] args) {39 String projectPath = System.getProperty("user.dir");40 System.setProperty("webdriver.chrome.driver", projectPath + "/drivers/chromedriver/chromedriver.exe");41 ChromeOptions options = new ChromeOptions();42 options.setCapability(CapabilityType.BROWSER_NAME, "chrome");43 options.setCapability(CapabilityType.PLATFORM_NAME, "Windows 10");44 options.setCapability(CapabilityType.VERSION, "88.0.4324.96");45 ChromeDriver driver = new ChromeDriver(options);

Full Screen

Full Screen

getPlatformName

Using AI Code Generation

copy

Full Screen

1package com.testautomationguru.ocular.comparison;2import org.openqa.selenium.Capabilities;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.remote.RemoteWebDriver;5public class BrowserNameProvider implements ComparisonCriteriaProvider {6public String getComparisonCriteria(WebDriver driver) {7Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();8return caps.getPlatform().name();9}10}11package com.testautomationguru.ocular.comparison;12import org.openqa.selenium.Capabilities;13import org.openqa.selenium.WebDriver;14import org.openqa.selenium.remote.RemoteWebDriver;15public class BrowserVersionProvider implements ComparisonCriteriaProvider {16public String getComparisonCriteria(WebDriver driver) {17Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();18return caps.getVersion();19}20}21package com.testautomationguru.ocular.comparison;22import org.openqa.selenium.Capabilities;23import org.openqa.selenium.WebDriver;24import org.openqa.selenium.remote.RemoteWebDriver;25public class ResolutionProvider implements ComparisonCriteriaProvider {26public String getComparisonCriteria(WebDriver driver) {27Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();28return caps.getCapability("screenResolution").toString();29}30}31package com.testautomationguru.ocular.comparison;32import org.openqa.selenium.Capabilities;33import org.openqa.selenium.WebDriver;34import org.openqa.selenium.remote.RemoteWebDriver;35public class DeviceNameProvider implements ComparisonCriteriaProvider {36public String getComparisonCriteria(WebDriver driver) {37Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();38return caps.getCapability("deviceName").toString();39}40}41package com.testautomationguru.ocular.comparison;42import org.openqa.selenium.Capabilities;43import org.openqa.selenium.WebDriver;44import org.openqa.selenium.remote.RemoteWebDriver;45public class DeviceOrientationProvider implements ComparisonCriteriaProvider {46public String getComparisonCriteria(WebDriver driver) {47Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();48return caps.getCapability("deviceOrientation").toString();49}50}51package com.testautomationguru.ocular.comparison;52import org.openqa.selenium.Capabilities;53import org.openqa.selenium

Full Screen

Full Screen

getPlatformName

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Capabilities;2import org.openqa.selenium.remote.RemoteWebDriver;3import org.openqa.selenium.remote.DesiredCapabilities;4public class GetPlatformName {5 public static void main(String[] args) {6 DesiredCapabilities cap = new DesiredCapabilities();7 cap.setBrowserName("Chrome");8 RemoteWebDriver driver = new RemoteWebDriver(cap);9 String platformName = driver.getCapabilities().getPlatform().getPlatformName();10 System.out.println("The platform name is: " + platformName);11 driver.quit();12 }13}

Full Screen

Full Screen

getPlatformName

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Capabilities;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.chrome.ChromeOptions;4import org.openqa.selenium.remote.DesiredCapabilities;5public class GetPlatformName {6 public static void main(String[] args) {7 System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");8 ChromeOptions options = new ChromeOptions();9 options.addArguments("--start-maximized");10 DesiredCapabilities capabilities = DesiredCapabilities.chrome();11 capabilities.setCapability(ChromeOptions.CAPABILITY, options);12 ChromeDriver driver = new ChromeDriver(capabilities);13 Capabilities cap = driver.getCapabilities();14 System.out.println("Platform name: " + cap.getPlatformName());15 driver.quit();16 }17}

Full Screen

Full Screen

getPlatformName

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Capabilities;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.firefox.FirefoxDriver;5import org.testng.annotations.AfterMethod;6import org.testng.annotations.BeforeMethod;7import org.testng.annotations.Test;8public class GetBrowserNameAndVersion {9 WebDriver driver;10 public void setup() {11 System.setProperty("webdriver.chrome.driver", "C:\\Users\\sudhanshu\\Downloads\\chromedriver_win32\\chromedriver.exe");12 System.setProperty("webdriver.gecko.driver", "C:\\Users\\sudhanshu\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe");13 }14 public void getBrowserNameAndVersion() {15 driver = new ChromeDriver();16 Capabilities caps = ((ChromeDriver) driver).getCapabilities();17 String browserName = caps.getBrowserName();18 String browserVersion = caps.getVersion();19 System.out.println("Browser Name: "+browserName);20 System.out.println("Browser Version: "+browserVersion);21 driver.quit();22 driver = new FirefoxDriver();23 caps = ((FirefoxDriver) driver).getCapabilities();24 browserName = caps.getBrowserName();25 browserVersion = caps.getVersion();26 System.out.println("Browser Name: "+browserName);27 System.out.println("Browser Version: "+browserVersion);28 driver.quit();29 }30 public void tearDown() {31 driver.quit();32 }33}

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