use of kong.unirest.Unirest in project seleniumRobot by bhecquet.
the class BrowserStackCapabilitiesFactory method uploadFile.
/**
* Upload application to saucelabs server
* @param targetAppPath
* @param serverURL
* @return
* @throws IOException
* @throws AuthenticationException
*/
private String uploadFile(String application) {
// extract user name and password from getWebDriverGrid
Matcher matcher = REG_USER_PASSWORD.matcher(SeleniumTestsContextManager.getThreadContext().getWebDriverGrid().get(0));
String user;
String password;
if (matcher.matches()) {
user = matcher.group(1);
password = matcher.group(2);
} else {
throw new ConfigurationException("webDriverGrid variable does not have the right format for connecting to sauceLabs: \"https://<user>:<token>@hub.browserstack.com/wd/hub\"");
}
try (UnirestInstance unirest = Unirest.spawnInstance()) {
String proxyHost = System.getProperty("https.proxyHost");
String proxyPort = System.getProperty("https.proxyPort");
if (proxyHost != null && proxyPort != null) {
unirest.config().proxy(proxyHost, Integer.valueOf(proxyPort));
}
HttpResponse<JsonNode> jsonResponse = unirest.post(BROWSERSTACK_UPLOAD_URL).basicAuth(user, password).field("file", new File(application)).asJson().ifFailure(response -> {
throw new ConfigurationException(String.format("Application file upload failed: %s", response.getStatusText()));
}).ifSuccess(response -> {
logger.info("Application successfuly uploaded to Saucelabs");
});
return jsonResponse.getBody().getObject().getString("app_url");
} catch (UnirestException e) {
throw new ConfigurationException("Application file upload failed: " + e.getMessage());
}
}
use of kong.unirest.Unirest in project seleniumRobot by bhecquet.
the class SauceLabsCapabilitiesFactory method uploadFile.
/**
* Upload application to saucelabs server
* @param targetAppPath
* @param serverURL
* @return
* @throws IOException
* @throws AuthenticationException
*/
private void uploadFile(String application) {
// extract user name and password from getWebDriverGrid
Matcher matcher = REG_USER_PASSWORD.matcher(SeleniumTestsContextManager.getThreadContext().getWebDriverGrid().get(0));
String user;
String password;
String datacenter;
if (matcher.matches()) {
user = matcher.group(1);
password = matcher.group(2);
datacenter = matcher.group(3);
} else {
throw new ConfigurationException("webDriverGrid variable does not have the right format for connecting to sauceLabs: \"https://<user>:<token>@ondemand.<datacenter>.saucelabs.com:443/wd/hub\"");
}
try (UnirestInstance unirest = Unirest.spawnInstance()) {
String proxyHost = System.getProperty("https.proxyHost");
String proxyPort = System.getProperty("https.proxyPort");
if (proxyHost != null && proxyPort != null) {
unirest.config().proxy(proxyHost, Integer.valueOf(proxyPort));
}
unirest.post(String.format(SAUCE_UPLOAD_URL, datacenter)).basicAuth(user, password).field("payload", new File(application)).field("name", new File(application).getName()).asString().ifFailure(response -> {
throw new ConfigurationException(String.format("Application file upload failed: %s", response.getStatusText()));
}).ifSuccess(response -> {
logger.info("Application successfuly uploaded to Saucelabs");
});
} catch (UnirestException e) {
throw new ConfigurationException("Application file upload failed: " + e.getMessage());
}
}
Aggregations