Java 类org.openqa.selenium.remote.CapabilityType 实例源码

项目:spa-perf    文件:SPAPerfChromeDriver.java   
private static DesiredCapabilities getPerformanceLoggingCapabilities() {
    DesiredCapabilities caps = DesiredCapabilities.chrome();

    // Enable performance logging
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

    // Enable timeline tracing
    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    Map<String, String> perfLoggingPrefs = new HashMap<String, String>();
    // Tracing categories, please note NO SPACE NEEDED after the commas
    perfLoggingPrefs.put("traceCategories", "blink.console,disabled-by-default-devtools.timeline");
    chromeOptions.put("perfLoggingPrefs", perfLoggingPrefs);
    //chromeOptions.put("debuggerAddress", "127.0.0.1:10134");
    caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    return caps;
}
项目:NoraUi    文件:DriverFactory.java   
/**
 * Generates a phantomJs webdriver.
 *
 * @return
 *         A phantomJs webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generatePhantomJsDriver() throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.PHANTOMJS);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    logger.info("Generating Phantomjs driver ({}) ...", pathWebdriver);

    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "fr-FR");
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, pathWebdriver);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setJavascriptEnabled(true);

    setLoggingLevel(capabilities);

    // Proxy configuration
    String proxy = "";
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        proxy = Context.getProxy().getHttpProxy();
    }
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
            new String[] { "--proxy=" + proxy, "--web-security=no", "--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--webdriver-loglevel=NONE" });
    return new PhantomJSDriver(capabilities);
}
项目:NoraUi    文件:DriverFactory.java   
/**
 * Generates a htmlunit webdriver.
 *
 * @return
 *         A htmlunit webdriver
 */
private WebDriver generateHtmlUnitDriver() {
    logger.info("Generating HtmlUnit driver...");
    final DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    capabilities.setJavascriptEnabled(true);

    setLoggingLevel(capabilities);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }
    return new HtmlUnitDriver(capabilities);
}
项目:akita-testing-template    文件:AkitaChromeDriverProvider.java   
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    Map<String, Object> preferences = new Hashtable<>();
    preferences.put("profile.default_content_settings.popups", 0);
    preferences.put("download.prompt_for_download", "false");
    String downloadsPath = System.getProperty("user.home") + "/Downloads";
    preferences.put("download.default_directory", loadSystemPropertyOrDefault("fileDownloadPath", downloadsPath));
    preferences.put("plugins.plugins_disabled", new String[]{
            "Adobe Flash Player", "Chrome PDF Viewer"});
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", preferences);

    capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(capabilities);
}
项目:zucchini    文件:SeleniumDriver.java   
private static WebDriver createPhantomJSDriver(String driverPath) {

        DesiredCapabilities desiredCapabilities = DesiredCapabilities.phantomjs();
        desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, driverPath);
        desiredCapabilities.setCapability(CapabilityType.ELEMENT_SCROLL_BEHAVIOR, true);
        desiredCapabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
        desiredCapabilities.setCapability(CapabilityType.ENABLE_PROFILING_CAPABILITY, true);
        desiredCapabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, true);

        desiredCapabilities.setJavascriptEnabled(true);

        ArrayList<String> cliArgs = new ArrayList<String>();
        cliArgs.add("--web-security=true");
        cliArgs.add("--ignore-ssl-errors=true");
        desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs);

        return new PhantomJSDriver(desiredCapabilities);
    }
项目:AutomationFrameworkTPG    文件:DriverProperties.java   
private WebDriver initIEDriver(String appURL) {
    System.out.println("Launching IE browser..");
    DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
    ieCapabilities.setJavascriptEnabled(true); 
    ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,   
            true); 
    ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); 
    ieCapabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING,true);         
    ieCapabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.DISMISS); //Accept unexpected alerts 
    ieCapabilities.setCapability("requireWindowFocus", true); 
    ieCapabilities.setCapability("enablePersistentHover", false); 
    ieCapabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);

    WebDriver driver=new InternetExplorerDriver(ieCapabilities);
    driver.manage().deleteAllCookies();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    for(String winHandle : driver.getWindowHandles()){
       driver =  driver.switchTo().window(winHandle);
    }
    driver.get(appURL);
    return new WebDriverProxy().protect(driver);
}
项目:webtester2-core    文件:RemoteFactoryTest.java   
@Test
public void capabilitiesAreSetWhenCreatingBrowser() throws MalformedURLException {

    given(configuration.getRemoteBrowserName()).willReturn("firefox");
    given(configuration.getRemoteBrowserVersion()).willReturn("46.0.1");
    given(configuration.getRemoteFirefoxMarionette()).willReturn(true);
    given(configuration.getRemoteHost()).willReturn("localhost");
    given(configuration.getRemotePort()).willReturn(4444);

    cut.createBrowser();

    then(webDriverProducer).should().apply(urlCaptor.capture(), capabilitiesCaptor.capture());

    URL url = urlCaptor.getValue();
    assertThat(url).hasProtocol("http").hasHost("localhost").hasPort(4444).hasPath("/wd/hub");

    DesiredCapabilities capabilities = capabilitiesCaptor.getValue();
    assertThat(capabilities.getCapability(CapabilityType.BROWSER_NAME)).isEqualTo("firefox");
    assertThat(capabilities.getCapability(CapabilityType.VERSION)).isEqualTo("46.0.1");
    assertThat(capabilities.getCapability(CapabilityType.PLATFORM)).isEqualTo(Platform.ANY);
    assertThat(capabilities.getCapability(CapabilityType.HAS_NATIVE_EVENTS)).isEqualTo(false);
    assertThat(capabilities.getCapability(CapabilityType.ACCEPT_SSL_CERTS)).isEqualTo(true);
    assertThat(capabilities.getCapability("marionette")).isEqualTo(true);

}
项目:0686OS    文件:TestCommon.java   
@Before
public void setUp() throws Exception {
    Configuration.load();
    Configuration.print();

    System.setProperty("webdriver.gecko.driver", new File("drivers/geckodriver").getAbsolutePath());
    System.setProperty("webdriver.chrome.driver", new File("drivers/chromedriver").getAbsolutePath());

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(CapabilityType.BROWSER_NAME, "");
    cap.setCapability("platformVersion", Configuration.get("app_platformVersion"));
    cap.setCapability("platformName", "Android");
    cap.setCapability("app", new File(Configuration.get("app_path")).getAbsolutePath());
    cap.setCapability("deviceName", "Any");
    cap.setCapability("commandTimeout", "60");
    if (Configuration.platform().isWeb()) {
        Driver.add(Configuration.get("browser"), cap);
    } else {
        Driver.add(Configuration.get("driver_url"), Configuration.get("browser"), cap);
    }
    searchPage = PageFactory.init(SearchPage.class);
    searchPage.navigate();
}
项目:jscoverproxy-maven-plugin    文件:JSCoverProxyMavenMojo.java   
private WebDriver getWebClient(int portForJSCoverProxy) {
    Proxy proxy = new Proxy().setHttpProxy("localhost:" + portForJSCoverProxy);
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(CapabilityType.PROXY, proxy);
    caps.setJavascriptEnabled(true);
    caps.setBrowserName(BrowserType.HTMLUNIT);
    return new HtmlUnitDriver(caps) {
        @Override
        protected WebClient modifyWebClient(WebClient client) {
            client.setScriptPreProcessor((htmlPage, sourceCode, sourceName, lineNumber, htmlElement) -> {
                if(removeJsSnippets != null && !removeJsSnippets.isEmpty()) {
                    for(String toReplace : removeJsSnippets) {
                        sourceCode = sourceCode.replace(toReplace, "");
                    }
                    return sourceCode;
                } else {
                    return sourceCode;
                }

            });
            return client;
        }
    };
}
项目:aet    文件:FirefoxWebDriverFactory.java   
@Override
public WebCommunicationWrapper createWebDriver(ProxyServerWrapper proxyServer)
    throws WorkerException {
  try {
    Proxy proxy = proxyServer.seleniumProxy();
    proxyServer.setCaptureContent(true);
    proxyServer.setCaptureHeaders(true);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, proxy);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    FirefoxProfile fp = getFirefoxProfile();
    fp.setAcceptUntrustedCertificates(true);
    fp.setAssumeUntrustedCertificateIssuer(false);
    capabilities.setCapability(AetFirefoxDriver.PROFILE, fp);

    return new WebCommunicationWrapperImpl(getFirefoxDriver(fp, capabilities), proxyServer,
        requestExecutorFactory
            .createInstance());
  } catch (Exception e) {
    throw new WorkerException(e.getMessage(), e);
  }
}
项目:seleniumtestsframework    文件:IOsCapabilitiesFactory.java   
public DesiredCapabilities createCapabilities(final DriverConfig cfg) {
    final DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("automationName", cfg.getAutomationName());
    capabilities.setCapability("platformName", cfg.getMobilePlatformName());

    // Set up version and device name else appium server would pick the only available emulator/device
    // Both of these are ignored for android for now
    capabilities.setCapability("platformVersion", cfg.getMobilePlatformVersion());
    capabilities.setCapability("deviceName", cfg.getDeviceName());

    capabilities.setCapability("app", cfg.getApp());
    capabilities.setCapability("appPackage", cfg.getAppPackage());
    capabilities.setCapability("appActivity", cfg.getAppActivity());

    capabilities.setCapability(CapabilityType.BROWSER_NAME, cfg.getBrowserName());
    capabilities.setCapability("newCommandTimeout", cfg.getNewCommandTimeout());

    return capabilities;
}
项目:seleniumtestsframework    文件:IPhoneCapabilitiesFactory.java   
public DesiredCapabilities createCapabilities(final DriverConfig cfg) {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("automationName", cfg.getAutomationName());
    capabilities.setCapability("platformName", cfg.getMobilePlatformName());

    // Set up version and device name else appium server would pick the only available emulator/device
    // Both of these are ignored for android for now
    capabilities.setCapability("platformVersion", cfg.getMobilePlatformVersion());
    capabilities.setCapability("deviceName", cfg.getDeviceName());

    capabilities.setCapability("app", cfg.getApp());
    capabilities.setCapability("appPackage", cfg.getAppPackage());
    capabilities.setCapability("appActivity", cfg.getAppActivity());

    capabilities.setCapability(CapabilityType.BROWSER_NAME, cfg.getBrowserName());
    capabilities.setCapability("newCommandTimeout", cfg.getNewCommandTimeout());

    return capabilities;
}
项目:seleniumtestsframework    文件:AndroidCapabilitiesFactory.java   
public DesiredCapabilities createCapabilities(final DriverConfig cfg) {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("automationName", cfg.getAutomationName());
    capabilities.setCapability("platformName", cfg.getMobilePlatformName());

    // Set up version and device name else appium server would pick the only available emulator/device
    // Both of these are ignored for android for now
    capabilities.setCapability("platformVersion", cfg.getMobilePlatformVersion());
    capabilities.setCapability("deviceName", cfg.getDeviceName());

    capabilities.setCapability("app", cfg.getApp());
    capabilities.setCapability("appPackage", cfg.getAppPackage());
    capabilities.setCapability("appActivity", cfg.getAppActivity());

    capabilities.setCapability(CapabilityType.BROWSER_NAME, cfg.getBrowserName());
    capabilities.setCapability("newCommandTimeout", cfg.getNewCommandTimeout());

    return capabilities;
}
项目:Appium-Grid-For-Android    文件:BaseTest.java   
public void createDriver(){
    try {
        port = appiumMan.startAppium();             // Start appium server            

        // create appium driver instance
        DesiredCapabilities capabilities = DesiredCapabilities.android();
        capabilities.setCapability("deviceName", deviceName);
        capabilities.setCapability("platformName", "android");
        capabilities.setCapability(CapabilityType.VERSION, osVersion);
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
        capabilities.setCapability("udid", deviceId);

        this.driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"),capabilities);
    }
    catch(Exception e){
        e.printStackTrace();
    }
}
项目:Appium-Grid-For-Android    文件:BaseTest.java   
public void createDriver(String appPath){
    try {
        port = appiumMan.startAppium();             // Start appium server            

        // create appium driver instance
        DesiredCapabilities capabilities = DesiredCapabilities.android();
        capabilities.setCapability("deviceName", deviceName);
        capabilities.setCapability("platformName", "android");
        capabilities.setCapability(CapabilityType.VERSION, osVersion);
        capabilities.setCapability("app", appPath);
        capabilities.setCapability("udid", deviceId);

        this.driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"),capabilities);
    }
    catch(Exception e){
        e.printStackTrace();
    }
}
项目:AndroidRobot    文件:ChromeDriverClient.java   
public void createDriver(String pkg_name, String sn) {
        if(this.driver == null) {
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.setExperimentalOption("androidPackage", pkg_name);
    //        chromeOptions.setExperimentalOption("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin");
    //        chromeOptions.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
            chromeOptions.setExperimentalOption("androidUseRunningApp", true);
            chromeOptions.setExperimentalOption("androidDeviceSerial", sn);
    //        Map<String, Object> chromeOptions = new HashMap<String, Object>();
    //        chromeOptions.put("androidPackage", "com.eg.android.AlipayGphoneRC");
    //        chromeOptions.put("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            LoggingPreferences logPrefs = new LoggingPreferences();
            logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
            capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
            capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
//          capabilities.setCapability(CapabilityType., value);
            if(ChromeService.getService() != null)
                driver = new RobotRemoteWebDriver(ChromeService.getService().getUrl(), capabilities);
        }
    }
项目:grid-refactor-remote-server    文件:NewSession.java   
@Override
public Response handle() throws Exception {
  // Handle the case where the client does not send any desired capabilities.
  sessionId = allSessions.newSession(desiredCapabilities != null
                                     ? desiredCapabilities : new DesiredCapabilities());

  Map<String, Object> capabilities =
      Maps.newHashMap(allSessions.get(sessionId).getCapabilities().asMap());

  // Only servers implementing the server-side webdriver-backed selenium need
  // to return this particular value
  capabilities.put("webdriver.remote.sessionid", sessionId.toString());

  if (desiredCapabilities != null) {
    LoggingManager.perSessionLogHandler().configureLogging(
        (LoggingPreferences)desiredCapabilities.getCapability(CapabilityType.LOGGING_PREFS));
  }
  LoggingManager.perSessionLogHandler().attachToCurrentThread(sessionId);

  Response response = new Response();
  response.setSessionId(sessionId.toString());
  response.setValue(capabilities);
  return response;
}
项目:AppiumSauce    文件:ParallelBrowserTest.java   
/**
 * Constructs a new {@link org.openqa.selenium.remote.RemoteWebDriver} instance which is configured to use the capabilities defined by the {@link #browser},
 * {@link #version} and {@link #os} instance variables, and which is configured to run against ondemand.saucelabs.com, using
 * the username and access key populated by the {@link #authentication} instance.
 *
 * @throws Exception if an error occurs during the creation of the {@link org.openqa.selenium.remote.RemoteWebDriver} instance.
 */
