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

项目:Cognizant-Intelligent-Test-Scripter    文件:RemoteProxy.java   
public static HttpCommandExecutor getProxyExecutor(URL url, Properties prop) {

        prop = decrypt(prop);

        String proxyHost = prop.getProperty("proxyHost");
        int proxyPort = Integer.valueOf(prop.getProperty("proxyPort"));
        String proxyUserDomain = prop.getProperty("proxyUserDomain");
        String proxyUser = prop.getProperty("proxyUser");
        String proxyPassword = prop.getProperty("proxyPassword");

        HttpClientBuilder builder = HttpClientBuilder.create();
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();

        credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
                new NTCredentials(proxyUser, proxyPassword, getWorkstation(), proxyUserDomain));
        if (url.getUserInfo() != null && !url.getUserInfo().isEmpty()) {
            credsProvider.setCredentials(new AuthScope(url.getHost(), (url.getPort() > 0 ? url.getPort() : url.getDefaultPort())),
                    new UsernamePasswordCredentials(proxyUser, proxyPassword));
        }
        builder.setProxy(proxy);
        builder.setDefaultCredentialsProvider(credsProvider);
        HttpClient.Factory factory = new SimpleHttpClientFactory(builder);
        return new HttpCommandExecutor(new HashMap<String, CommandInfo>(), url, factory);

    }
项目:jspider    文件:WebDriverFactory.java   
public WebDriverEx createWebDriver(DriverService driverService,
                                      DesiredCapabilities desiredCapabilities,
                                      SiteConfig siteConfig,
                                      DriverConfig driverConfig) throws IOException {
    driverService.start();

    //自定义HttpClientFactory用于设置命令超时时间
    ApacheHttpClient.Factory httpClientFactory = createHttpClientFactory(siteConfig, driverConfig);
    HttpCommandExecutor httpCommandExecutor = new HttpCommandExecutor(
            ImmutableMap.<String, CommandInfo>of(), driverService.getUrl(), httpClientFactory);
    WebDriverEx webDriver = new WebDriverEx(httpCommandExecutor, desiredCapabilities);
    webDriver.setDriverService(driverService);
    webDriver.setCreatedTime(new Date());

    webDriver.manage().timeouts().implicitlyWait(driverConfig.getImplicitlyWait(), TimeUnit.MILLISECONDS);
    webDriver.manage().timeouts().pageLoadTimeout(driverConfig.getPageLoadTimeout(), TimeUnit.MILLISECONDS);
    webDriver.manage().timeouts().setScriptTimeout(driverConfig.getScriptTimeout(), TimeUnit.MILLISECONDS);

    return webDriver;
}
项目:menggeqa    文件:AppiumCommandExecutor.java   
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
    URL addressOfRemoteServer, HttpClient.Factory httpClientFactory) {
    super(additionalCommands, addressOfRemoteServer, httpClientFactory);
    service = null;
}
项目:menggeqa    文件:AppiumCommandExecutor.java   
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverService service,
    HttpClient.Factory httpClientFactory) {
    super(additionalCommands, service.getUrl(), httpClientFactory);
    this.service = service;
}
项目:menggeqa    文件:AppiumCommandExecutor.java   
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
    URL addressOfRemoteServer) {
    this(additionalCommands, addressOfRemoteServer, new ApacheHttpClient.Factory());
}
项目:menggeqa    文件:AppiumCommandExecutor.java   
public AppiumCommandExecutor(Map<String, CommandInfo> additionalCommands,
    DriverService service) {
    this(additionalCommands, service, new ApacheHttpClient.Factory());
}
项目:menggeqa    文件:MobileCommand.java   
private static Map<String, CommandInfo> createCommandRepository() {
    HashMap<String, CommandInfo> result = new HashMap<String, CommandInfo>();
    result.put(RESET, postC("/session/:sessionId/appium/app/reset"));
    result.put(GET_STRINGS, postC("/session/:sessionId/appium/app/strings"));
    result.put(SET_VALUE, postC("/session/:sessionId/appium/element/:id/value"));
    result.put(PULL_FILE, postC("/session/:sessionId/appium/device/pull_file"));
    result.put(PULL_FOLDER, postC("/session/:sessionId/appium/device/pull_folder"));
    result.put(HIDE_KEYBOARD, postC("/session/:sessionId/appium/device/hide_keyboard"));
    result.put(RUN_APP_IN_BACKGROUND, postC("/session/:sessionId/appium/app/background"));
    result.put(PERFORM_TOUCH_ACTION, postC("/session/:sessionId/touch/perform"));
    result.put(PERFORM_MULTI_TOUCH, postC("/session/:sessionId/touch/multi/perform"));
    result.put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed"));
    result.put(INSTALL_APP, postC("/session/:sessionId/appium/device/install_app"));
    result.put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app"));
    result.put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch"));
    result.put(CLOSE_APP, postC("/session/:sessionId/appium/app/close"));
    result.put(LOCK, postC("/session/:sessionId/appium/device/lock"));
    result.put(COMPLEX_FIND, postC("/session/:sessionId/appium/app/complex_find"));
    result.put(GET_SETTINGS, getC("/session/:sessionId/appium/settings"));
    result.put(SET_SETTINGS, postC("/session/:sessionId/appium/settings"));
    result.put(GET_DEVICE_TIME, getC("/session/:sessionId/appium/device/system_time"));
    result.put(GET_SESSION,getC("/session/:sessionId/"));
    //iOS
    result.put(SHAKE, postC("/session/:sessionId/appium/device/shake"));
    //Android
    result.put(CURRENT_ACTIVITY,
        getC("/session/:sessionId/appium/device/current_activity"));
    result.put(END_TEST_COVERAGE,
        postC("/session/:sessionId/appium/app/end_test_coverage"));
    result.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection"));
    result.put(IS_LOCKED, postC("/session/:sessionId/appium/device/is_locked"));
    result.put(LONG_PRESS_KEY_CODE,
        postC("/session/:sessionId/appium/device/long_press_keycode"));
    result.put(OPEN_NOTIFICATIONS,
        postC("/session/:sessionId/appium/device/open_notifications"));
    result.put(PRESS_KEY_CODE,
        postC("/session/:sessionId/appium/device/press_keycode"));
    result.put(PUSH_FILE, postC("/session/:sessionId/appium/device/push_file"));
    result.put(SET_NETWORK_CONNECTION,
        postC("/session/:sessionId/network_connection"));
    result.put(START_ACTIVITY,
        postC("/session/:sessionId/appium/device/start_activity"));
    result.put(TOGGLE_LOCATION_SERVICES,
        postC("/session/:sessionId/appium/device/toggle_location_services"));
    result.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock"));
    result.put(REPLACE_VALUE, postC("/session/:sessionId/appium/element/:id/replace_value"));
    return result;
}
项目:SiteGenesis-Community-TestSuite    文件:AnnotationRunnerHelper.java   
/**
 * Returns an {@link URL} to a Selenium grid (e.g. SauceLabs) that contains basic authentication for access
 * 
 * @return {@link URL} to Selenium grid augmented with credentials
 * @throws MalformedURLException
 */
