How to use valueOf method of org.openqa.selenium.Enum Platform class

Best Selenium code snippet using org.openqa.selenium.Enum Platform.valueOf

Source:DriverFactory.java Github

copy

Full Screen

...205 return null;206 }207 private Platform getPlatform() {208 if (!ConfigProperties.PLATFORM.get().isEmpty()) {209 return Platform.valueOf(ConfigProperties.PLATFORM.get());210 } else {211 throw new RuntimeException("Invalid platform Type");212 }213 }214 public Browser getBrowser() {215 return Browser.valueOf(ConfigProperties.BROWSER.get());216 }217 public static void downloadDriver() {218 String browser_ = Browser.valueOf(ConfigProperties.BROWSER.get()).toString();219 if (!(browser_.equalsIgnoreCase("safari"))) {220 WebDriverManager.getInstance(DriverManagerType.valueOf(browser_.toUpperCase())).setup();221 }222 }223}...

Full Screen

Full Screen

Source:WebDriverType.java Github

copy

Full Screen

...141 }142 };143 private static final Logger LOG = LoggerFactory.getLogger(WebDriverType.class);144 private static WebDriver getWebDriverWithProxyCookieSupport(Properties properties, WebDriver driver) {145 if (Boolean.valueOf(properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE))) {146 driver.get(properties.getProperty(ConfigKeys.BASE_URL));147 Cookie cookie = new Cookie(148 properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE_NAME),149 properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE_VALUE),150 "." + properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE_DOMAIN), "/",151 DateUtils.addMonths(new Date(), 1));152 driver.manage().addCookie(cookie);153 }154 return driver;155 }156 public abstract WebDriver create(Capabilities capabilities, Properties properties);157 /**158 * Returns WebDriverType for name159 *160 * @param typeName name of web driver type161 * @return WebDriverType162 */163 public static WebDriverType get(String typeName) {164 WebDriverType webDriverType = WebDriverType.HTML;165 if (StringUtils.isNotBlank(typeName)) {166 try {167 webDriverType = WebDriverType.valueOf(typeName.toUpperCase());168 } catch (IllegalArgumentException e) {169 LOG.error("Illegal type: " + typeName, e);170 }171 }172 return webDriverType;173 }174}...

Full Screen

Full Screen

Source:WebDriverFactory.java Github

copy

Full Screen

...23 final String pathWebDriverChromeMac = PropertiesReader.getProperty("path.webDriver.chrome.mac");24 final String pathWebDriverChromeWin = PropertiesReader.getProperty("path.webDriver.chrome.win");25 final String pathWebDriverIe = PropertiesReader.getProperty("path.webDriver.ie");26 final String remoteWebDriverUrl = PropertiesReader.getProperty("remote.webDriver.url");27 final Browsers propertyBrowserTypeEnum = Browsers.valueOf(propertyBrowser.toUpperCase());28 final Browsers cmdBrowserTypeEnum = Browsers.valueOf(browser.toUpperCase());29 final boolean isRemote = Boolean.valueOf(remote);30 if (!isRemote) {31 if ("default".equals(browser)) {32 switch (propertyBrowserTypeEnum) { //Switching browser if using property33 case CHROME_MAC:34 System.setProperty(webDriverChrome, pathWebDriverChromeMac);35 driver = new ChromeDriver();36 break;37 case CHROME:38 System.setProperty(webDriverChrome, pathWebDriverChromeWin);39 driver = new ChromeDriver();40 break;41 case EXPLORER:42 System.setProperty(webDriverIe, pathWebDriverIe);43 driver = new InternetExplorerDriver();44 break;45 case FIREFOX:46 default:47 driver = new FirefoxDriver();48 break;49 }50 } else {51 switch (cmdBrowserTypeEnum) { //Switching browser if using command line52 case CHROME_MAC:53 System.setProperty(webDriverChrome, pathWebDriverChromeMac);54 driver = new ChromeDriver();55 break;56 case CHROME:57 System.setProperty(webDriverChrome, pathWebDriverChromeWin);58 driver = new ChromeDriver();59 break;60 case EXPLORER:61 System.setProperty(webDriverIe, pathWebDriverIe);62 driver = new InternetExplorerDriver();63 break;64 case FIREFOX:65 default:66 driver = new FirefoxDriver();67 break;68 }69 }70 } else {71 capabilities72 .setPlatform(Platform.valueOf(platform.toUpperCase()));73 capabilities74 .setBrowserName(String.valueOf(browser));75 capabilities76 .setVersion(version);77 driver = new RemoteWebDriver(new URL(remoteWebDriverUrl), capabilities);78 }79 }80}...

Full Screen

Full Screen

Source:Browser.java Github

copy

Full Screen

...21 private FirefoxProfile firefoxProfile;22 private String version;23 private String platform;24 public Browser(String type, URL hub) {25 this.type = BrowserType.valueOf(type.toUpperCase());26 this.hub = hub;27 }28 public Browser(String type) {29 this.type = BrowserType.valueOf(type.toUpperCase());30 }31 public Browser(String type, URL hub, String version, String platform) {32 this.type = BrowserType.valueOf(type.toUpperCase());33 this.hub = hub;34 this.version = version;35 this.platform = platform;36 }37 public WebDriver getNewDriver() {38 WebDriver driver;39 if (hub != null) {40 driver = getRemoteDriver();41 } else {42 driver = getLocalDriver();43 }44 if (windowMaximize) {45 driver.manage().window().maximize();46 } else {47 driver.manage().window().setPosition(new Point(0, 0));48 driver.manage().window()49 .setSize(new Dimension(windowWidth, windowHeigth));50 }51 return driver;52 }53 public void setWindowMaximize(boolean windowMaximize) {54 this.windowMaximize = windowMaximize;55 }56 public void setWindowDimensions(int windowWidth, int windowHeigth) {57 this.windowWidth = windowWidth;58 this.windowHeigth = windowHeigth;59 }60 public void setFirefoxProfile(String profileParam) {61 File profileDir = new File(profileParam);62 this.firefoxProfile = new FirefoxProfile(profileDir);63 }64 private String convertBrowsersname(){65 String browserName = "";66 switch (this.type) {67 case FIREFOX:68 browserName="firefox";69 break;70 case IE:71 browserName="internet explorer";72 break;73 case CHROME:74 browserName="chrome";75 break;76 default:77 browserName="firefox";78 break;79 }80 return browserName;81 82 }83 84 private WebDriver getRemoteDriver() {85 DesiredCapabilities capabilities;86 if (version != null && platform != null) {87 capabilities = new DesiredCapabilities();88 capabilities.setBrowserName(convertBrowsersname());89 capabilities.setVersion(this.version);90 capabilities.setPlatform(Platform.valueOf(this.platform));91 } else {92 switch (this.type) {93 case FIREFOX:94 capabilities = DesiredCapabilities.firefox();95 if (this.firefoxProfile != null)96 capabilities.setCapability(FirefoxDriver.PROFILE,97 this.firefoxProfile);98 break;99 case IE:100 capabilities = DesiredCapabilities.internetExplorer();101 break;102 case CHROME:103 capabilities = DesiredCapabilities.chrome();104 break;...

Full Screen

Full Screen

Source:DriverSelector.java Github

copy

Full Screen

...7import java.net.MalformedURLException;8import java.net.URL;9import static org.openqa.selenium.Proxy.ProxyType.MANUAL;10import static selenium.config.DriverEnum.CHROME;11import static selenium.config.DriverEnum.valueOf;12public class DriverSelector {13 private WebDriver webdriver;14 private DriverEnum selectedDriverType;15 private final DriverEnum defaultDriverType = CHROME;16 private final String browser = System.getProperty("browser", defaultDriverType.toString()).toUpperCase();17 private final String operatingSystem = System.getProperty("os.name").toUpperCase();18 private final String systemArchitecture = System.getProperty("os.arch");19 private final boolean useRemoteWebDriver = Boolean.getBoolean("remoteDriver");20 private final boolean proxyEnabled = Boolean.getBoolean("proxyEnabled");21 private final String proxyHostname = System.getProperty("proxyHost");22 private final Integer proxyPort = Integer.getInteger("proxyPort");23 private final String proxyDetails = String.format("%s:%d", proxyHostname, proxyPort);24 public WebDriver getDriver() throws Exception {25 if (null == webdriver) {26 Proxy proxy = null;27 if (proxyEnabled) {28 proxy = new Proxy();29 proxy.setProxyType(MANUAL);30 proxy.setHttpProxy(proxyDetails);31 proxy.setSslProxy(proxyDetails);32 }33 determineEffectiveDriverType();34 DesiredCapabilities desiredCapabilities = selectedDriverType.getDesiredCapabilities(proxy);35 instantiateWebDriver(desiredCapabilities);36 }37 return webdriver;38 }39 public void quitDriver() {40 if (null != webdriver) {41 webdriver.quit();42 }43 }44 private void determineEffectiveDriverType() {45 DriverEnum driverType = defaultDriverType;46 try {47 driverType = valueOf(browser);48 } catch (IllegalArgumentException ignored) {49 System.err.println("Unknown driver specified, defaulting to '" + driverType + "'...");50 } catch (NullPointerException ignored) {51 System.err.println("No driver specified, defaulting to '" + driverType + "'...");52 }53 selectedDriverType = driverType;54 }55 private void instantiateWebDriver(DesiredCapabilities desiredCapabilities) throws MalformedURLException {56 System.out.println(" ");57 System.out.println("Current Operating System: " + operatingSystem);58 System.out.println("Current Architecture: " + systemArchitecture);59 System.out.println("Current Browser Selection: " + selectedDriverType);60 System.out.println(" ");61 if (useRemoteWebDriver) {62 URL seleniumGridURL = new URL(System.getProperty("gridURL"));63 String desiredBrowserVersion = System.getProperty("desiredBrowserVersion");64 String desiredPlatform = System.getProperty("desiredPlatform");65 if (null != desiredPlatform && !desiredPlatform.isEmpty()) {66 desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));67 }68 if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {69 desiredCapabilities.setVersion(desiredBrowserVersion);70 }71 webdriver = new RemoteWebDriver(seleniumGridURL, desiredCapabilities);72 } else {73 webdriver = selectedDriverType.getWebDriverObject(desiredCapabilities);74 }75 }76}...

Full Screen

Full Screen

valueOf

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Platform;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.net.InetAddress;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.Alert;10import org.openqa.selenium.By;11import org.openqa.selenium.WebElement;12public class TestSelenium {13public static void main(String[] args) throws MalformedURLException {14DesiredCapabilities capabilities = DesiredCapabilities.firefox();15capabilities.setCapability("platform", Platform.ANY);16capabilities.setCapability("version", "ANY");17driver.quit();18}19}20Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.remote.DesiredCapabilities.setCapability(Ljava/lang/String;Lorg/openqa/selenium/Platform;)V21at TestSelenium.main(TestSelenium.java:13)

Full Screen

Full Screen

valueOf

Using AI Code Generation

copy

Full Screen

1package com.selenium4beginners.java.enums;2import org.openqa.selenium.Platform;3public class EnumValueOfMethod {4 public static void main(String[] args) {5 Platform platform = Platform.valueOf("WINDOWS");6 System.out.println("Platform: " + platform);7 }8}9Enum values() Method in Java10Enum[] values()11package com.selenium4beginners.java.enums;12import org.openqa.selenium.Platform;13public class EnumValuesMethod {14 public static void main(String[] args) {15 Platform[] platforms = Platform.values();16 for (Platform platform : platforms) {17 System.out.println("Platform: " + platform);18 }19 }20}21Enum ordinal() Method in Java22int ordinal()23package com.selenium4beginners.java.enums;24import org.openqa.selenium.Platform;25public class EnumOrdinalMethod {26 public static void main(String[] args) {27 Platform platform = Platform.valueOf("WINDOWS");28 System.out.println("Ordinal: " + platform.ordinal());29 }30}31Enum compareTo() Method in Java32int compareTo(Enum enum)

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