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

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

Source:CapabilityTypes.java Github

copy

Full Screen

...9import org.openqa.selenium.remote.BrowserType;10import org.openqa.selenium.remote.CapabilityType;11import org.openqa.selenium.remote.DesiredCapabilities;12import org.openqa.selenium.safari.SafariOptions;13import java.util.List;14import static com.github.toy.constructor.core.api.utils.SPIUtil.loadSPI;15import static java.lang.String.format;16import static java.util.Optional.ofNullable;17import static java.util.stream.Collectors.toList;18import static org.apache.commons.lang3.ArrayUtils.contains;19import static org.apache.commons.lang3.StringUtils.isBlank;20import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;21public enum CapabilityTypes implements PropertySupplier<Capabilities> {22 /**23 * Capabilities for the starting of {@link org.openqa.selenium.remote.RemoteWebDriver}24 */25 REMOTE("remote") {26 /**27 * Creates {@link Capabilities} with following properties:28 * <p>29 * <p>{@code web.driver.capability.browserName} to define browser. This is the necessary property</p>30 * <p>{@code web.driver.capability.platformName} to define name of a supported platform.31 * Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform</p>32 * <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are33 * {@code true} or {@code false}. By default js is enabled. This is not the necessary property.</p>34 * <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary35 * property.</p>36 * <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a37 * supplier.38 * @see CapabilitySupplier39 * @see AdditionalCapabilitiesFor </p>40 * </p>41 *42 * @return built {@link Capabilities}43 */44 @Override45 public Capabilities get() {46 if (CommonCapabilityProperties.BROWSER_NAME.get() == null ||47 isBlank(String.valueOf(CommonCapabilityProperties.BROWSER_NAME.get()))) {48 throw new IllegalArgumentException(format("The property %s should be defined",49 CommonCapabilityProperties.BROWSER_NAME.getPropertyName()));50 }51 return super.get();52 }53 },54 /**55 * Capabilities for the starting of {@link org.openqa.selenium.chrome.ChromeDriver}56 */57 CHROME("chrome") {58 /**59 * Creates {@link Capabilities} with following properties:60 * <p>61 * <p>{@code web.driver.capability.platformName} to define name of a supported platform.62 * Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform</p>63 * <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are64 * {@code true} or {@code false}. By default js is enabled. This is not the necessary property.</p>65 * <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary66 * property.</p>67 * <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a68 * supplier.69 * @see CapabilitySupplier70 * @see AdditionalCapabilitiesFor </p>71 * </p>72 *73 * @return built {@link ChromeOptions}74 */75 @Override76 public Capabilities get() {77 return new ChromeOptions().merge(super.get());78 }79 },80 /**81 * Capabilities for the starting of {@link org.openqa.selenium.edge.EdgeDriver}82 */83 EDGE("edge") {84 /**85 * Creates {@link Capabilities} with following properties:86 * <p>87 * <p>{@code web.driver.capability.platformName} to define name of a supported platform.88 * Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform</p>89 * <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are90 * {@code true} or {@code false}. By default js is enabled. This is not the necessary property.</p>91 * <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary92 * property.</p>93 * <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a94 * supplier.95 * @see CapabilitySupplier96 * @see AdditionalCapabilitiesFor </p>97 * </p>98 *99 * @return built {@link EdgeOptions}100 */101 @Override102 public Capabilities get() {103 return new EdgeOptions().merge(super.get());104 }105 },106 /**107 * Capabilities for the starting of {@link org.openqa.selenium.firefox.FirefoxDriver}108 */109 FIREFOX("firefox") {110 /**111 * Creates {@link Capabilities} with following properties:112 * <p>113 * <p>{@code web.driver.capability.platformName} to define name of a supported platform.114 * Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform</p>115 * <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are116 * {@code true} or {@code false}. By default js is enabled. This is not the necessary property.</p>117 * <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary118 * property.</p>119 * <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a120 * supplier.121 * @see CapabilitySupplier122 * @see AdditionalCapabilitiesFor </p>123 * </p>124 *125 * @return built {@link FirefoxOptions}126 */127 @Override128 public Capabilities get() {129 return new FirefoxOptions().merge(super.get());130 }131 },132 /**133 * Capabilities for the starting of {@link org.openqa.selenium.ie.InternetExplorerDriver}134 */135 IE("ie") {136 /**137 * Creates {@link Capabilities} with following properties:138 * <p>139 * <p>{@code web.driver.capability.platformName} to define name of a supported platform.140 * Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform</p>141 * <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are142 * {@code true} or {@code false}. By default js is enabled. This is not the necessary property.</p>143 * <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary144 * property.</p>145 * <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a146 * supplier.147 * @see CapabilitySupplier148 * @see AdditionalCapabilitiesFor </p>149 * </p>150 *151 * @return built {@link InternetExplorerOptions}152 */153 @Override154 public Capabilities get() {155 return new InternetExplorerOptions().merge(super.get());156 }157 },158 /**159 * Capabilities for the starting of {@link org.openqa.selenium.opera.OperaDriver}160 */161 OPERA("opera") {162 /**163 * Creates {@link Capabilities} with following properties:164 * <p>165 * <p>{@code web.driver.capability.platformName} to define name of a supported platform.166 * Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform</p>167 * <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are168 * {@code true} or {@code false}. By default js is enabled. This is not the necessary property.</p>169 * <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary170 * property.</p>171 * <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a172 * supplier.173 * @see CapabilitySupplier174 * @see AdditionalCapabilitiesFor </p>175 * </p>176 *177 * @return built {@link OperaOptions}178 */179 @Override180 public Capabilities get() {181 return new OperaOptions().merge(super.get());182 }183 },184 /**185 * Capabilities for the starting of {@link org.openqa.selenium.safari.SafariDriver}186 */187 SAFARI("safari") {188 /**189 * Creates {@link Capabilities} with following properties:190 * <p>191 * <p>{@code web.driver.capability.platformName} to define name of a supported platform.192 * Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform</p>193 * <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are194 * {@code true} or {@code false}. By default js is enabled. This is not the necessary property.</p>195 * <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary196 * property.</p>197 * <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a198 * supplier.199 * @see CapabilitySupplier200 * @see AdditionalCapabilitiesFor </p>201 * </p>202 *203 * @return built {@link SafariOptions}204 */205 @Override206 public Capabilities get() {207 return new SafariOptions().merge(super.get());208 }209 },210 /**211 * Creates {@link Capabilities} with following properties:212 * <p>213 * <p>{@code web.driver.capability.platformName} to define name of a supported platform.214 * Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform</p>215 * <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are216 * {@code true} or {@code false}. By default js is enabled. This is not the necessary property.</p>217 * <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary218 * property.</p>219 * <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a220 * supplier.221 * @see CapabilitySupplier222 * @see AdditionalCapabilitiesFor </p>223 * </p>224 *225 * @return built {@link Capabilities} for {@link org.openqa.selenium.phantomjs.PhantomJSDriver}226 */227 PHANTOM_JS("phantomJs") {228 @Override229 public Capabilities get() {230 DesiredCapabilities capabilities = new DesiredCapabilities().merge(super.get());231 capabilities.setCapability(BROWSER_NAME, BrowserType.PHANTOMJS);232 return capabilities;233 }234 };235 private static final String CAPABILITY_SUPPLIERS = "capability.suppliers";236 private final String name;237 CapabilityTypes(String name) {238 this.name = format("%s.%s", name, CAPABILITY_SUPPLIERS);239 }240 @Override241 public Capabilities get() {242 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();243 ofNullable(CommonCapabilityProperties.BROWSER_NAME.get()).ifPresent(o ->244 desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, o));245 ofNullable(CommonCapabilityProperties.PLATFORM_NAME.get()).ifPresent(o ->246 desiredCapabilities.setCapability(CapabilityType.PLATFORM_NAME, o));247 desiredCapabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT,248 CommonCapabilityProperties.SUPPORTS_JAVASCRIPT.get());249 ofNullable(CommonCapabilityProperties.BROWSER_VERSION.get()).ifPresent(o ->250 desiredCapabilities.setCapability(CapabilityType.BROWSER_VERSION, o));251 returnOptionalFromEnvironment()252 .map(s -> loadSPI(CapabilitySupplier.class)253 .stream().filter(capabilitySupplier -> {254 AdditionalCapabilitiesFor additionalCapabilitiesFor;255 return ((additionalCapabilitiesFor =256 capabilitySupplier.getClass().getAnnotation(AdditionalCapabilitiesFor.class)) != null257 && additionalCapabilitiesFor.type().equals(this)258 && contains(s.split(","), additionalCapabilitiesFor.supplierName().trim())259 );260 }).collect(toList()))261 .orElse(List.of()).forEach(capabilitySupplier -> desiredCapabilities.merge(capabilitySupplier.get()));262 return desiredCapabilities;263 }264 @Override265 public String getPropertyName() {266 return name;267 }268 public enum CommonCapabilityProperties implements PropertySupplier<Object> {269 /**270 * Reads property {@code web.driver.capability.browserName} and returns string value.271 * Should be the same as following:272 * <p>273 * <p>{@link BrowserType#CHROME}</p>274 * <p>{@link BrowserType#EDGE}</p>275 * <p>{@link BrowserType#FIREFOX}</p>276 * <p>{@link BrowserType#IEXPLORE}</p>277 * <p>{@link BrowserType#OPERA_BLINK}</p>278 * <p>{@link BrowserType#SAFARI}</p>279 * <p>{@link BrowserType#PHANTOMJS}</p>280 * </p>281 */282 BROWSER_NAME(format("web.driver.capability.%s", CapabilityType.BROWSER_NAME)),283 /**284 * Reads property {@code web.driver.capability.platformName} and returns string value.285 * Should be the same as an item of {@link org.openqa.selenium.Platform}286 */287 PLATFORM_NAME(format("web.driver.capability.%s", CapabilityType.PLATFORM_NAME)),288 /**289 * Reads property {@code web.driver.capability.javascriptEnabled} and returns boolean value.290 * Should be {@code true} or {@code false}. By default it returns {@code true}.291 */292 SUPPORTS_JAVASCRIPT(format("web.driver.capability.%s", CapabilityType.SUPPORTS_JAVASCRIPT)) {293 @Override294 public Boolean get() {295 return returnOptionalFromEnvironment().map(Boolean::parseBoolean).orElse(true);296 }297 },298 /**299 * Reads property {@code web.driver.capability.browserVersion} and returns string value.300 */301 BROWSER_VERSION(format("web.driver.capability.%s", CapabilityType.BROWSER_VERSION));302 private final String name;303 CommonCapabilityProperties(String name) {304 this.name = name;305 }306 @Override307 public String getPropertyName() {308 return name;309 }310 @Override311 public Object get() {312 return returnOptionalFromEnvironment().orElse(null);313 }314 }315}...

Full Screen

Full Screen

Source:DriverFactory.java Github

copy

Full Screen

...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 }...

Full Screen

Full Screen

Source:WebDriverType.java Github

copy

Full Screen

...4 * %%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:WebDriverFactory.java Github

copy

Full Screen

...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;...

Full Screen

Full Screen

Source:DriverSelector.java Github

copy

Full Screen

...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:StaticBrowserFactory.java Github

copy

Full Screen

...55 case EDGE:56 options = new EdgeOptions();57 break;58 }59 if (!version.isBlank()) {60 options.setCapability(CapabilityType.BROWSER_VERSION, version);61 }62 if (!platform.isBlank()) {63 options.setCapability(CapabilityType.PLATFORM_NAME, platform);64 }65 if (gridAddress != null) {66 browserObject = RemoteWebDriver.builder().oneOf(options).address(gridAddress).build();67 } else {68 browserObject = RemoteWebDriver.builder().oneOf(options).build();69 }70 return browserObject;71 }72}...

Full Screen

Full Screen

is

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.RemoteWebDriver;3import java.net.MalformedURLException;4import java.net.URL;5public class SeleniumGrid {6 public static void main(String[] args) throws MalformedURLException {7 DesiredCapabilities capabilities = new DesiredCapabilities();8 capabilities.setBrowserName("firefox");9 capabilities.setPlatform(Platform.WINDOWS);

Full Screen

Full Screen

is

Using AI Code Generation

copy

Full Screen

1if (Platform.getCurrent().is(Platform.LINUX)) {2}3if (Platform.getCurrent().is(Platform.LINUX)) {4}5if (Platform.getCurrent().is(Platform.LINUX)) {6}

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