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

net.serenitybdd.core.SystemTimeouts Maven / Gradle / Ivy

There is a newer version: 4.2.8
Show newest version
package net.serenitybdd.core;

import net.serenitybdd.model.environment.EnvironmentSpecificConfiguration;
import net.serenitybdd.core.pages.DefaultTimeouts;
import net.thucydides.model.ThucydidesSystemProperty;
import net.thucydides.model.environment.SystemEnvironmentVariables;
import net.thucydides.model.util.EnvironmentVariables;

import java.util.Optional;

public class SystemTimeouts {
    private final EnvironmentVariables environmentVariables;

    public SystemTimeouts(EnvironmentVariables environmentVariables) {
        this.environmentVariables = environmentVariables;
    }

    public static SystemTimeouts forTheCurrentTest() {
        return new SystemTimeouts(SystemEnvironmentVariables.currentEnvironmentVariables());
    }

    public long getImplicitTimeout() {
        Optional configuredTimeout = webdriverCapabilitiesImplicitTimeoutFrom(environmentVariables);
        return configuredTimeout.orElse(DefaultTimeouts.DEFAULT_IMPLICIT_WAIT_TIMEOUT.toMillis());
    }

    public long getWaitForTimeout() {
        return ThucydidesSystemProperty.WEBDRIVER_WAIT_FOR_TIMEOUT.longFrom(environmentVariables, DefaultTimeouts.DEFAULT_WAIT_FOR_TIMEOUT.toMillis());
    }

    public static Optional webdriverCapabilitiesImplicitTimeoutFrom(EnvironmentVariables environmentVariables) {
        return EnvironmentSpecificConfiguration
                .from(environmentVariables)
                .getOptionalProperty("webdriver.capabilities.timeouts.implicit","webdriver.timeouts.implicitlywait")
                .map(Long::parseLong);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy