Search in sources :

Example 26 with WebDriverException

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()));
}
Also used : File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException)

Example 27 with WebDriverException

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;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) User(com.wikia.webdriver.common.core.helpers.User) HttpEntity(org.apache.http.HttpEntity) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 28 with WebDriverException

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 "";
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) IOException(java.io.IOException) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

WebDriverException (org.openqa.selenium.WebDriverException)28 IOException (java.io.IOException)16 File (java.io.File)8 Matcher (java.util.regex.Matcher)4 URISyntaxException (java.net.URISyntaxException)3 Pattern (java.util.regex.Pattern)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 Gson (com.google.gson.Gson)2 TypeToken (com.google.gson.reflect.TypeToken)2 User (com.wikia.webdriver.common.core.helpers.User)2 AdsComparison (com.wikia.webdriver.pageobjectsfactory.pageobject.adsbase.helpers.AdsComparison)2 BufferedImage (java.awt.image.BufferedImage)2 Method (java.lang.reflect.Method)2 URL (java.net.URL)2 NoSuchElementException (java.util.NoSuchElementException)2 HttpResponse (org.apache.http.HttpResponse)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2