io.qameta.allure.Allure Java Examples
The following examples show how to use
io.qameta.allure.Allure.
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: StaticMatrixTest.java From sailfish-core with Apache License 2.0 | 6 votes |
private void attachFiles() throws IOException { if (LOGGER.isInfoEnabled()) { LOGGER.info("Attaching files for matrix: {}", matrix.getCanonicalPath()); } try(InputStream stream = new FileInputStream(matrix)) { String name = matrix.getName(); Allure.addAttachment(name, Files.probeContentType(matrix.toPath()), stream, FilenameUtils.getExtension(name)); } try(InputStream stream = new FileInputStream(services)) { Allure.addAttachment("Services.zip", Files.probeContentType(services.toPath()), stream, "zip"); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Attached files for matrix: {}", matrix.getCanonicalPath()); } }
Example #2
Source File: AllureCitrusTest.java From allure-java with Apache License 2.0 | 6 votes |
@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: AllureCitrusTest.java From allure-java with Apache License 2.0 | 6 votes |
@AllureFeatures.Steps @Test void shouldAddAllureSteps() { final DefaultTestDesigner designer = new DefaultTestDesigner(); designer.name("Simple test"); designer.action(new AbstractTestAction() { @Override public void doExecute(final TestContext context) { Allure.step("a"); Allure.step("b"); Allure.step("c"); } }); final AllureResults results = run(designer); assertThat(results.getTestResults()) .flatExtracting(TestResult::getSteps) .flatExtracting(StepResult::getSteps) .extracting(StepResult::getName) .containsExactly("a", "b", "c"); }
Example #4
Source File: AllureSelenideTest.java From allure-java with Apache License 2.0 | 6 votes |
@AllureFeatures.Steps @Test void shouldNotLogSelenideLocatorSteps() { final AllureResults results = runWithinTestContext(() -> { final AllureSelenide selenide = new AllureSelenide() .savePageSource(false) .screenshots(false) .includeSelenideSteps(false); SelenideLogger.addListener(UUID.randomUUID().toString(), selenide); Allure.step("step1"); final SelenideLog log = SelenideLogger.beginStep( "dummy source", "dummyMethod()" ); SelenideLogger.commitStep(log, LogEvent.EventStatus.PASS); Allure.step("step2"); }); List<StepResult> steps = extractAllStepsFromResults(results); assertThat(steps).hasSize(2); assertThat(steps.get(0).getName()).isEqualTo("step1"); // no selenide steps in between assertThat(steps.get(1).getName()).isEqualTo("step2"); }
Example #5
Source File: AllureJunit4Test.java From allure-java with Apache License 2.0 | 6 votes |
@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 #6
Source File: AllureJbehaveTest.java From allure-java with Apache License 2.0 | 6 votes |
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 #7
Source File: RunUtils.java From allure-java with Apache License 2.0 | 5 votes |
public static AllureResults runWithinTestContext(final Runnable runnable) { return runWithinTestContext( runnable, Allure::setLifecycle, StepsAspects::setLifecycle, AttachmentsAspects::setLifecycle ); }
Example #8
Source File: AllureJunit5Test.java From allure-java with Apache License 2.0 | 5 votes |
@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 #9
Source File: AllureTestNgTest.java From allure-java with Apache License 2.0 | 5 votes |
@Step("Run testng suites {suites}") private AllureResults runTestNgSuites(final Consumer<TestNG> configurer, final String... suites) { final ClassLoader classLoader = getClass().getClassLoader(); List<String> suiteFiles = Arrays.stream(suites) .map(classLoader::getResource) .filter(Objects::nonNull) .map(URL::getFile) .collect(Collectors.toList()); assertThat(suites) .as("Cannot find all suite xml files") .hasSameSizeAs(suiteFiles); final AllureResultsWriterStub results = new AllureResultsWriterStub(); final AllureLifecycle lifecycle = new AllureLifecycle(results); final AllureTestNg adapter = new AllureTestNg(lifecycle); final TestNG testNg = new TestNG(false); testNg.addListener((ITestNGListener) adapter); testNg.setTestSuites(suiteFiles); configurer.accept(testNg); final AllureLifecycle cached = Allure.getLifecycle(); try { Allure.setLifecycle(lifecycle); StepsAspects.setLifecycle(lifecycle); AttachmentsAspects.setLifecycle(lifecycle); testNg.run(); } finally { Allure.setLifecycle(cached); StepsAspects.setLifecycle(cached); AttachmentsAspects.setLifecycle(cached); } return results; }
Example #10
Source File: AllureJunitPlatform.java From allure-java with Apache License 2.0 | 5 votes |
private void resetContext(final TestIdentifier testIdentifier) { // in case of fixtures that reported within a test we need to return current // test case uuid to allure thread local storage Optional.of(testIdentifier) .filter(TestIdentifier::isTest) .flatMap(tests::get) .ifPresent(Allure.getLifecycle()::setCurrentTestCase); }
Example #11
Source File: RunUtils.java From allure-java with Apache License 2.0 | 5 votes |
@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 #12
Source File: AllureJunitPlatformTest.java From allure-java with Apache License 2.0 | 5 votes |
@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 #13
Source File: TestWithSteps.java From allure-java with Apache License 2.0 | 5 votes |
protected final void step(final String stepName) { final String uuid = UUID.randomUUID().toString(); try { Allure.getLifecycle().startStep(uuid, new StepResult() .setName(stepName) .setStatus(Status.PASSED) ); } finally { Allure.getLifecycle().stopStep(uuid); } }
Example #14
Source File: AllureSpockTest.java From allure-java with Apache License 2.0 | 5 votes |
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 #15
Source File: AllureSelenideTest.java From allure-java with Apache License 2.0 | 5 votes |
@AllureFeatures.Steps @Test void shouldSupportNestedSteps() { final AllureResults results = runWithinTestContext(() -> { final AllureSelenide selenide = new AllureSelenide() .savePageSource(false) .screenshots(false); SelenideLogger.addListener(UUID.randomUUID().toString(), selenide); final SelenideLog log = SelenideLogger.beginStep( "dummy source", "dummyMethod()", "param1", "param2" ); Allure.step("child1"); Allure.step("child2"); Allure.step("child3"); SelenideLogger.commitStep(log, LogEvent.EventStatus.PASS); }); final StepResult selenideStep = extractStepFromResults(results); assertThat(selenideStep.getSteps()) .extracting(StepResult::getName) .containsExactly("child1", "child2", "child3"); }
Example #16
Source File: ConfigDialogImpl.java From bobcat with Apache License 2.0 | 5 votes |
private void configure(ComponentConfiguration config) { Allure.addAttachment("Component configuration", config.toString()); config.getTabs().forEach(tab -> { switchTab(tab.getTabName()); setFields(config.getConfigurationForTab(tab.getTabName())); }); }
Example #17
Source File: AllureHelper.java From qa-automation-samples with MIT License | 5 votes |
private static void screenShot(String status, Scenario scenario) { byte[] screenshootBytes = ((TakesScreenshot) Page.getDriver()).getScreenshotAs(OutputType.BYTES); InputStream screenshootStream = new ByteArrayInputStream(screenshootBytes); Allure.addAttachment(scenario.getName() +" - "+ status, screenshootStream); }
Example #18
Source File: ScreenshotExtension.java From bobcat with Apache License 2.0 | 4 votes |
private void takeScreenshot(WebDriver webDriver) throws IOException { File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE); Allure.addAttachment("Screenshot", new FileInputStream(screenshotAs)); }
Example #19
Source File: AllureAspectJ.java From allure-java with Apache License 2.0 | 4 votes |
@Override protected AllureLifecycle initialValue() { return Allure.getLifecycle(); }
Example #20
Source File: AllureJunitPlatform.java From allure-java with Apache License 2.0 | 4 votes |
public AllureJunitPlatform() { this.lifecycle = Allure.getLifecycle(); }
Example #21
Source File: AllureCucumber4Jvm.java From allure-java with Apache License 2.0 | 4 votes |
@SuppressWarnings("unused") public AllureCucumber4Jvm() { this(Allure.getLifecycle()); }
Example #22
Source File: AllureSelenide.java From allure-java with Apache License 2.0 | 4 votes |
public AllureSelenide() { this(Allure.getLifecycle()); }
Example #23
Source File: AllureCucumber3Jvm.java From allure-java with Apache License 2.0 | 4 votes |
@SuppressWarnings("unused") public AllureCucumber3Jvm() { this(Allure.getLifecycle()); }
Example #24
Source File: AllureJunit5Assert.java From allure-java with Apache License 2.0 | 4 votes |
@Override protected AllureLifecycle initialValue() { return Allure.getLifecycle(); }
Example #25
Source File: AllureJbehave.java From allure-java with Apache License 2.0 | 4 votes |
@SuppressWarnings("unused") public AllureJbehave() { this(Allure.getLifecycle()); }
Example #26
Source File: AllureTestNg.java From allure-java with Apache License 2.0 | 4 votes |
public AllureTestNg() { this.lifecycle = Allure.getLifecycle(); }
Example #27
Source File: AttachmentsTest.java From allure-java with Apache License 2.0 | 4 votes |
@Test public void testWithAttachment() { Allure.addAttachment("String attachment", "text/plain", "<p>HELLO</p>"); Assert.assertTrue(true); }
Example #28
Source File: StepsAspects.java From allure-java with Apache License 2.0 | 4 votes |
@Override protected AllureLifecycle initialValue() { return Allure.getLifecycle(); }
Example #29
Source File: AttachmentsAspects.java From allure-java with Apache License 2.0 | 4 votes |
@Override protected AllureLifecycle initialValue() { return Allure.getLifecycle(); }
Example #30
Source File: BeforeEachFixtureFailureSupport.java From allure-java with Apache License 2.0 | 4 votes |
@Test void test1() { Allure.step("test1 1"); Allure.step("test1 2"); }