package at.porscheinformatik.seleniumcomponents;

import java.util.Locale;

import org.openqa.selenium.WebDriver;

/**
 * Environment for Selenium tests.
 *
 * @author HAM
 */
public interface SeleniumEnvironment
{

    /**
     * Returns the driver for the browser.
     *
     * @return the web driver
     */
    WebDriver getDriver();

    /**
     * The language used for the messages.
     *
     * @return the locale
     */
    Locale getLanguage();

    /**
     * Returns the message with the specified key. If the message is missing, it should return null.
     *
     * @param key the key
     * @param args the args
     * @return the message, null if not found
     */
    String getMessage(String key, Object... args);

    /**
     * Returns the message with the specified key. If the message is missing, it returns the key itself.
     *
     * @param key the key
     * @param args the args
     * @return the message, never null
     */
    default String getMessageOrKey(String key, Object... args)
    {
        String message = getMessage(key, args);

        return message != null ? message : key;
    }

    /**
     * Quits the Selenium driver.
     */
    default void quit()
    {
        getDriver().quit();
    }

    /**
     * Restarts the driver.
     */
    void restart();

}

@@ -43,16 +43,124 @@
 nents;%0A%0A
+import java.time.LocalDate;%0Aimport java.time.format.DateTimeFormatter;%0Aimport java.time.format.FormatStyle;%0A
 import j
@@ -556,24 +556,1881 @@
 anguage();%0A%0A
+    /**%0A     * Parses the given date string in the locale returned by %7B@link #getLanguage()%7D with %7B@link FormatStyle#MEDIUM%7D%0A     * %0A     * @param dateAsString the date to parse%0A     * @return the parsed date%0A     */%0A    default LocalDate parseDate(String dateAsString)%0A    %7B%0A        return parseDate(dateAsString, FormatStyle.MEDIUM);%0A    %7D%0A%0A    /**%0A     * Parses the given date string in the locale returned by %7B@link #getLanguage()%7D%0A     * %0A     * @param dateAsString the date to parse%0A     * @param style the date style%0A     * @return the parsed date%0A     */%0A    default LocalDate parseDate(String dateAsString, FormatStyle style)%0A    %7B%0A        if (dateAsString == null)%0A        %7B%0A            return null;%0A        %7D%0A%0A        DateTimeFormatter formatter = getDateTimeFormatter(style);%0A%0A        return LocalDate.parse(dateAsString, formatter);%0A    %7D%0A%0A    /**%0A     * Formats the given date string in the locale returned by %7B@link #getLanguage()%7D with %7B@link FormatStyle#MEDIUM%7D%0A     * %0A     * @param date the date to format%0A     * @return the formatted date%0A     */%0A    default String formatDate(LocalDate date)%0A    %7B%0A        return formatDate(date, FormatStyle.MEDIUM);%0A    %7D%0A%0A    /**%0A     * Formats the given date string in the locale returned by %7B@link #getLanguage()%7D%0A     * %0A     * @param date the date to format%0A     * @param style the date style%0A     * @return the formatted date%0A     */%0A    default String formatDate(LocalDate date, FormatStyle style)%0A    %7B%0A        if (date == null)%0A        %7B%0A            return null;%0A        %7D%0A%0A        DateTimeFormatter formatter = getDateTimeFormatter(style);%0A%0A        return date.format(formatter);%0A    %7D%0A%0A    default DateTimeFormatter getDateTimeFormatter(FormatStyle style)%0A    %7B%0A        Locale language = getLanguage();%0A%0A        return DateTimeFormatter.ofLocalizedDate(style).localizedBy(language);%0A    %7D%0A%0A
     /**%0A    

Add date handling to SeleniumEnvironment