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

com.github.invictum.reportportal.Utils Maven / Gradle / Ivy

package com.github.invictum.reportportal;

import net.thucydides.model.domain.TestOutcome;
import net.thucydides.model.domain.TestResult;
import net.thucydides.model.domain.TestStep;

import java.time.Duration;
import java.time.ZonedDateTime;
import java.util.Date;

public class Utils {

    private Utils() {
    }

    /**
     * Finds log level based on step result status.
     *
     * @param testResult used to define log level
     * @return discovered log level
     */
    public static String logLevel(TestResult testResult) {
        return Status.mapTo(testResult).logLevel().toString();
    }

    /**
     * Calculates step's end time.
     *
     * @param step to calculate time on
     * @return step end time in {@link Date} format
     */
    public static Date stepEndDate(TestStep step) {
        ZonedDateTime endTimeZoned = step.getStartTime().plus(Duration.ofMillis(step.getDuration()));
        return Date.from(endTimeZoned.toInstant());
    }

    /**
     * Calculates test's end time.
     *
     * @param test to calculate time on
     * @return test end time in {@link Date} format
     */
    public static Date testEndDate(TestOutcome test) {
        ZonedDateTime endTimeZoned = test.getStartTime().plus(Duration.ofMillis(test.getDuration()));
        return Date.from(endTimeZoned.toInstant());
    }

    /**
     * Calculates step's start time
     *
     * @param step to calculate time for
     * @return step start time in {@link Date} format
     */
    public static Date stepStartDate(TestStep step) {
        return Date.from(step.getStartTime().toInstant());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy