Search in sources :

Example 1 with HttpClient

use of com.testsigma.automator.http.HttpClient in project testsigma by testsigmahq.

the class SafariDriver method setTimeouts.

@Override
public void setTimeouts() throws AutomatorException {
    String osVersion = getPlatform();
    int browserVersionValue = Integer.parseInt(getSafariVersion().split("\\.")[0]);
    if (((osVersion.equals("macOS 10.13") || osVersion.equals("macOS 10.14") || osVersion.equals("High Sierra")) || (osVersion.equals("macOS 10.15") || osVersion.equals("Catalina"))) && (browserVersionValue >= 12) && (executionLabType != ExecutionLabType.Hybrid)) {
        SessionId session = remoteWebDriver.getSessionId();
        Map<String, Object> timeouts = new HashMap<>();
        timeouts.put("implicit", settings.getElementTimeout() * 1000);
        timeouts.put("pageLoad", settings.getPageLoadTimeout() * 1000);
        try {
            UriComponents uriComponents = UriComponentsBuilder.fromUriString("/session/{sessionId}/timeouts").build().expand(session.toString()).encode();
            String url = webDriverSettings.getWebDriverServerUrl() + uriComponents.toUriString();
            HttpClient httpClient = EnvironmentRunner.getWebAppHttpClient();
            String authHeader = HttpClient.BEARER + " " + getSettings().getJwtApiKey();
            HttpResponse<String> response = null;
            for (int i = 0; i < 3; i++) {
                try {
                    response = httpClient.post(url, timeouts, new TypeReference<>() {
                    }, authHeader);
                    break;
                } catch (Exception ex) {
                    log.error(ex.getMessage(), ex);
                }
            }
            log.error(response.getStatusCode() + " - " + response.getResponseText());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new AutomatorException(e.getMessage(), e);
        }
    } else {
        super.setTimeouts();
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) UriComponents(org.springframework.web.util.UriComponents) HashMap(java.util.HashMap) HttpClient(com.testsigma.automator.http.HttpClient) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SessionId(org.openqa.selenium.remote.SessionId) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) MalformedURLException(java.net.MalformedURLException)

Example 2 with HttpClient

use of com.testsigma.automator.http.HttpClient in project testsigma by testsigmahq.

the class AddonService method checkAndDownloadJar.

public String checkAndDownloadJar(String classPath, String modifiedHash) throws IOException {
    log.info("Addon Plugin For Processing Step :::" + classPath);
    String fileName = FilenameUtils.getName(classPath);
    if (fileName.indexOf("?") > 0) {
        fileName = fileName.substring(0, fileName.indexOf("?"));
    }
    String jarFilePath = Paths.get(PathUtil.getInstance().getCustomClassesPath(), modifiedHash, fileName).toFile().getAbsolutePath();
    File jarFile = new File(jarFilePath);
    if (!jarFile.exists()) {
        log.info(String.format("Jar File Doesn't Exists. Downloading from %s to %s", classPath, jarFile.getAbsolutePath()));
        if (jarFile.getParentFile() != null) {
            jarFile.getParentFile().mkdirs();
        }
        HttpClient httpClient = EnvironmentRunner.getAssetsHttpClient();
        HttpResponse<String> response = httpClient.downloadFile(classPath, jarFilePath);
        log.info(String.format("Response while downloading jar file: %s - %s  ", response.getStatusCode(), response.getStatusMessage()));
        if (!jarFile.exists()) {
            log.error("Failed to download zip file to location - " + jarFile.getAbsolutePath());
        }
    } else {
        log.info(String.format("Jar file exists at %s so skipping download of custom NLP Jar", jarFile.getAbsolutePath()));
    }
    return jarFilePath;
}
Also used : HttpClient(com.testsigma.automator.http.HttpClient) File(java.io.File)

Aggregations

HttpClient (com.testsigma.automator.http.HttpClient)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 AutomatorException (com.testsigma.automator.exceptions.AutomatorException)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 SessionId (org.openqa.selenium.remote.SessionId)1 UriComponents (org.springframework.web.util.UriComponents)1