Java Code Examples for org.openqa.selenium.remote.DesiredCapabilities#getCapability()
The following examples show how to use
org.openqa.selenium.remote.DesiredCapabilities#getCapability() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebDriverTypeTests.java From vividus with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static DesiredCapabilities testGetFirefoxWebDriver(WebDriverConfiguration configuration) throws Exception { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); FirefoxOptions firefoxOptions = new FirefoxOptions(); whenNew(FirefoxOptions.class).withArguments(desiredCapabilities).thenReturn(firefoxOptions); whenNew(FirefoxOptions.class).withNoArguments().thenReturn(firefoxOptions); FirefoxDriver expected = mock(FirefoxDriver.class); whenNew(FirefoxDriver.class).withParameterTypes(FirefoxOptions.class).withArguments(firefoxOptions) .thenReturn(expected); WebDriver actual = WebDriverType.FIREFOX.getWebDriver(desiredCapabilities, configuration); assertEquals(expected, actual); Map<String, Object> options = (Map<String, Object>) desiredCapabilities .getCapability(FirefoxOptions.FIREFOX_OPTIONS); Map<String, Object> prefs = (Map<String, Object>) options.get("prefs"); assertEquals("about:blank", prefs.get("startup.homepage_welcome_url.additional")); return desiredCapabilities; }
Example 2
Source File: WebDriverTypeTests.java From vividus with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static DesiredCapabilities testGetIExploreWebDriver(WebDriverConfiguration configuration) throws Exception { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions(); whenNew(InternetExplorerOptions.class).withArguments(desiredCapabilities).thenReturn(internetExplorerOptions); whenNew(InternetExplorerOptions.class).withNoArguments().thenReturn(internetExplorerOptions); InternetExplorerDriver expected = mock(InternetExplorerDriver.class); whenNew(InternetExplorerDriver.class) .withParameterTypes(InternetExplorerOptions.class) .withArguments(internetExplorerOptions) .thenReturn(expected); WebDriver actual = WebDriverType.IEXPLORE.getWebDriver(desiredCapabilities, configuration); assertEquals(expected, actual); Map<String, Object> options = (Map<String, Object>) desiredCapabilities.getCapability(IE_OPTIONS); assertTrue((boolean) options.get(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS)); return desiredCapabilities; }
Example 3
Source File: BrowserStackWebDriverBuilder.java From justtestlah with Apache License 2.0 | 6 votes |
@Override protected DesiredCapabilities addCommonCapabilities(DesiredCapabilities capabilities) { super.addCommonCapabilities(capabilities); Object app = capabilities.getCapability("app"); if (app == null) { throw new BrowserstackException("Property app must not be null"); } if (!app.toString().startsWith("bs://")) { uploadAppPackage(app.toString()); capabilities.setCapability("app", appUrl); } else { LOG.info("Using previously uploaded app package {}", app); } capabilities.setCapability("project", project); capabilities.setCapability("build", build); capabilities.setCapability("acceptSslCerts", acceptSslCerts); capabilities.setCapability("browserstack.debug", debug); capabilities.setCapability("browserstack.video", video); capabilities.setCapability("browserstack.geoLocation", geoLocation); capabilities.setCapability("browserstack.timezone", timezone); return capabilities; }
Example 4
Source File: Configuration.java From carina with Apache License 2.0 | 6 votes |
/** * Get platform name from configuration properties or DesiredCapabilities. * @param caps * DesiredCapabilities * @return String platform name */ public static String getPlatform(DesiredCapabilities caps) { // any platform by default String platform = "*"; // redefine platform if mobile.platformName is available if (!R.CONFIG.get(SpecialKeywords.PLATFORM).isEmpty()) { platform = R.CONFIG.get(SpecialKeywords.PLATFORM); } // redefine platform if mobile.platformName is available if (!R.CONFIG.get(SpecialKeywords.PLATFORM_NAME).isEmpty()) { platform = R.CONFIG.get(SpecialKeywords.PLATFORM_NAME); } if (caps != null && caps.getCapability("platform") != null) { platform = caps.getCapability("platform").toString(); } if (caps != null && caps.getCapability("platformName") != null) { platform = caps.getCapability("platformName").toString(); } //TODO: try to get actual platform name return platform; }
Example 5
Source File: DesktopFactory.java From carina with Apache License 2.0 | 6 votes |
/** * Sets browser window according to capabilites.resolution value, otherwise * maximizes window. * * @param driver - instance of desktop @WebDriver * @param capabilities - driver capabilities */ private void resizeBrowserWindow(WebDriver driver, DesiredCapabilities capabilities) { try { if (capabilities.getCapability("resolution") != null) { String resolution = (String) capabilities.getCapability("resolution"); int width = Integer.valueOf(resolution.split("x")[0]); int height = Integer.valueOf(resolution.split("x")[1]); driver.manage().window().setPosition(new Point(0, 0)); driver.manage().window().setSize(new Dimension(width, height)); LOGGER.info(String.format("Browser window size set to %dx%d", width, height)); } else { driver.manage().window().maximize(); LOGGER.info("Browser window was maximized"); } } catch (Exception e) { LOGGER.error("Unable to resize browser window", e); } }
Example 6
Source File: WebDriverTypeTests.java From vividus with Apache License 2.0 | 5 votes |
@Test @PrepareForTest(fullyQualifiedNames = "org.vividus.selenium.WebDriverType$2") @SuppressWarnings("unchecked") public void testGetIExploreWebDriverWithCommandLineArguments() throws Exception { String argument = "private"; WebDriverConfiguration configuration = new WebDriverConfiguration(); configuration.setCommandLineArguments(new String[] { argument }); DesiredCapabilities desiredCapabilities = testGetIExploreWebDriver(configuration); Map<String, Object> options = (Map<String, Object>) desiredCapabilities.getCapability(IE_OPTIONS); assertEquals(argument, options.get(InternetExplorerDriver.IE_SWITCHES)); }
Example 7
Source File: OperaCaps.java From Selenium-Foundation with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static String getCapabilities(SeleniumConfig config) { String binaryPath = config.getString(OPERA_BINARY); Objects.requireNonNull(binaryPath, "Path to Opera binary must be specified in setting [" + OPERA_BINARY + "]"); DesiredCapabilities caps = new DesiredCapabilities().merge(config.getCapabilitiesForJson(CAPABILITIES)[0]); Map<String, Object> options = (Map<String, Object>) caps.getCapability(OPTIONS_KEY); if (options == null) { options = new HashMap<>(); } options.put(BINARY_KEY, new File(binaryPath).getPath()); caps.setCapability(OPTIONS_KEY, options); return config.toJson(caps); }
Example 8
Source File: AppiumDriverManager.java From AppiumTestDistribution with GNU General Public License v3.0 | 5 votes |
private void addChromeDriverPathIfChromeOnDevice(DesiredCapabilities desiredCapabilities, String isChromDriverPath, boolean isPlatformAndroid) throws IOException { if (isPlatformAndroid && (null == isChromDriverPath)) { String udid = (String) desiredCapabilities.getCapability("udid"); String pathForChromDriverForDevice = getPathForChromeDriver(udid); if (null != pathForChromDriverForDevice) { desiredCapabilities.setCapability( AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, pathForChromDriverForDevice); } } }
Example 9
Source File: Configuration.java From carina with Apache License 2.0 | 5 votes |
public static String getDriverType(DesiredCapabilities capabilities) { if (capabilities == null) { // calculate driver type based on config.properties arguments return getDriverType(); } LOGGER.debug("Detecting driver_type by capabilities: " + capabilities); String platform = ""; if (capabilities.getCapability("platform") != null) { platform = capabilities.getCapability("platform").toString(); } if (capabilities.getCapability("platformName") != null) { platform = capabilities.getCapability("platformName").toString(); } if (SpecialKeywords.ANDROID.equalsIgnoreCase(platform) || SpecialKeywords.IOS.equalsIgnoreCase(platform) || SpecialKeywords.TVOS.equalsIgnoreCase(platform)) { LOGGER.debug("Detected MOBILE driver_type by platform: " + platform); return SpecialKeywords.MOBILE; } // handle use-case when we provide only uuid object among desired capabilities if (capabilities.getCapability("udid") != null) { LOGGER.debug("Detected MOBILE driver_type by uuid inside capabilities"); return SpecialKeywords.MOBILE; } LOGGER.debug("Return default DESKTOP driver_type"); return SpecialKeywords.DESKTOP; }
Example 10
Source File: CapabilitiesLoaderTest.java From carina with Apache License 2.0 | 5 votes |
@Test() public void getCapabilitiesTest() { DesiredCapabilities caps = new CapabilitiesLoader().getCapabilities(customCapabilities); String value = (String) caps.getCapability(stringParam); Assert.assertNotNull(value, "Unable to find '" + stringParam + "' capability!"); Assert.assertEquals(value, stringValue, "Returned capability value is not valid!"); Assert.assertTrue((Boolean) caps.getCapability(booleanParamTrue), "Returned capability value is not valid!"); Assert.assertFalse((Boolean) caps.getCapability(booleanParamFalse), "Returned capability value is not valid!"); // verify that param without "capabilities." prefix is not loaded here Assert.assertNull(caps.getCapability(coreParam), coreParam + " is present among capabilities mistakenly!"); }
Example 11
Source File: AppiumDriverManager.java From AppiumTestDistribution with GNU General Public License v3.0 | 4 votes |
@Synchronized private AppiumDriver<MobileElement> initialiseDriver( Optional<DesiredCapabilities> capabilities) throws Exception { AppiumDriver currentDriverSession; DesiredCapabilities desiredCapabilities = capabilities.get(); String isChromDriverPath = (String) desiredCapabilities.getCapability( AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE); boolean isPlatformAndroid = AppiumDeviceManager.getMobilePlatform().name() .equalsIgnoreCase("android"); addChromeDriverPathIfChromeOnDevice( desiredCapabilities, isChromDriverPath, isPlatformAndroid); LOGGER.info("Capabilities: " + desiredCapabilities.toString()); String remoteWDHubIP = getRemoteWDHubIP(); if (!AppiumDeviceManager.getAppiumDevice().getDevice().isCloud() && AppiumDeviceManager.getMobilePlatform().name().equalsIgnoreCase("iOS")) { currentDriverSession = new IOSDriver(new URL(remoteWDHubIP), desiredCapabilities); LOGGER.info("Session Created for iOS ---- " + currentDriverSession.getSessionId() + "---" + currentDriverSession.getSessionDetail("udid")); } else if (!AppiumDeviceManager.getAppiumDevice().getDevice().isCloud() && isPlatformAndroid) { currentDriverSession = new AndroidDriver(new URL(remoteWDHubIP), desiredCapabilities); LOGGER.info("Session Created for Android ---- " + currentDriverSession.getSessionId() + "---" + currentDriverSession.getSessionDetail("udid")); } else { currentDriverSession = new AppiumDriver<>(new URL(remoteWDHubIP), desiredCapabilities); LOGGER.info("Session Created ---- " + currentDriverSession.getSessionId() + "---" + currentDriverSession.getRemoteAddress().getHost() + "---" + currentDriverSession.getSessionDetail("udid")); } return currentDriverSession; }