List of usage examples for org.openqa.selenium.remote DesiredCapabilities DesiredCapabilities
public DesiredCapabilities(Capabilities... others)
From source file:com.cognifide.qa.bb.provider.selenium.webdriver.modifiers.capabilities.EnableProxy.java
License:Apache License
private DesiredCapabilities enableProxy(Capabilities capabilities) { DesiredCapabilities caps = new DesiredCapabilities(capabilities); try {/*from www .j a v a2 s . c om*/ InetAddress proxyInetAddress = InetAddress.getByName(proxyIp); BrowserMobProxy browserMobProxy = proxyController.startProxyServer(proxyInetAddress); Proxy seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxy, proxyInetAddress); caps.setCapability(CapabilityType.PROXY, seleniumProxy); } catch (UnknownHostException e) { throw new IllegalStateException(e); } return caps; }
From source file:com.ebay.spine.LinuxWebDriverVNCRenderer.java
License:Apache License
@Override public String renderSummary() { StringBuilder builder = new StringBuilder(); builder.append("<fieldset>").append("<legend>") .append("<img width='30' src='../resources/images/tux.png' style='vertical-align:middle;' title='" + proxy.getVm().getName() + "'/>") .append(proxy.getClass().getSimpleName()).append("</legend>"); builder.append("listening on ").append(proxy.getRemoteURL()); if (((WebRemoteProxy) proxy).isDown()) { builder.append("<b> (down)</b>"); }/*from w w w. j a v a 2 s.co m*/ builder.append("<br>"); if (proxy.getTimeOut() > 0) { int inSec = proxy.getTimeOut() / 1000; builder.append("test session time out after ").append(inSec).append(" sec.<br>"); } builder.append("test started / max before restart : " + proxy.getTotalTestStarted() + "/" + proxy.getMaxTestBeforeClean() + "<br>"); builder.append("Supports up to <b>").append(proxy.getMaxNumberOfConcurrentTestSessions()) .append("</b> concurrent tests from : </u><br>"); builder.append("<div id='browsers'>"); for (TestSlot slot : proxy.getTestSlots()) { TestSession session = slot.getSession(); builder.append("<a href='#' "); if (session != null) { builder.append(" class='vncCapable' hub='" + proxy.getRegistry().getHub().getHost() + "' pwd='" + proxy.getVncPassword() + "' ip='" + proxy.getRemoteURL().getHost() + "' display='" + session.getRequestedCapabilities().get("x") + "' "); builder.append(" title='").append(session.get("lastCommand")).append("' "); } else { builder.append(" title='").append(slot.getCapabilities()).append("' "); } builder.append(" >"); String icon = BrowserNameUtils.consoleIconName(new DesiredCapabilities(slot.getCapabilities()), registry); builder.append("<img src='../resources/images/" + icon + ".png' height='20px' "); if (session != null) { builder.append(" class='busy' >"); } else { builder.append(" class='free'>"); } builder.append(slot.getCapabilities().get("version")); builder.append("</a>"); } builder.append("</div>"); builder.append("</fieldset>"); return builder.toString(); }
From source file:com.ebay.spine.WindowsWebDriverVNCRenderer.java
License:Apache License
@Override public String renderSummary() { StringBuilder builder = new StringBuilder(); builder.append("<fieldset>").append("<legend>").append( "<img width='40' src='../resources/images/windows_logo.jpg' style='vertical-align:middle;' title='" + proxy.getVm().getName() + "'/>") .append(proxy.getClass().getSimpleName()).append("</legend>"); builder.append("listening on ").append(proxy.getRemoteURL()); if (((WebRemoteProxy) proxy).isDown()) { builder.append("<b> (down)</b>"); }//w w w . ja v a 2 s. com builder.append("<br>"); if (proxy.getTimeOut() > 0) { int inSec = proxy.getTimeOut() / 1000; builder.append("test session time out after ").append(inSec).append(" sec.<br>"); } builder.append("test started / max before restart : " + proxy.getTotalTestStarted() + "/" + proxy.getMaxTestBeforeClean() + "<br>"); builder.append("Supports up to <b>").append(proxy.getMaxNumberOfConcurrentTestSessions()) .append("</b> concurrent tests from : </u><br>"); builder.append("<div id='browsers'>"); for (TestSlot slot : proxy.getTestSlots()) { TestSession session = slot.getSession(); builder.append("<a href='#' "); if (session != null) { builder.append(" class='vncCapable' hub='" + proxy.getRegistry().getHub().getHost() + "' pwd='" + proxy.getVncPassword() + "' ip='" + proxy.getRemoteURL().getHost() + "' display='0' "); builder.append(" title='").append(session.get("lastCommand")).append("' "); } else { builder.append(" title='").append(slot.getCapabilities()).append("' "); } builder.append(" >"); String icon = BrowserNameUtils.consoleIconName(new DesiredCapabilities(slot.getCapabilities()), registry); builder.append("<img src='../resources/images/" + icon + ".png' height='20px' "); if (session != null) { builder.append(" class='busy' >"); } else { builder.append(" class='free'>"); } builder.append(slot.getCapabilities().get("version")); builder.append("</a>"); } builder.append("</div>"); builder.append("</fieldset>"); return builder.toString(); }
From source file:com.google.testing.web.Browser.java
License:Apache License
/** * Provisions and returns a new {@link WebDriver} session. * * @param capabilities Configuration of the browser. *//* w w w . j ava 2s .co m*/ public WebDriver newSession(Capabilities capabilities) { DesiredCapabilities desired = new DesiredCapabilities(capabilities); WebDriver driver = new Augmenter().augment(new RemoteWebDriver(constructUrl(address), desired)); return driver; }
From source file:com.griddynamics.cd.selenium.WebDriverFactory.java
License:Apache License
public WebDriver createDriver(Capabilities capabilities) { DesiredCapabilities finalCapabilities = new DesiredCapabilities(capabilities); finalCapabilities = withProxy(finalCapabilities); finalCapabilities = withChromeOptions(finalCapabilities); try {//w w w .ja v a2s. com RemoteWebDriver driver = new RemoteWebDriver(new URL(webDriverUrl), finalCapabilities); //otherwise it may fail from time to time because of performance/network glitches on the node driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); return driver; } catch (MalformedURLException e) { throw new IllegalArgumentException("Couldn't start WebDriver Session with: " + webDriverUrl, e); } }
From source file:com.mengge.AppiumDriver.java
License:Apache License
/** * @param originalCapabilities the given {@link Capabilities}. * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has * to be set up//ww w.j a va2s . c o m * @return {@link Capabilities} with changed mobile platform value */ protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities, String newPlatform) { DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities); dc.setCapability(MobileCapabilityType.PLATFORM_NAME, newPlatform); return dc; }
From source file:com.mgmtp.jfunk.web.CapabilitiesProvider.java
License:Apache License
@Override public Map<String, DesiredCapabilities> get() { Configuration config = configProvider.get(); Map<String, Map<String, List<JFunkCapability>>> capabilitiesMap = newHashMap(); for (Entry<String, String> entry : config.entrySet()) { String key = entry.getKey(); Matcher matcher = CAPABILITIES_PREFIX_PATTERN.matcher(key); if (matcher.find()) { String driverType = matcher.groupCount() == 1 && matcher.group(1) != null ? matcher.group(1) : "global"; String capabilityString = key.substring(matcher.end() + 1); int lastDotIndex = capabilityString.lastIndexOf('.'); String value = entry.getValue(); JFunkCapability capability;// ww w. j a v a 2s . c om if (lastDotIndex != -1) { JFunkCapabilityType type = JFunkCapabilityType.LIST; try { Integer.parseInt(capabilityString.substring(lastDotIndex + 1)); capabilityString = capabilityString.substring(0, lastDotIndex); } catch (NumberFormatException ex) { // not a list capability type = JFunkCapabilityType.STRING; } capability = new JFunkCapability(capabilityString, value, type); } else { capability = new JFunkCapability(capabilityString, value, JFunkCapabilityType.STRING); } Map<String, List<JFunkCapability>> map = capabilitiesMap.get(driverType); if (map == null) { map = newHashMapWithExpectedSize(5); capabilitiesMap.put(driverType, map); } List<JFunkCapability> list = map.get(capability.name); if (list == null) { list = newArrayListWithExpectedSize(1); map.put(capability.name, list); } list.add(capability); } } Map<String, List<JFunkCapability>> tmpGlobals = capabilitiesMap.remove("global"); final Map<String, Object> globalCapabilities = tmpGlobals == null ? ImmutableMap.<String, Object>of() : transformCapabilities(tmpGlobals); final Proxy proxy = createProxyFromConfig(config); // transform in to map of capabilities for each webdriver type final Map<String, DesiredCapabilities> byDriverTypeCapabilities = transformEntries(capabilitiesMap, new EntryTransformer<String, Map<String, List<JFunkCapability>>, DesiredCapabilities>() { @Override public DesiredCapabilities transformEntry(final String key, final Map<String, List<JFunkCapability>> value) { Map<String, Object> capabilities = newHashMap(globalCapabilities); Map<String, Object> transformedCapabilities = transformCapabilities(value); capabilities.putAll(transformedCapabilities); DesiredCapabilities result = new DesiredCapabilities(capabilities); if (proxy != null) { result.setCapability(CapabilityType.PROXY, proxy); } return result; } }); // wrap, so we get empty capabilities instead of nulls return new ForwardingMap<String, DesiredCapabilities>() { @Override protected Map<String, DesiredCapabilities> delegate() { return byDriverTypeCapabilities; } @Override public DesiredCapabilities get(final Object key) { DesiredCapabilities capabilities = super.get(key); if (capabilities == null) { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); if (proxy != null) { desiredCapabilities.setCapability(CapabilityType.PROXY, proxy); } capabilities = desiredCapabilities; } return capabilities; } }; }
From source file:com.rmn.qa.servlet.StatusServlet.java
License:Open Source License
private String getIcon(Map<String, Object> capabilities, RemoteProxy proxy) { return BrowserNameUtils.getConsoleIconPath(new DesiredCapabilities(capabilities), proxy.getRegistry()); }
From source file:com.saucelabs.sauce_ondemand.driver.SauceOnDemandSPIImpl.java
License:Open Source License
@Override public WebDriver createWebDriver(SeleniumFactory factory, String browserURL, DesiredCapabilities capabilities) { String uri = factory.getUri(); if (!uri.startsWith(SCHEME)) return null; // not ours uri = uri.substring(SCHEME.length()); if (!uri.startsWith("?")) throw new IllegalArgumentException("Missing '?':" + factory.getUri()); // massage parameter into JSON format Map<String, List<String>> paramMap = populateParameterMap(uri); DesiredCapabilities desiredCapabilities; if (hasParameter(paramMap, OS) && hasParameter(paramMap, BROWSER) && hasParameter(paramMap, BROWSER_VERSION)) { String browser = getFirstParameter(paramMap, BROWSER); desiredCapabilities = new DesiredCapabilities(capabilities); desiredCapabilities.setBrowserName(browser); desiredCapabilities.setVersion(getFirstParameter(paramMap, BROWSER_VERSION)); desiredCapabilities.setCapability(CapabilityType.PLATFORM, getFirstParameter(paramMap, OS)); if (browser.equals("firefox")) { setFirefoxProfile(paramMap, desiredCapabilities); }//w w w.j a v a 2s . c o m } else { //use Firefox as a default desiredCapabilities = capabilities; desiredCapabilities.merge(DesiredCapabilities.firefox()); setFirefoxProfile(paramMap, desiredCapabilities); } String host = readPropertyOrEnv(SELENIUM_HOST, DEFAULT_WEBDRIVER_HOST); String portAsString = readPropertyOrEnv(SELENIUM_PORT, null); if (portAsString == null || portAsString.equals("")) { portAsString = DEFAULT_WEBDRIVER_PORT; } try { WebDriver driver = new RemoteWebDriverImpl( new URL(MessageFormat.format("http://{2}:{3}@{0}:{1}/wd/hub", host, portAsString, getFirstParameter(paramMap, USERNAME), getFirstParameter(paramMap, ACCESS_KEY))), desiredCapabilities, new Credential(getFirstParameter(paramMap, USERNAME), getFirstParameter(paramMap, ACCESS_KEY)), getFirstParameter(paramMap, "job-name")); if (browserURL != null) { driver.get(browserURL); } return driver; } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL: " + factory.getUri(), e); } }
From source file:com.sebuilder.interpreter.webdriverfactory.Firefox.java
License:Apache License
/** * @param config Key/value pairs treated as required capabilities, with the exception of: * <ul>//www .ja va2s . c o m * <li>binary: path to Firefox binary to use</li> * <li>profile: path to Firefox profile to use</li> * </ul> * @return A FirefoxDriver. */ @Override public RemoteWebDriver make(HashMap<String, String> config) { FirefoxBinary fb = config.containsKey("binary") ? new FirefoxBinary(new File(config.get("binary"))) : new FirefoxBinary(); FirefoxProfile fp = config.containsKey("profile") ? new FirefoxProfile(new File(config.get("profile"))) : new FirefoxProfile(); HashMap<String, String> caps = new HashMap<String, String>(config); caps.remove("binary"); caps.remove("profile"); return new FirefoxDriver(fb, fp, new DesiredCapabilities(caps)); }