use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class ExtHelper method findExtension.
public static File findExtension(String name, String suffix) {
File extensions = new File("." + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "extensions");
String fullName = name + "." + suffix;
Collection<File> extFiles = FileUtils.listFiles(extensions, new String[] { suffix }, true);
for (File extFile : extFiles) {
if (extFile.getName().equals(fullName)) {
return extFile;
}
}
throw new WebDriverException(String.format("Can't find '%s' extension in '%s'", fullName, extensions.getPath()));
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class Helios method getAccessToken.
public static String getAccessToken(String userName, String password) {
for (User user : User.values()) {
if (userName.equals(user.getUserName()) && StringUtils.isNotBlank(user.getAccessToken())) {
tokenCache.put(userName, user.getAccessToken());
}
}
String heliosGetTokenURL = HeliosConfig.getUrl(HeliosConfig.HeliosController.TOKEN);
CloseableHttpClient httpClient = getDefaultClient();
if (StringUtils.isNotBlank(getTokenFromCache(userName))) {
return tokenCache.get(userName);
}
HttpPost httpPost = new HttpPost(heliosGetTokenURL);
List<NameValuePair> nvps = new ArrayList<>();
nvps.add(new BasicNameValuePair("grant_type", HeliosConfig.GrantType.PASSWORD.getGrantType()));
nvps.add(new BasicNameValuePair("username", userName));
nvps.add(new BasicNameValuePair("password", password));
CloseableHttpResponse response = null;
String token = "";
httpPost.setEntity(new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8));
try {
try {
response = httpClient.execute(httpPost);
} catch (ConnectTimeoutException e) {
PageObjectLogging.log("Timeout when connecting to helios", e, true);
response = httpClient.execute(httpPost);
}
HttpEntity entity = response.getEntity();
JSONObject responseValue = new JSONObject(EntityUtils.toString(entity));
EntityUtils.consume(entity);
token = responseValue.getString("access_token");
tokenCache.put(userName, token);
} catch (JSONException e) {
PageObjectLogging.log("JSON EXCEPTION", ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(e);
} catch (ClientProtocolException e) {
PageObjectLogging.log("CLIENT PROTOCOL EXCEPTION", ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(e);
} catch (IOException e) {
PageObjectLogging.log(IOEXCEPTION_COMMAND, IOEXCEPTION_ERROR_MESSAGE + ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(e);
} finally {
PageObjectLogging.log("LOGIN HEADERS: ", response != null ? response.toString() : null, true);
PageObjectLogging.log("LOGIN RESPONSE: ", response != null ? response.getEntity().toString() : null, true);
}
return token;
}
use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.
the class Helios method getTokenFromCache.
private static String getTokenFromCache(String userName) {
CloseableHttpClient httpClient = getDefaultClient();
try {
if (tokenCache.containsKey(userName)) {
String getTokenInfoURL = HeliosConfig.getUrl(HeliosConfig.HeliosController.INFO) + String.format("?code=%s&noblockcheck", tokenCache.get(userName));
HttpGet getInfo = new HttpGet(getTokenInfoURL);
if (httpClient.execute(getInfo).getStatusLine().getStatusCode() == 200) {
return tokenCache.get(userName);
}
}
} catch (IOException e) {
PageObjectLogging.log(IOEXCEPTION_COMMAND, IOEXCEPTION_ERROR_MESSAGE + ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(e);
}
return "";
}
Aggregations