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

com.github.mike10004.seleniumhelp.EnvironmentWebDriverFactory Maven / Gradle / Ivy

There is a newer version: 0.58
Show newest version
package com.github.mike10004.seleniumhelp;

import com.google.common.collect.ImmutableMap;
import org.openqa.selenium.MutableCapabilities;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

public abstract class EnvironmentWebDriverFactory implements WebDriverFactory {

    protected final Supplier> environmentSupplier;

    protected EnvironmentWebDriverFactory(Builder builder) {
        this.environmentSupplier = checkNotNull(builder.environmentSupplier);
    }

    static Map createEnvironmentForDisplay(@Nullable String display) {
        Map env = new HashMap<>();
        setDisplayEnvironmentVariable(env, display);
        return env;
    }

    static void setDisplayEnvironmentVariable(Map env, @Nullable String display) {
        if (display != null) {
            env.put("DISPLAY", display);
        }
    }

    static Supplier> createEnvironmentSupplierForDisplay(@Nullable String display) {
        if (display == null) {
            return ImmutableMap::of;
        } else {
            return () -> (ImmutableMap.of("DISPLAY", display));
        }
    }

    @SuppressWarnings("unchecked")
    public static abstract class Builder {
        private Supplier> environmentSupplier = HashMap::new;

        protected Builder() {
        }

        public final B environment(Supplier> environmentSupplier) {
            this.environmentSupplier = checkNotNull(environmentSupplier);
            return (B) this;
        }

        public final B environment(Map environment) {
            this.environmentSupplier = () -> environment;
            return (B) this;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy