Java Code Examples for io.qameta.allure.Allure#getLifecycle()

The following examples show how to use io.qameta.allure.Allure#getLifecycle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllureJbehaveTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private AllureResults runStories(final String... storyResources) {
    final AllureResultsWriterStub writer = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writer);

    final Embedder embedder = new Embedder();
    embedder.useEmbedderMonitor(new NullEmbedderMonitor());
    embedder.useEmbedderControls(new EmbedderControls()
            .doGenerateViewAfterStories(false)
            .doFailOnStoryTimeout(false)
            .doBatch(false)
            .doIgnoreFailureInStories(true)
            .doIgnoreFailureInView(true)
            .doVerboseFailures(false)
            .doVerboseFiltering(false)
    );
    final AllureJbehave allureJbehave = new AllureJbehave(lifecycle);
    embedder.useConfiguration(new MostUsefulConfiguration()
            .useStoryLoader(new LoadFromClasspath(this.getClass()))
            .useStoryReporterBuilder(new ReportlessStoryReporterBuilder(temp.toFile())
                    .withReporters(allureJbehave)
            )
            .useDefaultStoryReporter(new NullStoryReporter())
    );
    final InjectableStepsFactory stepsFactory = new InstanceStepsFactory(
            embedder.configuration(),
            new SimpleStorySteps(),
            new BrokenStorySteps()
    );
    embedder.useCandidateSteps(stepsFactory.createCandidateSteps());
    final AllureLifecycle cached = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        embedder.runStoriesAsPaths(Arrays.asList(storyResources));
    } finally {
        Allure.setLifecycle(cached);
    }
    return writer;
}
 
Example 2
Source File: AllureCitrusTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@Step("Run test case {testDesigner}")
private AllureResults run(final TestDesigner testDesigner) {
    final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            CitrusSpringConfig.class, AllureCitrusConfig.class
    );
    final Citrus citrus = Citrus.newInstance(applicationContext);
    final TestContext testContext = citrus.createTestContext();

    final TestActionListeners listeners = applicationContext.getBean(TestActionListeners.class);
    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    final AllureLifecycle lifecycle = applicationContext.getBean(AllureLifecycle.class);
    try {
        Allure.setLifecycle(lifecycle);
        final TestCase testCase = testDesigner.getTestCase();
        testCase.setTestActionListeners(listeners);

        citrus.run(testCase, testContext);
    } catch (Exception ignored) {
    } finally {
        Allure.setLifecycle(defaultLifecycle);
    }

    return applicationContext.getBean(AllureResultsWriterStub.class);
}
 
Example 3
Source File: AllureJunit4Test.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@Step("Run classes {classes}")
private AllureResults runClasses(final Class<?>... classes) {
    final AllureResultsWriterStub writerStub = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writerStub);
    final JUnitCore core = new JUnitCore();
    core.addListener(new AllureJunit4(lifecycle));

    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);
        core.run(classes);
        return writerStub;
    } finally {
        Allure.setLifecycle(defaultLifecycle);
        StepsAspects.setLifecycle(defaultLifecycle);
        AttachmentsAspects.setLifecycle(defaultLifecycle);
    }
}
 
Example 4
Source File: AllureJunitPlatformTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Step("Run classes {classes}")
private AllureResults runClasses(final Class<?>... classes) {
    final AllureResultsWriterStub writerStub = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writerStub);

    final ClassSelector[] classSelectors = Stream.of(classes)
            .map(DiscoverySelectors::selectClass)
            .toArray(ClassSelector[]::new);

    final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .selectors(classSelectors)
            .build();

    final LauncherConfig config = LauncherConfig.builder()
            .enableTestExecutionListenerAutoRegistration(false)
            .addTestExecutionListeners(new AllureJunitPlatform(lifecycle))
            .build();
    final Launcher launcher = LauncherFactory.create(config);

    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);
        launcher.execute(request);
        return writerStub;
    } finally {
        Allure.setLifecycle(defaultLifecycle);
        StepsAspects.setLifecycle(defaultLifecycle);
        AttachmentsAspects.setLifecycle(defaultLifecycle);
    }
}
 
Example 5
Source File: AllureSpockTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
protected AllureResults run(final Class<?> clazz) {
    final AllureResultsWriterStub results = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(results);

    final RunNotifier notifier = new RunNotifier();
    final SpecInfo spec = new SpecInfoBuilder(clazz).build();
    spec.addListener(new AllureSpock(lifecycle));

    new JUnitDescriptionGenerator(spec).describeSpecMethods();
    new JUnitDescriptionGenerator(spec).describeSpec();

    final AllureLifecycle cached = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);

        RunContext.get().createSpecRunner(spec, notifier).run();
    } catch (Exception e) {
        throw new RuntimeException("could not execute sample", e);
    } finally {
        Allure.setLifecycle(cached);
        StepsAspects.setLifecycle(cached);
        AttachmentsAspects.setLifecycle(cached);
    }

    return results;
}
 
Example 6
Source File: RunUtils.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@SafeVarargs
public static AllureResults runWithinTestContext(final Runnable runnable,
                                                 final Consumer<AllureLifecycle>... configurers) {
    final AllureResultsWriterStub writer = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writer);

    final String uuid = UUID.randomUUID().toString();
    final TestResult result = new TestResult().setUuid(uuid);

    final AllureLifecycle cached = Allure.getLifecycle();
    try {
        Stream.of(configurers).forEach(configurer -> configurer.accept(lifecycle));

        lifecycle.scheduleTestCase(result);
        lifecycle.startTestCase(uuid);

        runnable.run();
    } catch (Throwable e) {
        lifecycle.updateTestCase(uuid, testResult -> {
            getStatus(e).ifPresent(testResult::setStatus);
            getStatusDetails(e).ifPresent(testResult::setStatusDetails);

        });
    } finally {
        lifecycle.stopTestCase(uuid);
        lifecycle.writeTestCase(uuid);

        Stream.of(configurers).forEach(configurer -> configurer.accept(cached));
    }

    return writer;
}
 
Example 7
Source File: AllureJunit5Test.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Step("Run classes {classes}")
private AllureResults runClasses(final Class<?>... classes) {
    final AllureResultsWriterStub writerStub = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writerStub);

    final ClassSelector[] classSelectors = Stream.of(classes)
            .map(DiscoverySelectors::selectClass)
            .toArray(ClassSelector[]::new);

    final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .configurationParameter("junit.jupiter.extensions.autodetection.enabled", "true")
            .selectors(classSelectors)
            .build();

    final LauncherConfig config = LauncherConfig.builder()
            .enableTestExecutionListenerAutoRegistration(false)
            .addTestExecutionListeners(new AllureJunitPlatform(lifecycle))
            .build();
    final Launcher launcher = LauncherFactory.create(config);

    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);
        launcher.execute(request);
        return writerStub;
    } finally {
        Allure.setLifecycle(defaultLifecycle);
        StepsAspects.setLifecycle(defaultLifecycle);
        AttachmentsAspects.setLifecycle(defaultLifecycle);
    }
}
 
Example 8
Source File: StepUtils.java    From allure-java with Apache License 2.0 4 votes vote down vote up
StepUtils(final Feature feature, final Scenario scenario) {
    this.lifecycle = Allure.getLifecycle();
    this.feature = feature;
    this.scenario = scenario;
}
 
Example 9
Source File: AttachmentsAspects.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
protected AllureLifecycle initialValue() {
    return Allure.getLifecycle();
}
 
Example 10
Source File: AllureAspectJ.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
protected AllureLifecycle initialValue() {
    return Allure.getLifecycle();
}
 
Example 11
Source File: StepsAspects.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
protected AllureLifecycle initialValue() {
    return Allure.getLifecycle();
}
 
Example 12
Source File: AllureJbehave.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public AllureJbehave() {
    this(Allure.getLifecycle());
}
 
Example 13
Source File: Allure1ParametersAspects.java    From allure-java with Apache License 2.0 4 votes vote down vote up
public static AllureLifecycle getLifecycle() {
    if (Objects.isNull(lifecycle)) {
        lifecycle = Allure.getLifecycle();
    }
    return lifecycle;
}
 
Example 14
Source File: Allure1TestCaseAspects.java    From allure-java with Apache License 2.0 4 votes vote down vote up
public static AllureLifecycle getLifecycle() {
    if (Objects.isNull(lifecycle)) {
        lifecycle = Allure.getLifecycle();
    }
    return lifecycle;
}
 
Example 15
Source File: Allure1StepsAspects.java    From allure-java with Apache License 2.0 4 votes vote down vote up
public static AllureLifecycle getLifecycle() {
    if (Objects.isNull(lifecycle)) {
        lifecycle = Allure.getLifecycle();
    }
    return lifecycle;
}
 
Example 16
Source File: AllureCucumberJvm.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public AllureCucumberJvm() {
    this(Allure.getLifecycle());
}
 
Example 17
Source File: AllureCucumber2Jvm.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public AllureCucumber2Jvm() {
    this(Allure.getLifecycle());
}
 
Example 18
Source File: AllureJunit4.java    From allure-java with Apache License 2.0 4 votes vote down vote up
public AllureJunit4() {
    this(Allure.getLifecycle());
}
 
Example 19
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public AllureCitrus() {
    this.lifecycle = Allure.getLifecycle();
}
 
Example 20
Source File: AllureSelenide.java    From allure-java with Apache License 2.0 4 votes vote down vote up
public AllureSelenide() {
    this(Allure.getLifecycle());
}