Search in sources :

Example 6 with WebDriverException

use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.

the class ImageEditor method saveImageFile.

public void saveImageFile(File imageFile, String path) {
    Pattern pattern = Pattern.compile("/*.jpg|/*.png|/*.jpeg");
    Matcher matcher = pattern.matcher(path);
    String newPath = null;
    if (!matcher.matches()) {
        newPath = path + ".png";
    }
    try {
        FileUtils.copyFile(imageFile, new File(newPath));
    } catch (IOException e) {
        throw new WebDriverException(e);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException)

Example 7 with WebDriverException

use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.

the class NetworkTrafficInterceptor method logDFP.

/**
   * Looks for correlator pattern in requests query strings to DFP domain, and logs if all the calls
   * have the same correlator ID. Any difference is ID is logged as failure.
   */
public void logDFP(String skinCorrelator) {
    har = getHar();
    String expectedCorrelator = null;
    Pattern pt = Pattern.compile("(correlator=)\\d*");
    for (HarEntry entry : har.getLog().getEntries()) {
        if (entry.getRequest().getUrl().contains("pubads.g.doubleclick.net") && entry.getRequest().getQueryString().toString().contains(skinCorrelator)) {
            Matcher matcher = pt.matcher(entry.getRequest().getQueryString().toString());
            if (matcher.find()) {
                String correlatorID = matcher.group(0);
                if (expectedCorrelator == null) {
                    expectedCorrelator = correlatorID;
                }
                PageObjectLogging.log("CORRELATOR CHECK", "CORRELATOR ID: " + correlatorID, correlatorID.equals(expectedCorrelator));
            } else {
                throw new WebDriverException("Missing correlator param in query string");
            }
        }
    }
}
Also used : HarEntry(net.lightbody.bmp.core.har.HarEntry) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) WebDriverException(org.openqa.selenium.WebDriverException)

Example 8 with WebDriverException

use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.

the class Helios method deleteAllTokens.

public static void deleteAllTokens(User user) {
    String heliosGetTokenURL = HeliosConfig.getUrl(HeliosConfig.HeliosController.USERS);
    HttpDelete httpDelete = new HttpDelete(String.format("%s/%s/tokens", heliosGetTokenURL, user.getUserId()));
    httpDelete.setHeader("THE-SCHWARTZ", Configuration.getCredentials().apiToken);
    CloseableHttpResponse response = null;
    try {
        response = getDefaultClient().execute(httpDelete);
        PageObjectLogging.log("DELETE HEADERS: ", response.toString(), true);
    } 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);
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 9 with WebDriverException

use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.

the class ApiCall method call.

public void call() {
    try {
        URL url = new URL(getURL());
        CloseableHttpClient httpClient = HttpClientBuilder.create().disableAutomaticRetries().build();
        HttpPost httpPost = getHtppPost(url);
        // set header
        if (getUser() != null) {
            httpPost.addHeader("X-Wikia-AccessToken", Helios.getAccessToken(getUser()));
        }
        // set query params
        if (getParams() != null) {
            httpPost.setEntity(new UrlEncodedFormEntity(getParams(), StandardCharsets.UTF_8));
        }
        httpClient.execute(httpPost);
        PageObjectLogging.log("CONTENT PUSH", "Content posted to: " + getURL(), true);
    } catch (ClientProtocolException e) {
        PageObjectLogging.log("EXCEPTION", ExceptionUtils.getStackTrace(e), false);
        throw new WebDriverException(ERROR_MESSAGE);
    } catch (IOException e) {
        PageObjectLogging.log("IO EXCEPTION", ExceptionUtils.getStackTrace(e), false);
        throw new WebDriverException(ERROR_MESSAGE);
    } catch (URISyntaxException e) {
        PageObjectLogging.log("URI_SYNTAX EXCEPTION", ExceptionUtils.getStackTrace(e), false);
        throw new WebDriverException(ERROR_MESSAGE);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) ClientProtocolException(org.apache.http.client.ClientProtocolException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 10 with WebDriverException

use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.

the class EmailUtils method getFirstEmailContent.

public static String getFirstEmailContent(String userName, String password, String subject) {
    try {
        PageObjectLogging.logInfo("Checking emails for " + userName + " that contain '" + subject + "'");
        // establishing connections
        Properties props = System.getProperties();
        props.setProperty("mail.store.protocol", "imaps");
        Session session = Session.getDefaultInstance(props, null);
        Store store = session.getStore("imaps");
        store.connect("imap.googlemail.com", userName, password);
        // getInbox
        Folder inbox = store.getFolder("Inbox");
        inbox.open(Folder.READ_ONLY);
        Message[] messages = null;
        boolean forgottenPasswordMessageFound = false;
        Message magicMessage = null;
        for (int i = 0; !forgottenPasswordMessageFound; i++) {
            messages = inbox.getMessages();
            PageObjectLogging.log("Mail", "Waiting for the message", true);
            Thread.sleep(2000);
            for (Message message : messages) {
                if (message.getSubject().contains(subject)) {
                    forgottenPasswordMessageFound = true;
                    magicMessage = message;
                }
            }
            if (i > 15) {
                throw new WebDriverException("Mail timeout exceeded");
            }
        }
        PageObjectLogging.log("Mail", "Mail arrived", true);
        Message m = magicMessage;
        String line;
        StringBuilder builder = new StringBuilder();
        InputStreamReader in = new InputStreamReader(m.getInputStream());
        BufferedReader reader = new BufferedReader(in);
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        store.close();
        return builder.toString();
    } catch (NoSuchProviderException e) {
        PageObjectLogging.log("getFirstEmailContent", e, false);
        throw new WebDriverException();
    } catch (MessagingException | IOException | InterruptedException e) {
        PageObjectLogging.log("getFirstEmailContent", e, false);
        throw new WebDriverException();
    }
}
Also used : Message(javax.mail.Message) InputStreamReader(java.io.InputStreamReader) MessagingException(javax.mail.MessagingException) Store(javax.mail.Store) IOException(java.io.IOException) Properties(java.util.Properties) Folder(javax.mail.Folder) BufferedReader(java.io.BufferedReader) NoSuchProviderException(javax.mail.NoSuchProviderException) Session(javax.mail.Session) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

WebDriverException (org.openqa.selenium.WebDriverException)27 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