@Before
public void setUp() throws Exception {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, browser);
    if (version != null) {
        capabilities.setCapability(CapabilityType.VERSION, version);
    }
    capabilities.setCapability(CapabilityType.PLATFORM, os);
    capabilities.setCapability("name", "Sauce Sample Test");
    this.driver = new RemoteWebDriver(new URL("http://" + SAUCE_USERNAME + ":" + SAUCE_KEY + "@ondemand.saucelabs.com:80/wd/hub")
            ,capabilities);
    this.sessionId = (((RemoteWebDriver) driver).getSessionId()).toString();

}
项目:seauto    文件:AbstractConfigurableDriverProvider.java   
/**
 * Best found default capabilities for Internet Explorer
 * 
 * @return {@link DesiredCapabilities}
 */
protected DesiredCapabilities getInternetExplorerCapabilities()
{
  final DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();

  // get past certificate security warning pages
  capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

  // setup native events and window focus
  // http://jimevansmusic.blogspot.com/2012/06/whats-wrong-with-internet-explorer.html
  capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true);
  capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);

  // don't accept alerts automatically
  capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, false);

  return capabilities;
}
项目:AndroidAppsTestAutomationSamples    文件:AddCustomerTest.java   
@Before
public void setUp() throws Exception {
    // このテストに必要なdesired capabilitiesを構築し、それに基づいたAndroidDriverインスタンスを生成する。
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
    // Selendroidモードで動作させるときには、AUTOMATION_NAMEを"Selendroid"にする。
    capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Selendroid");
    capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "com.nowsprinting.hellotesting.appium");
    capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.nowsprinting.hellotesting.app.CustomerListActivity");
    capabilities.setCapability("unicodeKeyboard", true);
    capabilities.setCapability("resetKeyboard", true);
    mDriver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    // デフォルトのタイムアウト値を80秒とする。
    mDriver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
项目:SeleniumGridScaler    文件:AutomationRunRequest.java   
/**
 * Returns true if this run request matches the capabilities passed in.  Includes browser, browser version, and OS
 * @param capabilities
 * @return
 */
public boolean matchesCapabilities(Map<String,Object> capabilities) {
    String capabilityBrowser = (String)capabilities.get(CapabilityType.BROWSER_NAME);
    String capabilityBrowserVersion = (String)capabilities.get(CapabilityType.VERSION);
    String capabilityOs = (String)capabilities.get(CapabilityType.PLATFORM);
    if(!AutomationUtils.lowerCaseMatch(browser, capabilityBrowser)) {
        return false;
    }
    if(browserVersion != null && !AutomationUtils.lowerCaseMatch(browserVersion,capabilityBrowserVersion))  {
        return false;
    }
    if(os != null && !AutomationUtils.lowerCaseMatch(os, capabilityOs)) {
        // If either OS has 'ANY' for the platform, that means it should be a match regardless and we don't have to count this as a non-match
        if(!AutomationUtils.lowerCaseMatch(os,"any") && !AutomationUtils.lowerCaseMatch(capabilityOs,"any")) {
            return false;
        }
    }
    return true;
}
项目:SeleniumGridScaler    文件:AutomationRequestMatcherTest.java   
@Test
// Tests that a node in the Expired state is not considered as a free resource
public void testRequestNodeExpiredState() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),10);
    node.updateStatus(AutomationDynamicNode.STATUS.EXPIRED);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID, nodeId);
    proxy.setConfig(config);
    List<TestSlot> testSlots = new ArrayList<TestSlot>();
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,browser);
    testSlots.add(new TestSlot(proxy, SeleniumProtocol.WebDriver, null, capabilities));
    proxy.setTestSlots(testSlots);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    AutomationRequestMatcher requestMatcher = new AutomationRequestMatcher();
    int freeThreads = requestMatcher.getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("Thread count should be correct due to an expired node", 0, freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRequestMatcherTest.java   
@Test
// Tests that a node in the Terminated state without an instance id is still considered a valid resource
public void testRequestNodeTerminatedNoInstanceId() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),10);
    node.updateStatus(AutomationDynamicNode.STATUS.TERMINATED);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    proxy.setMaxNumberOfConcurrentTestSessions(5);
    Map<String,Object> config = new HashMap<>();
    proxy.setConfig(config);
    List<TestSlot> testSlots = new ArrayList<TestSlot>();
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,browser);
    testSlots.add(new TestSlot(proxy, SeleniumProtocol.WebDriver, null, capabilities));
    proxy.setTestSlots(testSlots);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    AutomationRequestMatcher requestMatcher = new AutomationRequestMatcher();
    int freeThreads = requestMatcher.getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("Node should be available since instance id was not on the node", 1, freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRequestMatcherTest.java   
@Test
// Happy path that browsers matching shows correct free node count
 public void testRequestMatchingBrowsers() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(50);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,browser);
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));

    Assert.assertEquals("Thread count should be correct due to matching browser", 10, freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRequestMatcherTest.java   
@Test
// Test that non-matching browsers do not contribute to the free node count
public void testRequestNonMatchingBrowsers() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(50);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,"doesntMatch");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));

    Assert.assertEquals("Thread count should be correct due to matching OS", 0, freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRequestMatcherTest.java   
@Test
// Makes sure that all matching slots will be included to match
public void testRequestAllTestSlotsIncluded() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(10);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,"firefox");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("There should be no matching threads since the node limit was reached",10,freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRequestMatcherTest.java   
@Test
// Tests that the correct number of slots match even when the max session config on node is less than
// the slot number
public void testRequestAllTestSlotsIncludedGreaterNodeLimit() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(15);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,"firefox");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("There should be no matching threads since the node limit was reached",10,freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRequestMatcherTest.java   
@Test
// Tests that the correct number of slots match even when the max session config on node is greater than
// the slot number
public void testRequestAllTestSlotsIncludedLessThanNodeLimit() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(5);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID,nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,"firefox");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("There should be no matching threads since the node limit was reached",5,freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRequestMatcherTest.java   
@Test
// Test to make sure an in progress counts against the free node count
public void testRequestNewRunNotStarted() throws IOException, ServletException{
    String browser = "firefox";
    String nodeId = "nodeId";
    // Add a node that is not running to make sure its not included in the available calculation
    AutomationDynamicNode node = new AutomationDynamicNode("testUuid",nodeId,null,null,new Date(),50);
    AutomationContext.getContext().addNode(node);
    String runId = "runId";
    AutomationContext.getContext().addRun(new AutomationRunRequest(runId,10,"firefox"));
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setMaxNumberOfConcurrentTestSessions(50);
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> config = new HashMap<String, Object>();
    config.put(AutomationConstants.INSTANCE_ID, nodeId);
    proxy.setConfig(config);
    Map<String,Object> capabilities = new HashMap<String,Object>();
    capabilities.put(CapabilityType.BROWSER_NAME,"firefox");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    proxy.setMultipleTestSlots(testSlot, 10);
    proxySet.add(proxy);
    AutomationContext.getContext().setTotalNodeCount(50);
    int freeThreads = new AutomationRequestMatcher().getNumFreeThreadsForParameters(proxySet,new AutomationRunRequest(browser));
    Assert.assertEquals("No nodes should be free since existing run hasn't started",0,freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRunContextTest.java   
@Test
// Tests that the correct node count is returned when tests don't have a UUID
public void testNodesFreeNoUuid() {
    AutomationRunContext runContext = new AutomationRunContext();
    runContext.setTotalNodeCount(10);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> capabilities = new HashMap<>();
    capabilities.put(CapabilityType.PLATFORM,"linux");
    capabilities.put(CapabilityType.BROWSER_NAME,"chrome");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    testSlot.getNewSession(capabilities);
    proxy.setMultipleTestSlots(testSlot,5);
    proxySet.add(proxy);
    int freeThreads = runContext.getTotalThreadsAvailable(proxySet);
    Assert.assertEquals(5,freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRunContextTest.java   
@Test
// Tests that the correct node count is returned when tests don't have a UUID
public void testNodesFreeWithUuid() {
    AutomationRunContext runContext = new AutomationRunContext();
    runContext.setTotalNodeCount(10);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> capabilities = new HashMap<>();
    capabilities.put(CapabilityType.PLATFORM,"linux");
    capabilities.put(CapabilityType.BROWSER_NAME,"chrome");
    capabilities.put(AutomationConstants.UUID,"testUuid");
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    testSlot.getNewSession(capabilities);
    proxy.setMultipleTestSlots(testSlot,5);
    proxySet.add(proxy);
    int freeThreads = runContext.getTotalThreadsAvailable(proxySet);
    Assert.assertEquals(5,freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRunContextTest.java   
@Test
// Tests that a new run is counted instead of tests in progress
public void testNewRunIsCounted() {
    String uuid = "testUuid";
    AutomationRunContext runContext = new AutomationRunContext();
    runContext.setTotalNodeCount(10);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> capabilities = new HashMap<>();
    capabilities.put(CapabilityType.PLATFORM,"linux");
    capabilities.put(CapabilityType.BROWSER_NAME,"chrome");
    capabilities.put(AutomationConstants.UUID,uuid);
    AutomationRunRequest request = new AutomationRunRequest(uuid,10,"chrome");
    runContext.addRun(request);
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    testSlot.getNewSession(capabilities);
    proxy.setMultipleTestSlots(testSlot,5);
    proxySet.add(proxy);
    int freeThreads = runContext.getTotalThreadsAvailable(proxySet);
    Assert.assertEquals(0,freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRunContextTest.java   
@Test
// Tests that for an old run, the in progress tests are counted
public void testOldRunInProgress() {
    String uuid = "testUuid";
    AutomationRunContext runContext = new AutomationRunContext();
    runContext.setTotalNodeCount(10);
    ProxySet proxySet = new ProxySet(false);
    MockRemoteProxy proxy = new MockRemoteProxy();
    proxy.setCapabilityMatcher(new AutomationCapabilityMatcher());
    Map<String,Object> capabilities = new HashMap<>();
    capabilities.put(CapabilityType.PLATFORM,"linux");
    capabilities.put(CapabilityType.BROWSER_NAME,"chrome");
    capabilities.put(AutomationConstants.UUID,uuid);
    AutomationRunRequest request = new AutomationRunRequest(uuid,10,"chrome","23","linux", AutomationUtils.modifyDate(new Date(),-5,Calendar.MINUTE));
    runContext.addRun(request);
    TestSlot testSlot = new TestSlot(proxy, SeleniumProtocol.WebDriver,null,capabilities);
    testSlot.getNewSession(capabilities);
    int inProgressTests = 5;
    proxy.setMultipleTestSlots(testSlot,inProgressTests);
    proxySet.add(proxy);
    int freeThreads = runContext.getTotalThreadsAvailable(proxySet);
    Assert.assertEquals("Free threads should reflect in progress test count",inProgressTests,freeThreads);
}
项目:SeleniumGridScaler    文件:AutomationRunRequestTest.java   
@Test
// Tests that a platform of 'ANY' matches another otherwise non-matching OS
public void testOsMatchesAnyRequests() {
    String uuid = "testUuid";
    String browser = "firefox";
    String browserVersion = "25";
    String os = "ANY";
    Map<String,Object> map = new HashMap<>();
    map.put(CapabilityType.BROWSER_NAME,browser);
    map.put(CapabilityType.VERSION,browserVersion);
    map.put(CapabilityType.PLATFORM,os);
    AutomationRunRequest first = new AutomationRunRequest(uuid,null,browser,browserVersion,"linux");
    AutomationRunRequest second = AutomationRunRequest.requestFromCapabilities(map);
    Assert.assertTrue("Requests should be equal", first.matchesCapabilities(second));
    Assert.assertTrue("Requests should be equal", second.matchesCapabilities(first));
}
项目:seletest    文件:ConfigurationDriver.java   
/**
 * android capabilities bean
 * @param appPath String path to apk stored
 * @param appActivity String activity to launch
 * @param appPackage String package of app
 * @param autolaunch String autolaunch specifies if application will be autolaunched or not
 * @return DesiredCapabilities
 */
@Bean
@Lazy(true)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public DesiredCapabilities androidcapabilities(String appPath, String appActivity, String appPackage, String autolaunch){
    File app=new File(appPath);
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PLATFORM, MobilePlatform.ANDROID);
    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "300");//how long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session
    capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
    capabilities.setCapability("autoLaunch", Boolean.parseBoolean(autolaunch));
    capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY,appActivity);
    capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, appPackage);
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator");
    return capabilities;
}
项目:seletest    文件:ConfigurationDriver.java   
/**
 * iOS capabilities bean
 * @param appPath String path to app or ipa stored
 * @param udid String udid of the device
 * @param bundleId String bundleid is the package name in iOS
 * @param autolaunch String autolaunch specifies if application will be autolaunched or not
 * @return DesiredCapabilities
 */
@Bean
@Lazy(true)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public DesiredCapabilities iOScapabilities(String appPath, String udid, String bundleId, String autolaunch){
    File app=new File(appPath);
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PLATFORM, MobilePlatform.IOS);
    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "300");//how long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session
    capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
    capabilities.setCapability("autoLaunch", Boolean.parseBoolean(autolaunch));
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
    capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, bundleId);
    capabilities.setCapability("udid", udid);
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator");
    return capabilities;
}
项目:candybean    文件:AppiumAndroidTest.java   
@Before
public void setUp() throws Exception {
    // set up appium
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
    capabilities.setCapability(CapabilityType.VERSION, "4.2.2");

    capabilities.setCapability("device", "Android");
    capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
    capabilities.setCapability("app", "https://s3.amazonaws.com/voodoo2/TestApp.apk.zip");
    capabilities.setCapability("app-package", "com.example.TestApp");
    capabilities.setCapability("app-activity", "MyActivity");

    driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    values = new ArrayList<>();
}
项目:candybean    文件:SugarAndroidTest.java   
@Before
public void setUp() throws Exception {
    // set up appium
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Selendroid");

    capabilities.setCapability(CapabilityType.VERSION, "4.2.2");

    capabilities.setCapability("device", "Android");
    capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
    capabilities.setCapability("app", "https://s3.amazonaws.com/voodoo2/SugarCRM.apk.zip");
    capabilities.setCapability("app-package", "com.sugarcrm.nomad");
    capabilities.setCapability("app-activity", "NomadActivity");

    driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    values = new ArrayList<>();
}