public static HttpCommandExecutor createGridExecutor(ProxyConfigurationDto proxyConfig, URL gridUrl, String gridUsername,
                                                     String gridPassword) throws MalformedURLException
{
    // create a configuration for accessing target site via proxy (if a proxy is defined)
    // the proxy and the destination site will have different or no credentials for accessing them
    // so we need to create different authentication scopes and link them with the credentials
    BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();

    // create credentials for proxy access
    if (proxyConfig != null //
    && !StringUtils.isEmpty(proxyConfig.getUsername()) //
    && !StringUtils.isEmpty(proxyConfig.getPassword()))
    {
        AuthScope proxyAuth = new AuthScope(proxyConfig.getHost(), Integer.valueOf(proxyConfig.getPort()));
        Credentials proxyCredentials = new UsernamePasswordCredentials(proxyConfig.getUsername(), proxyConfig.getPassword());
        basicCredentialsProvider.setCredentials(proxyAuth, proxyCredentials);
    }

    // create credentials for target website
    AuthScope gridAuth = new AuthScope(gridUrl.getHost(), gridUrl.getPort());

    if (!StringUtils.isEmpty(gridUsername))
    {
        Credentials gridCredentials = new UsernamePasswordCredentials(gridUsername, gridPassword);
        basicCredentialsProvider.setCredentials(gridAuth, gridCredentials);
    }

    // now create a http client, set the custom proxy and inject the credentials
    HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    clientBuilder.setDefaultCredentialsProvider(basicCredentialsProvider);
    if (proxyConfig != null)
        clientBuilder.setProxy(new HttpHost(proxyConfig.getHost(), Integer.valueOf(proxyConfig.getPort())));
    CloseableHttpClient httpClient = clientBuilder.build();

    Map<String, CommandInfo> additionalCommands = new HashMap<String, CommandInfo>();   // just a dummy

    // this command executor will do the credential magic for us. both proxy and target site credentials
    return new HttpCommandExecutor(additionalCommands, gridUrl, new ProxyHttpClient(httpClient));

}
项目:bdt    文件:HookGSpec.java   
/**
 * Connect to selenium.
 *
 * @throws MalformedURLException
 */
@Before(order = ORDER_10, value = {"@mobile,@web"})
public void seleniumSetup() throws MalformedURLException {
    String grid = System.getProperty("SELENIUM_GRID");
    if (grid == null) {
        fail("Selenium grid not available");
    }
    String b = ThreadProperty.get("browser");

    if ("".equals(b)) {
        fail("Non available browsers");
    }

    String browser = b.split("_")[0];
    String version = b.split("_")[1];
    commonspec.setBrowserName(browser);
    commonspec.getLogger().debug("Setting up selenium for {}", browser);

    DesiredCapabilities capabilities = null;

    switch (browser.toLowerCase()) {
        case "chrome":
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--no-sandbox");
            chromeOptions.addArguments("--ignore-certificate-errors");
            capabilities = DesiredCapabilities.chrome();
            capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
            break;
        case "firefox":
            capabilities = DesiredCapabilities.firefox();
            break;
        case "phantomjs":
            capabilities = DesiredCapabilities.phantomjs();
            break;
        case "iphone":
        case "safari":
            capabilities = DesiredCapabilities.iphone();
            capabilities.setCapability("platformName", "iOS");
            capabilities.setCapability("platformVersion", "8.1");
            capabilities.setCapability("deviceName", "iPhone Simulator");
            break;
        case "android":
            capabilities = DesiredCapabilities.android();
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("platformVersion", "6.0");
            capabilities.setCapability("deviceName", "Android Emulator");
            capabilities.setCapability("app", "Browser");
            break;
        default:
            commonspec.getLogger().error("Unknown browser: " + browser);
            throw new SeleniumException("Unknown browser: " + browser);
    }

    capabilities.setVersion(version);

    grid = "http://" + grid + "/wd/hub";
    HttpClient.Factory factory = new ApacheHttpClient.Factory(new HttpClientFactory(60000, 60000));
    HttpCommandExecutor executor = new HttpCommandExecutor(new HashMap<String, CommandInfo>(), new URL(grid), factory);
    commonspec.setDriver(new RemoteWebDriver(executor, capabilities));
    commonspec.getDriver().manage().timeouts().pageLoadTimeout(PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
    commonspec.getDriver().manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS);
    commonspec.getDriver().manage().timeouts().setScriptTimeout(SCRIPT_TIMEOUT, TimeUnit.SECONDS);

    commonspec.getDriver().manage().deleteAllCookies();
    if (capabilities.getCapability("deviceName") == null) {
        commonspec.getDriver().manage().window().setSize(new Dimension(1440, 900));
    }
    commonspec.getDriver().manage().window().maximize();

}
项目:selendroid    文件:SelendroidCommandExecutor.java   
private static CommandInfo newVendorCommand(String path, HttpMethod method) {
  return new CommandInfo(VENDOR_PREFIX + path, method);
}
项目:menggeqa    文件:MobileCommand.java   
/**
 * This methods forms GET commands.
 *
 * @param url is the command URL
 * @return an instance of {@link org.openqa.selenium.remote.CommandInfo}
 */
public static CommandInfo getC(String url) {
    return new CommandInfo(url, HttpMethod.GET);
}
项目:menggeqa    文件:MobileCommand.java   
/**
 * This methods forms POST commands.
 *
 * @param url is the command URL
 * @return an instance of {@link org.openqa.selenium.remote.CommandInfo}
 */
public static CommandInfo postC(String url) {
    return new CommandInfo(url, HttpMethod.POST);
}
项目:menggeqa    文件:MobileCommand.java   
/**
 * This methods forms DELETE commands.
 *
 * @param url is the command URL
 * @return an instance of {@link org.openqa.selenium.remote.CommandInfo}
 */
public static CommandInfo deleteC(String url) {
    return new CommandInfo(url, HttpMethod.DELETE);
}