Example usage for org.openqa.selenium Platform family

List of usage examples for org.openqa.selenium Platform family

Introduction

In this page you can find the example usage for org.openqa.selenium Platform family.

Prototype

public abstract Platform family();

Source Link

Document

Returns a platform that represents a family for the current platform.

Usage

From source file:com.rmn.qa.AutomationUtils.java

License:Open Source License

/**
 * Returns the underlying 'family' of the specified platform
 * @param platform//from  w  w  w.  j av  a  2  s  .  c  om
 * @return
 */
public static Platform getUnderlyingFamily(Platform platform) {
    if (platform == null) {
        return null;
    }
    if (platform == Platform.UNIX || platform == Platform.WINDOWS || platform == Platform.MAC
            || platform == Platform.ANY) {
        return platform;
    } else {
        return getUnderlyingFamily(platform.family());
    }
}

From source file:com.rmn.qa.task.AutomationScaleNodeTask.java

License:Open Source License

@Override
public void doWork() {
    log.warn("Doing node scale work");
    // Iterate over all queued requests and track browser/platform combinations that are eligible to scale capacity for
    Iterator<DesiredCapabilities> pendingCapabilities = getDesiredCapabilities().iterator();
    if (pendingCapabilities.hasNext()) {
        log.info("Analyzing currently queued requests");
        while (pendingCapabilities.hasNext()) {
            DesiredCapabilities capabilities = pendingCapabilities.next();
            String browser = (String) capabilities.getCapability(CapabilityType.BROWSER_NAME);
            Object platformObject = capabilities.getCapability(CapabilityType.PLATFORM);
            Platform platform = AutomationUtils.getPlatformFromObject(platformObject);
            // If a valid platform wasn't able to be parsed from the queued test request, go ahead and default to Platform.ANY,
            // as Platform is not required for this plugin
            if (platform == null) {
                // Default to ANY here and let AwsVmManager dictate what ANY translates to
                platform = Platform.ANY;
            }//from  w  ww .  j  a  va  2s . com
            // Group all platforms by their underlying family
            platform = AutomationUtils.getUnderlyingFamily(platform);
            BrowserPlatformPair desiredPair = new BrowserPlatformPair(browser, platform);

            // Don't attempt to calculate load for browsers & platform families we cannot start
            if (!isEligibleToScale(desiredPair)) {
                log.warn("Unsupported browser and platform pair, browser:  " + browser + " platform family: "
                        + platform.family());
                continue;
            }

            // Handle requests for specific browser platforms.
            queuedBrowsersPlatforms.computeIfAbsent(new BrowserPlatformPair(browser, platform),
                    s -> new Date());
        }
    }
    // Now, iterate over eligible browser/platform combinations that we're tracking and attempt to scale up
    Iterator<BrowserPlatformPair> queuedBrowsersIterator = queuedBrowsersPlatforms.keySet().iterator();
    while (queuedBrowsersIterator.hasNext()) {
        BrowserPlatformPair originalBrowserPlatformRequest = queuedBrowsersIterator.next();
        Date currentTime = new Date();
        Date timeBrowserPlatformQueued = queuedBrowsersPlatforms.get(originalBrowserPlatformRequest);
        if (haveTestRequestsBeenQueuedForLongEnough(currentTime, timeBrowserPlatformQueued)) { // If we've had pending queued requests for this browser for at least 5 seconds
            pendingCapabilities = getDesiredCapabilities().iterator();
            if (pendingCapabilities.hasNext()) {
                int browsersToStart = 0;
                while (pendingCapabilities.hasNext()) {
                    DesiredCapabilities currentlyQueuedCapabilities = pendingCapabilities.next();
                    String currentlyQueuedBrowser = (String) currentlyQueuedCapabilities
                            .getCapability(CapabilityType.BROWSER_NAME);
                    Object platformObject = currentlyQueuedCapabilities.getCapability(CapabilityType.PLATFORM);
                    Platform currentlyQueuedPlatform = AutomationUtils.getPlatformFromObject(platformObject);
                    // If a valid platform wasn't able to be parsed from the queued test request, go ahead and default to Platform.ANY,
                    // as Platform is not required for this plugin
                    if (currentlyQueuedPlatform == null) {
                        currentlyQueuedPlatform = Platform.ANY;
                    }
                    // Group all platforms by their underlying family
                    currentlyQueuedPlatform = AutomationUtils.getUnderlyingFamily(currentlyQueuedPlatform);
                    if (originalBrowserPlatformRequest
                            .equals(new BrowserPlatformPair(currentlyQueuedBrowser, currentlyQueuedPlatform))) {
                        browsersToStart++;
                    }
                }
                this.startNodesForBrowserPlatform(originalBrowserPlatformRequest, browsersToStart);
            }
            // Regardless of if we spun up browsers or not, clear this count out
            queuedBrowsersIterator.remove();
        }
    }
}