How to use Enum Platform class of org.openqa.selenium package

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

Source:DriverFactory.java Github

copy

Full Screen

1package com.maveric.core.driver;2import com.maveric.core.config.ConfigProperties;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.ios.IOSDriver;5import io.github.bonigarcia.wdm.WebDriverManager;6import io.github.bonigarcia.wdm.config.DriverManagerType;7import org.apache.logging.log4j.LogManager;8import org.apache.logging.log4j.Logger;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.chrome.ChromeDriver;11import org.openqa.selenium.chrome.ChromeOptions;12import org.openqa.selenium.edge.EdgeDriver;13import org.openqa.selenium.edge.EdgeOptions;14import org.openqa.selenium.firefox.FirefoxDriver;15import org.openqa.selenium.firefox.FirefoxDriverLogLevel;16import org.openqa.selenium.firefox.FirefoxOptions;17import org.openqa.selenium.ie.InternetExplorerDriver;18import org.openqa.selenium.ie.InternetExplorerOptions;19import org.openqa.selenium.remote.CapabilityType;20import org.openqa.selenium.remote.DesiredCapabilities;21import org.openqa.selenium.remote.RemoteWebDriver;22import org.openqa.selenium.safari.SafariDriver;23import org.openqa.selenium.safari.SafariOptions;24import java.net.MalformedURLException;25import java.net.URL;26import java.util.HashMap;27public class DriverFactory {28 public static final Logger logger = LogManager.getLogger();29 public static final String OS = System.getProperty("os.name").toLowerCase();30 public enum Browser {31 firefox, chrome, edge, iexplorer, safari32 }33 public enum RemoteGrid {34 sauce, browserstack, grid35 }36 public enum Platform {37 windows, macos, ios, android, linux38 }39 public void driverSetup() {40 Browser browser = getBrowser();41 if (isRemote()) {42 createRemoteDriver();43 } else {44 Driver.setWebDriver(createDriver(browser));45 }46 }47 public WebDriver createDriver(Browser browser) {48 switch (browser) {49 case firefox:50 return getFirefoxDriver();51 case chrome:52 return getChromeDriver();53 case edge:54 return getEdgeDriver();55 case iexplorer:56 return getIEDriver();57 case safari:58 return getSafariDriver();59 default:60 throw new RuntimeException("Invalid Browser");61 }62 }63 private WebDriver getSafariDriver() {64 SafariOptions safariOptions = new SafariOptions();65 safariOptions.setCapability("safari.cleanSession", true);66 return new SafariDriver(safariOptions);67 }68 private WebDriver getIEDriver() {69 InternetExplorerOptions ieOptions = new InternetExplorerOptions();70 ieOptions.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);71 ieOptions.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, true);72 ieOptions.setCapability("requireWindowFocus", true);73 ieOptions.takeFullPageScreenshot();74 ieOptions.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);75 ieOptions.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);76 ieOptions.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, false);77 ieOptions.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);78 ieOptions.setCapability("ignoreProtectedModeSettings", true);79 return new InternetExplorerDriver(ieOptions);80 }81 private WebDriver getEdgeDriver() {82 EdgeOptions edgeOptions = new EdgeOptions();83 return new EdgeDriver(edgeOptions);84 }85 private WebDriver getChromeDriver() {86 ChromeOptions chromeOptions = new ChromeOptions();87 chromeOptions.setHeadless(ConfigProperties.HEADLESS.getBoolean());88 if (OS.contains("nix") || OS.contains("nux")89 || OS.contains("aix")) {90 chromeOptions.addArguments("--disable-extensions");91 chromeOptions.addArguments("--disable-gpu");92 chromeOptions.addArguments("--disable-dev-shm-usage");93 chromeOptions.addArguments("--no-sandbox");94 }95 if (!ConfigProperties.CHROME_DEVICE.get().isEmpty()) {96 chromeOptions.setExperimentalOption(97 "mobileEmulation", new HashMap<String, Object>() {{98 put("deviceName", ConfigProperties.CHROME_DEVICE.get());99 }});100 }101 return new ChromeDriver(chromeOptions);102 }103 private WebDriver getFirefoxDriver() {104 FirefoxOptions firefoxOptions = new FirefoxOptions();105 firefoxOptions.setHeadless(ConfigProperties.HEADLESS.getBoolean());106 firefoxOptions.setLogLevel(FirefoxDriverLogLevel.INFO);107 return new FirefoxDriver(firefoxOptions);108 }109 public void createRemoteDriver() {110 try {111 DesiredCapabilities caps = new DesiredCapabilities();112 RemoteCapabilities remoteCaps = new RemoteCapabilities(getPlatform(), getBrowser());113 URL remoteURL;114 switch (getRemoteType()) {115 case browserstack:116 caps.merge(remoteCaps.getBrowserstackCapabilities());117 remoteURL = getBrowserStackURL();118 break;119 case sauce:120 caps.merge(remoteCaps.getSauceCapabilities());121 remoteURL = getSauceURL();122 logger.info("sauce");123 break;124 case grid:125 caps.merge(remoteCaps.getGridCapabilities());126 remoteURL = getGridURL();127 break;128 default:129 throw new RuntimeException("Invalid Remote Type");130 }131 caps.asMap().forEach((key, value) -> logger.info(key + " : " + value));132 boolean isNative = false;133 Object appCap = caps.getCapability("app");134 if (appCap != null && !(appCap.toString().isEmpty())) {135 isNative = true;136 }137 switch (getPlatform()) {138 case ios:139 if (isNative)140 Driver.setAppiumDriver(new IOSDriver<>(remoteURL, caps));141 else142 Driver.setWebDriver(new RemoteWebDriver(remoteURL, caps));143 break;144 case android:145 if (isNative)146 Driver.setAppiumDriver(new AndroidDriver<>(remoteURL, caps));147 else148 Driver.setWebDriver(new RemoteWebDriver(remoteURL, caps));149 break;150 case macos:151 case windows:152 case linux:153 Driver.setWebDriver(new RemoteWebDriver(remoteURL, caps));154 break;155 }156 } catch (Exception e) {157 e.printStackTrace();158 }159 }160 private RemoteGrid getRemoteType() {161 if (ConfigProperties.BROWSER_STACK.getBoolean()) {162 return RemoteGrid.browserstack;163 } else if (ConfigProperties.SAUCE.getBoolean()) {164 return RemoteGrid.sauce;165 } else {166 return RemoteGrid.grid;167 }168 }169 public boolean isRemote() {170 return (!ConfigProperties.GRID_URL.get().isEmpty())171 || ConfigProperties.SAUCE.getBoolean()172 || ConfigProperties.BROWSER_STACK.getBoolean();173 }174 private static URL getGridURL() {175 try {176 return new URL(ConfigProperties.GRID_URL.get());177 } catch (MalformedURLException e) {178 e.printStackTrace();179 }180 return null;181 }182 private static URL getBrowserStackURL() {183 try {184 String url = String.format("https://%s:%s@%s",185 ConfigProperties.BROWSER_STACK_USERNAME.get(),186 ConfigProperties.BROWSER_STACK_ACCESS_KEY.get(),187 ConfigProperties.BROWSER_STACK_HUB.get());188 return new URL(url);189 } catch (MalformedURLException e) {190 e.printStackTrace();191 }192 return null;193 }194 private static URL getSauceURL() {195 try {196 String url = String.format(197 "https://%s:%s@%s",198 ConfigProperties.SAUCE_USERNAME.get(),199 ConfigProperties.SAUCE_ACCESS_KEY.get(),200 ConfigProperties.SAUCE_HUB.get());201 return new URL(url);202 } catch (MalformedURLException e) {203 e.printStackTrace();204 }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

1/*-2 * #%L3 * Bobcat4 * %%5 * Copyright (C) 2016 Cognifide Ltd.6 * %%7 * Licensed under the Apache License, Version 2.0 (the "License");8 * you may not use this file except in compliance with the License.9 * You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * distributed under the License is distributed on an "AS IS" BASIS,15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16 * See the License for the specific language governing permissions and17 * limitations under the License.18 * #L%19 */20package com.cognifide.qa.bb.provider.selenium.webdriver;21import java.io.File;22import java.net.MalformedURLException;23import java.net.URL;24import java.util.Date;25import java.util.Properties;26import org.apache.commons.lang3.StringUtils;27import org.apache.commons.lang3.time.DateUtils;28import org.openqa.selenium.Capabilities;29import org.openqa.selenium.Cookie;30import org.openqa.selenium.WebDriver;31import org.openqa.selenium.chrome.ChromeDriver;32import org.openqa.selenium.firefox.FirefoxBinary;33import org.openqa.selenium.firefox.FirefoxDriver;34import org.openqa.selenium.htmlunit.HtmlUnitDriver;35import org.openqa.selenium.ie.InternetExplorerDriver;36import org.openqa.selenium.phantomjs.PhantomJSDriver;37import org.openqa.selenium.remote.DesiredCapabilities;38import org.openqa.selenium.remote.RemoteWebDriver;39import org.openqa.selenium.safari.SafariDriver;40import org.slf4j.Logger;41import org.slf4j.LoggerFactory;42import com.cognifide.qa.bb.constants.ConfigKeys;43import io.appium.java_client.android.AndroidDriver;44import io.appium.java_client.ios.IOSDriver;45import io.appium.java_client.remote.MobilePlatform;46/**47 * Enum represent available web driver types.48 */49public enum WebDriverType {50 FIREFOX {51 @Override52 public WebDriver create(Capabilities capabilities, Properties properties) {53 return getWebDriverWithProxyCookieSupport(properties, new FirefoxDriver(capabilities));54 }55 },56 MARIONETTE {57 @Override58 public WebDriver create(Capabilities capabilities, Properties properties) {59 DesiredCapabilities caps = DesiredCapabilities.firefox();60 caps.setCapability("marionette", true);61 return getWebDriverWithProxyCookieSupport(properties, new FirefoxDriver(capabilities));62 }63 },64 CHROME {65 @Override66 public WebDriver create(Capabilities capabilities, Properties properties) {67 return getWebDriverWithProxyCookieSupport(properties, new ChromeDriver(capabilities));68 }69 },70 IE {71 @Override72 public WebDriver create(Capabilities capabilities, Properties properties) {73 return getWebDriverWithProxyCookieSupport(properties, new InternetExplorerDriver(capabilities));74 }75 },76 SAFARI {77 @Override78 public WebDriver create(Capabilities capabilities, Properties properties) {79 return getWebDriverWithProxyCookieSupport(properties, new SafariDriver(capabilities));80 }81 },82 HTML {83 @Override84 public WebDriver create(Capabilities capabilities, Properties properties) {85 return getWebDriverWithProxyCookieSupport(properties, new HtmlUnitDriver(capabilities));86 }87 },88 GHOST {89 @Override90 public WebDriver create(Capabilities capabilities, Properties properties) {91 return getWebDriverWithProxyCookieSupport(properties, new PhantomJSDriver());92 }93 },94 APPIUM {95 @Override96 public WebDriver create(Capabilities capabilities, Properties properties) {97 return getWebDriverWithProxyCookieSupport(properties, createMobileDriver(capabilities, properties));98 }99 private WebDriver createMobileDriver(Capabilities capabilities, Properties properties) {100 final URL url;101 try {102 url = new URL(properties.getProperty(ConfigKeys.WEBDRIVER_APPIUM_URL));103 } catch (MalformedURLException e) {104 throw new IllegalArgumentException(e);105 }106 final String platform = properties.getProperty(ConfigKeys.WEBDRIVER_CAP_PLATFORM_NAME);107 switch (platform) {108 case MobilePlatform.ANDROID:109 return new AndroidDriver(url, capabilities);110 case MobilePlatform.IOS:111 return new IOSDriver(url, capabilities);112 default:113 throw new IllegalArgumentException(String.format(114 "webdriver.cap.platformName not configured correctly. Set it either to %s or %s",115 MobilePlatform.ANDROID, MobilePlatform.IOS));116 }117 }118 },119 REMOTE {120 @Override121 public WebDriver create(Capabilities capabilities, Properties properties) {122 final URL url;123 try {124 url = new URL(properties.getProperty(ConfigKeys.WEBDRIVER_URL));125 } catch (MalformedURLException e) {126 throw new IllegalArgumentException(e);127 }128 WebDriver driver = new RemoteWebDriver(url, capabilities);129 return getWebDriverWithProxyCookieSupport(properties, driver);130 }131 },132 XVFB {133 @Override134 public WebDriver create(Capabilities capabilities, Properties properties) {135 final File firefoxPath = new File(properties.getProperty(ConfigKeys.WEBDRIVER_FIREFOX_BIN));136 FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);137 firefoxBinary.setEnvironmentProperty("DISPLAY",138 properties.getProperty(ConfigKeys.WEBDRIVER_XVFB_ID));139 return getWebDriverWithProxyCookieSupport(properties,140 new FirefoxDriver(firefoxBinary, null, capabilities));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:MobileBrowser.java Github

copy

Full Screen

1package jp.co.rakuten.travel.framework.browser;2import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;3import static org.openqa.selenium.remote.CapabilityType.PLATFORM;4import java.io.File;5import java.net.MalformedURLException;6import java.net.URL;7import java.util.HashMap;8import java.util.Map;9import org.openqa.selenium.Dimension;10import org.openqa.selenium.Platform;11import org.openqa.selenium.Proxy;12import org.openqa.selenium.UnexpectedAlertBehaviour;13import org.openqa.selenium.WebDriverException;14import org.openqa.selenium.chrome.ChromeDriver;15import org.openqa.selenium.chrome.ChromeOptions;16import org.openqa.selenium.firefox.FirefoxDriver;17import org.openqa.selenium.firefox.FirefoxProfile;18import org.openqa.selenium.remote.CapabilityType;19import org.openqa.selenium.remote.DesiredCapabilities;20import org.openqa.selenium.remote.RemoteWebDriver;21import jp.co.rakuten.travel.framework.parameter.TestApiObject;22import jp.co.rakuten.travel.framework.parameter.TestApiParameters;23import jp.co.rakuten.travel.framework.utility.Utility;24public final class MobileBrowser extends BrowserImpl25{26 BrowserType m_driverBrowserType;27 protected MobileBrowser( File pacFile )28 {29 super( pacFile );30 switch( Utility.getEnum( TestApiObject.instance().get( TestApiParameters.API_BROWSER ), BrowserType.class ) )31 {32 case MOBILE_FIREFOX:33 m_driverBrowserType = BrowserType.FIREFOX;34 break;35 case MOBILE_CHROME:36 m_driverBrowserType = BrowserType.CHROME;37 break;38 default:39 break;40 }41 }42 @Override43 protected void onSetupProxy( Proxy proxy )44 {45 /**46 * No changes necessary for proxy47 */48 }49 @Override50 protected void onSetupCapabilities( DesiredCapabilities capabilities )51 {52 capabilities.setCapability( BROWSER_NAME, m_driverBrowserType );53 }54 @Override55 protected void onSetupDriver()56 {57 if( Boolean.getBoolean( TestApiObject.instance().get( TestApiParameters.API_SAUCE_LABS_ENABLED ) ) )58 {59 String username = TestApiObject.instance().get( TestApiParameters.API_SAUCE_LABS_USERNAME );60 String password = TestApiObject.instance().get( TestApiParameters.API_SAUCE_LABS_PASSWORD );61 try62 {63 m_driver = new RemoteWebDriver( new URL( "http://" + username + ":" + password + "@ondemand.saucelabs.com:80/wd/hub" ), m_capabilities );64 printSessionId();65 }66 catch( MalformedURLException e )67 {68 throw new WebDriverException( "Original Exception from " + e.getClass().getSimpleName(), e );69 }70 }71 else72 {73 switch( m_driverBrowserType )74 {75 case FIREFOX:76 m_driver = new FirefoxDriver( m_capabilities );77 UserAgentType userAgent = Utility.getEnum( TestApiObject.instance().get( TestApiParameters.API_USER_AGENT ), UserAgentType.class );78 m_driver.manage().window().setSize( new Dimension( userAgent.width(), userAgent.length() ) );79 break;80 case CHROME:81 try82 {83 m_driver = new ChromeDriver( m_capabilities );84 }85 catch( Exception e )86 {87 LOG.warn( "Please check Environment Variables for chromedriver" );88 LOG.warn( e.getClass().getSimpleName() + " found with message " + e.getMessage(), e );89 if( m_driver == null )90 {91 throw new NullPointerException( "Browser not supported " + m_driverBrowserType );92 }93 }94 break;95 default:96 break;97 }98 }99 }100 @Override101 protected void setupCapabilities()102 {103 LOG.info( "setupCapabilities" );104 m_capabilities = new DesiredCapabilities();105 UserAgentType userAgent = Utility.getEnum( TestApiObject.instance().get( TestApiParameters.API_USER_AGENT ), UserAgentType.class );106 m_capabilities.setBrowserName( TestApiObject.instance().get( TestApiParameters.API_BROWSER ) );107 m_capabilities.setVersion( TestApiObject.instance().get( TestApiParameters.API_BROWSER_VERSION ) );108 if( Boolean.getBoolean( TestApiObject.instance().get( TestApiParameters.API_SAUCE_LABS_ENABLED ) ) )109 {110 String username = TestApiObject.instance().get( TestApiParameters.API_SAUCE_LABS_USERNAME );111 String version = TestApiObject.instance().get( TestApiParameters.API_BROWSER_VERSION );112 m_capabilities.setCapability( PLATFORM, TestApiObject.instance().get( TestApiParameters.API_SAUCE_LABS_PLATFORM ) );113 m_capabilities.setCapability( "name", username );114 m_capabilities.setCapability( "build", version );115 }116 else117 {118 m_capabilities.setCapability( PLATFORM, Platform.ANY );119 m_capabilities.setCapability( CapabilityType.PROXY, m_proxy );120 }121 switch( m_driverBrowserType )122 {123 case FIREFOX:124 FirefoxProfile customProfile = new FirefoxProfile();125 customProfile.setPreference( "general.useragent.override", userAgent.val() );126 m_capabilities.setCapability( FirefoxDriver.PROFILE, customProfile );127 m_capabilities.setCapability( CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT );128 m_capabilities.setCapability( CapabilityType.ACCEPT_SSL_CERTS, true );129 m_capabilities.setCapability( CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true );130 break;131 case CHROME:132 Map< String, String > mobileEmulation = new HashMap< String, String >();133 mobileEmulation.put( "deviceName", userAgent.val() );134 Map< String, Object > chromeOptions = new HashMap< String, Object >();135 chromeOptions.put( "mobileEmulation", mobileEmulation );136 m_capabilities.setCapability( ChromeOptions.CAPABILITY, chromeOptions );137 break;138 default:139 break;140 }141 onSetupCapabilities( m_capabilities );142 }143}...

Full Screen

Full Screen

Source:BrowserManagerEnum.java Github

copy

Full Screen

1package com.mycorp;2import java.util.Map;3import org.apache.commons.lang3.StringUtils;4import org.openqa.selenium.Capabilities;5import org.openqa.selenium.Platform;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.edge.EdgeDriver;9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.ie.InternetExplorerDriver;11import org.openqa.selenium.opera.OperaDriver;12import org.openqa.selenium.phantomjs.PhantomJSDriver;13import org.openqa.selenium.remote.BrowserType;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.remote.RemoteWebDriver;16import org.openqa.selenium.remote.Response;17import io.github.bonigarcia.wdm.BrowserManager;18import io.github.bonigarcia.wdm.ChromeDriverManager;19import io.github.bonigarcia.wdm.EdgeDriverManager;20import io.github.bonigarcia.wdm.FirefoxDriverManager;21import io.github.bonigarcia.wdm.InternetExplorerDriverManager;22import io.github.bonigarcia.wdm.OperaDriverManager;23import io.github.bonigarcia.wdm.PhantomJsDriverManager;24import io.github.bonigarcia.wdm.VoidDriverManager;25public enum BrowserManagerEnum {26 CHROME( "chrome" ),27 FIREFOX( "firefox" ),28 EDGE( "edge" ),29 IE( "ie" ),30 MARIONETTE( "marionette" ),31 OPERA( "opera" ),32 PHANTOMJS( "phantomjs" ),33 NONE( "test" );34 private final String browserName;35 private BrowserManagerEnum( final String browserName ) {36 this.browserName = browserName;37 }38 public static BrowserManagerEnum of( final String browserName ) {39 final String lBrowserName = StringUtils.lowerCase( browserName );40 for( final BrowserManagerEnum browser : BrowserManagerEnum.values() ) {41 if( browser.browserName.equals( lBrowserName ) ) {42 return browser;43 }44 }45 return NONE;46 }47 public BrowserManager getBrowserManager() {48 switch( this ) {49 case CHROME: return ChromeDriverManager.getInstance().version( "2.24" );50 case MARIONETTE:51 case FIREFOX: return FirefoxDriverManager.getInstance();52 case EDGE: return EdgeDriverManager.getInstance();53 case IE: return InternetExplorerDriverManager.getInstance();54 case OPERA: return OperaDriverManager.getInstance();55 case PHANTOMJS: return PhantomJsDriverManager.getInstance();56 case NONE: default: return VoidDriverManager.getInstance().version( "1" );57 }58 }59 public BrowserManager getBrowserManager( final String version ) {60 return getBrowserManager().version( version );61 }62 public WebDriver getDriver() {63 switch( this ) {64 case CHROME: return new ChromeDriver();65 case MARIONETTE:66 case FIREFOX: return new FirefoxDriver();67 case EDGE: return new EdgeDriver();68 case IE: return new InternetExplorerDriver();69 case OPERA: return new OperaDriver();70 case PHANTOMJS: return new PhantomJSDriver();71 case NONE: default:72 final DesiredCapabilities dc = new DesiredCapabilities( BrowserType.MOCK, "mock-version", Platform.ANY );73 final RemoteWebDriver mock = new RemoteWebDriver( dc ) {74 /**75 * {@inheritDoc}76 *77 * @see RemoteWebDriver#execute(String, Map)78 */79 @Override80 protected Response execute( final String driverCommand, final Map< String, ? > parameters ) {81 return new Response();82 }83 /**84 * {@inheritDoc}85 *86 * @see RemoteWebDriver#startSession(Capabilities, Capabilities)87 */88 @Override89 protected void startSession( final Capabilities desiredCapabilities, final Capabilities requiredCapabilities ) {90 setSessionId( "mock" );91 }92 };93 return mock;94 }95 }96}...

Full Screen

Full Screen

Source:WebDriverFactory.java Github

copy

Full Screen

1package academy.softserve.edu.utils;2import academy.softserve.edu.enums.Browsers;3import lombok.Getter;4import org.openqa.selenium.Platform;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.firefox.FirefoxDriver;8import org.openqa.selenium.ie.InternetExplorerDriver;9import org.openqa.selenium.remote.DesiredCapabilities;10import org.openqa.selenium.remote.RemoteWebDriver;11import java.net.MalformedURLException;12import java.net.URL;13public class WebDriverFactory {14 @Getter15 private WebDriver driver;16 final void setDriver(final String browser, final String version) throws MalformedURLException {17 final DesiredCapabilities capabilities = new DesiredCapabilities();18 final String remote = PropertiesReader.getProperty("remote");19 final String propertyBrowser = PropertiesReader.getProperty("browser");20 final String platform = PropertiesReader.getProperty("platform");21 final String webDriverChrome = PropertiesReader.getProperty("webDriver.chrome");22 final String webDriverIe = PropertiesReader.getProperty("webDriver.ie");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:DriverManager.java Github

copy

Full Screen

1import io.github.bonigarcia.wdm.WebDriverManager;2import org.openqa.selenium.MutableCapabilities;3import org.openqa.selenium.Platform;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.chrome.ChromeOptions;7import org.openqa.selenium.edge.EdgeDriver;8import org.openqa.selenium.edge.EdgeOptions;9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.firefox.FirefoxOptions;11import org.openqa.selenium.remote.DesiredCapabilities;12import org.openqa.selenium.remote.RemoteWebDriver;13import java.net.MalformedURLException;14import java.net.URL;15public class DriverManager {16 protected RunType runType;17 private static final ThreadLocal<WebDriver> driver = new ThreadLocal<>();18 public enum RunType {LOCAL, GRID}19 private static void createLocalDriver(String browser, String browserVersion, String platformName) {20 MutableCapabilities capabilities ;21 switch (browser) {22 case "chrome" -> {23 WebDriverManager.chromedriver().setup();24 ChromeOptions chromeOptions = new ChromeOptions();25 chromeOptions.addArguments("--disable-notifications", "--disable-popup-blocking", "–disable-infobars");26 capabilities = chromeOptions;27 capabilities.setCapability("browserVersion", browserVersion);28 capabilities.setCapability("platformName", platformName);29 driver.set(new ChromeDriver(capabilities));30 }31 case "firefox" -> {32 WebDriverManager.firefoxdriver().setup();33 FirefoxOptions firefoxOptions = new FirefoxOptions();34 firefoxOptions.addArguments("--disable-notifications", "--disable-popup-blocking", "–disable-infobars");35 capabilities = firefoxOptions;36 capabilities.setCapability("browserVersion", browserVersion);37 capabilities.setCapability("platformName", platformName);38 driver.set(new FirefoxDriver(firefoxOptions));39 }40 case "edge" -> {41 WebDriverManager.edgedriver().setup();42 EdgeOptions edgeOptions = new EdgeOptions();43 edgeOptions.addArguments("--disable-notifications", "--disable-popup-blocking", "–disable-infobars");44 capabilities = edgeOptions;45 capabilities.setCapability("browserVersion", browserVersion);46 capabilities.setCapability("platformName", platformName);47 driver.set(new EdgeDriver(capabilities));48 }49 }50 }51 private static void createGridDriver(String browser, String browserVersion, String platformName) {52 DesiredCapabilities gridCapabilities = new DesiredCapabilities();53 gridCapabilities.setBrowserName(browser);54 gridCapabilities.setVersion(browserVersion);55 gridCapabilities.setPlatform(Platform.extractFromSysProperty(platformName));56 String GRID_REMOTE_URL = "http://localhost:4455/wd/hub";57 try {58 driver.set(new RemoteWebDriver(new URL(GRID_REMOTE_URL), gridCapabilities));59 } catch (MalformedURLException e) {60 throw new RuntimeException(e);61 }62 }63 protected static void createDriver(String browser, String browserVersion, String platformName, RunType runType) {64 switch (runType) {65 case LOCAL:66 createLocalDriver(browser,browserVersion,platformName);67 break;68 case GRID:69 createGridDriver(browser,browserVersion,platformName);70 break;71 }72 }73 protected static WebDriver getDriver() {74 return driver.get();75 }76 protected static void closeDriver() {77 driver.get().quit();78 driver.remove();79 }80}...

Full Screen

Full Screen

Source:DriverSelector.java Github

copy

Full Screen

1package selenium.config;2import org.openqa.selenium.Platform;3import org.openqa.selenium.Proxy;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.openqa.selenium.remote.RemoteWebDriver;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

Source:DriverOptions.java Github

copy

Full Screen

1package support.base;2import io.github.bonigarcia.wdm.WebDriverManager;3import org.openqa.selenium.Platform;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.chrome.ChromeOptions;7import org.openqa.selenium.edge.EdgeDriver;8import org.openqa.selenium.edge.EdgeOptions;9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.firefox.FirefoxOptions;11import org.openqa.selenium.remote.DesiredCapabilities;12/**13 * @author Muhammad Tafseer Haider14 */15public enum DriverOptions implements DriverSetup {16 FIREFOX {17 public WebDriver getWebDriverObject(DesiredCapabilities capabilities) {18 WebDriverManager.firefoxdriver().setup();19 FirefoxOptions options = new FirefoxOptions();20 capabilities.setPlatform(Platform.ANY);21 options.merge(capabilities);22 return new FirefoxDriver(options);23 }24 },25 CHROME {26 public WebDriver getWebDriverObject(DesiredCapabilities capabilities) {27 WebDriverManager.chromedriver().setup();28 ChromeOptions options = new ChromeOptions();29 options.addArguments("--incognito");30 options.addArguments("--no-sandbox");31 options.addArguments("--disable-gpu");32 options.addArguments("--no-default-browser-check");33 options.setCapability("applicationCacheEnabled", false);34 options.merge(capabilities);35 return new ChromeDriver(options);36 }37 },38 EDGE {39 public WebDriver getWebDriverObject(DesiredCapabilities capabilities) {40 WebDriverManager.edgedriver().setup();41 EdgeOptions options = new EdgeOptions();42 options.setCapability("useAutomationExtension", false);43 options.merge(capabilities);44 return new EdgeDriver(options);45 }46 }47}...

Full Screen

Full Screen

Enum Platform

Using AI Code Generation

copy

Full Screen

1public enum Platform {2ANY, LINUX, WINDOWS, MAC, UNIX, SOLARIS, ANDROID, IOS;3}4public enum BrowserType {5FIREFOX("firefox"), 6CHROME("chrome"), 7IE("internet explorer"), 8EDGE("MicrosoftEdge"), 9SAFARI("safari"), 10IPHONE("iPhone"), 11IPAD("iPad"), 12ANDROID("android"), 13PHANTOMJS("phantomjs"), 14HTMLUNIT("htmlunit"), 15OPERA_BLINK("opera"), 16OPERA("operablink"), 17CHROME_HEADLESS("chromeheadless");18private final String browserName;19BrowserType(String browserName) {20this.browserName = browserName;21}22public String getBrowserName() {23return browserName;24}25}26public enum BrowserName {27CHROME_HEADLESS;28}29public enum BrowserName {30FIREFOX("firefox"), 31CHROME("chrome"), 32IE("internet explorer"), 33EDGE("MicrosoftEdge"), 34SAFARI("safari"), 35IPHONE("iPhone"), 36IPAD("iPad"), 37ANDROID("android"), 38PHANTOMJS("phantomjs"), 39HTMLUNIT("htmlunit"), 40OPERA_BLINK("opera"), 41OPERA("operablink"), 42CHROME_HEADLESS("chromeheadless");43private final String browserName;44BrowserName(String browserName) {45this.browserName = browserName;46}47public String getBrowserName() {48return browserName;49}50}51public enum BrowserName {52FIREFOX("firefox"), 53CHROME("chrome"), 54IE("internet explorer"), 55EDGE("MicrosoftEdge"), 56SAFARI("safari"), 57IPHONE("iPhone"), 58IPAD("iPad"), 59ANDROID("android"), 60PHANTOMJS("phantomjs"), 61HTMLUNIT("htmlunit"), 62OPERA_BLINK("opera"), 63OPERA("operablink"),

Full Screen

Full Screen

Enum Platform

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 java.net.URL;5import java.net.MalformedURLException;6public class DesiredCapabilitiesDemo {7 public static void main(String[] args) throws MalformedURLException {8 DesiredCapabilities cap = new DesiredCapabilities();9 cap.setBrowserName("chrome");10 cap.setPlatform(Platform.WINDOWS);11 System.out.println(driver.getTitle());12 driver.quit();13 }14}

Full Screen

Full Screen

Enum Platform

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.selenium.platform;2import org.openqa.selenium.Platform;3public class PlatformDemo {4 public static void main(String[] args) {5 Platform currentPlatform = Platform.getCurrent();6 System.out.println("Current platform is: " + currentPlatform);7 }8}9package com.automationrhapsody.selenium.platform;10import org.openqa.selenium.Platform;11public class PlatformDemo {12 public static void main(String[] args) {13 Platform currentPlatform = Platform.getCurrent();14 System.out.println("Current platform is: " + currentPlatform);15 }16}

Full Screen

Full Screen
copy
1import java.util.Map; 2import java.util.AbstractMap;3import java.util.AbstractMap.SimpleEntry;4
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 popular Stackoverflow questions on Enum-Platform

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful