All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.testfabrik.webmate.javasdk.jobs.jobconfigs.BrowserSessionCrossbrowserJobInput Maven / Gradle / Ivy

There is a newer version: 0.56
Show newest version
package com.testfabrik.webmate.javasdk.jobs.jobconfigs;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.google.common.collect.ImmutableMap;
import com.testfabrik.webmate.javasdk.browsersession.BrowserSessionId;
import com.testfabrik.webmate.javasdk.jobs.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Helper class for creating BrowserSessionCrossbrowser jobs.
 */
public class BrowserSessionCrossbrowserJobInput implements WellKnownJobInput {

    private final BrowserSessionId referenceSession;
    private final List compareSessions;

    public BrowserSessionCrossbrowserJobInput(BrowserSessionId referenceSession,
                                              List compareSessions) {
        this.referenceSession = referenceSession;
        this.compareSessions = compareSessions;
    }

    @Override
    public JobConfigName getName() {
        return new JobConfigName("browsersession_crossbrowser_analysis");
    }

    @Override
    public Map makeInputValues() {
        JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
        ObjectMapper mapper = new ObjectMapper();

        List compareSessionJson = new ArrayList<>();
        for (BrowserSessionId compareSession : compareSessions) {
            JsonNode sessionNode = mapper.valueToTree(compareSession);
            WMValue sessionWMValue = new WMValue(new WMDataType("BrowserSessionRef"), sessionNode);
            compareSessionJson.add(mapper.valueToTree(sessionWMValue));
        }

        return ImmutableMap.of(
                new PortName("referenceSession"), new WMValue(new WMDataType("BrowserSessionRef"), jsonNodeFactory.textNode(referenceSession.toString())),
                new PortName("compareSessions"), new WMValue(new WMDataType("List[BrowserSessionRef]"), mapper.valueToTree(compareSessionJson)),
                new PortName("matchingType"), new WMValue(new WMDataType("String"), jsonNodeFactory.textNode("tag")),
                new PortName("enabledynamicelementsfilter"), new WMValue(new WMDataType("Boolean"), jsonNodeFactory.booleanNode(true))
        );
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy