Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

add generic test for BatchClose #175

Open
wants to merge 1 commit into
base: universal-sdk
Choose a base branch
from

Conversation

IdosApplitools
Copy link
Collaborator

@IdosApplitools IdosApplitools commented Jan 8, 2023

Added a generic test for closing a batch with BatchClose. It also checks for setting apiKey and serverUrl in the same test against testeyes.applitools.com.

Added methods: eyes.batchClose({id='batch_id', apiKey='key', serverUrl='serverUrl'}, helpers.getBatchInfo(results), helpers.getEnvironmentVariable(name) and helpers.sleep(miliseconds).

helpers.getBatchInfo sends a request to api/sessions/batches/<batch_pointer_id>/batch in order to assert isCompleted:

public com.applitools.eyes.metadata.BatchInfo getBatchInfo(TestResults results) {
        com.applitools.eyes.metadata.BatchInfo batchInfo = null;
        try {
            batchInfo = TestUtils.getBatchResults(eyes.getApiKey(), results);
        } catch (Throwable e) {
            e.printStackTrace();
            Assert.fail("Exception appeared while getting session results");
        }
        return batchInfo;
    }

public static BatchInfo getBatchResults(String apiKey, TestResults results) throws JsonProcessingException {
        String apiBatchUrl = results.getApiUrls().getBatch() + "/batch";
        URI apiBatchUri = UriBuilder.fromUri(apiBatchUrl)
                .queryParam("format", "json")
                .queryParam("AccessToken", results.getSecretToken())
                .queryParam("apiKey", apiKey)
                .build();

        RestClient client = new RestClient(new Logger(new StdoutLogHandler()), apiBatchUri, ServerConnector.DEFAULT_CLIENT_TIMEOUT);
        client.setAgentId(ClassVersionGetter.CURRENT_VERSION);
        if (System.getenv("APPLITOOLS_USE_PROXY") != null) {
            client.setProxy(new ProxySettings("http://127.0.0.1", 8888));
        }

        String srStr = client.sendHttpRequest(apiBatchUri.toString(), HttpMethod.GET, MediaType.APPLICATION_JSON).getBodyString();
        ObjectMapper jsonMapper = new ObjectMapper();
        jsonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

        return jsonMapper.readValue(srStr, BatchInfo.class);
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant