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

ru.yandex.qatools.allure.data.AllureReportGenerator Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package ru.yandex.qatools.allure.data;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import ru.yandex.qatools.allure.data.converters.TestCaseConverter;
import ru.yandex.qatools.allure.data.io.Reader;
import ru.yandex.qatools.allure.data.io.ReportWriter;
import ru.yandex.qatools.allure.data.plugins.PluginManager;
import ru.yandex.qatools.allure.model.TestCaseResult;
import ru.yandex.qatools.commons.model.Environment;

import java.io.File;

/**
 * @author Dmitry Baev [email protected]
 *         Date: 12.02.15
 */
public class AllureReportGenerator {

    @Inject
    private Reader testCaseReader;

    @Inject
    private Reader environmentReader;

    @Inject
    private Reader attachmentReader;

    @Inject
    private TestCaseConverter converter;

    @Inject
    private PluginManager pluginManager;

    public AllureReportGenerator(File... inputDirectories) {
        this(AllureReportGenerator.class.getClassLoader(), inputDirectories);
    }

    public AllureReportGenerator(ClassLoader pluginClassLoader, File... inputDirectories) {
        this(new AllureGuiceModule(pluginClassLoader, inputDirectories));
    }

    /**
     * For testing only
     */
    AllureReportGenerator(AbstractModule module) {
        Guice.createInjector(module).injectMembers(this);
    }

    public void generate(File outputDirectory) {
        ReportWriter writer = new ReportWriter(outputDirectory);
        generate(writer);
    }

    public void generate(ReportWriter writer) {
        if (!testCaseReader.iterator().hasNext()) {
            throw new ReportGenerationException("Could not find any allure results");
        }

        for (TestCaseResult result : testCaseReader) {
            pluginManager.prepare(result);

            AllureTestCase testCase = converter.convert(result);
            pluginManager.prepare(testCase);
            pluginManager.process(testCase);
            writer.write(testCase);
        }

        for (Environment environment : environmentReader) {
            pluginManager.prepare(environment);
            pluginManager.process(environment);
        }

        for (AttachmentInfo attachment : attachmentReader) {
            pluginManager.prepare(attachment);
            writer.write(attachment);
        }

        pluginManager.writePluginData(writer);
        pluginManager.writePluginResources(writer);
        pluginManager.writePluginList(writer);
        pluginManager.writePluginWidgets(writer);

        writer.writeReportInfo();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy