Search in sources :

Example 1 with AfterStep

use of io.cucumber.java.AfterStep in project syndesis-qe by syndesisio.

the class TestHooks method getLogs.

@AfterStep
public void getLogs(Scenario scenario) {
    if (scenario.isFailed()) {
        TestUtils.printPods(scenario);
        log.warn("Scenario {} failed, saving integration logs to scenario", scenario.getName());
        // There can be multiple integration pods for one test
        List<Pod> integrationPods = OpenShiftUtils.getInstance().pods().list().getItems().stream().filter(p -> p.getMetadata().getName().startsWith("i-") && !p.getMetadata().getName().contains("deploy") && !p.getMetadata().getName().contains("build")).collect(Collectors.toList());
        for (Pod integrationPod : integrationPods) {
            try {
                scenario.attach(OpenShiftUtils.getInstance().getPodLog(integrationPod).getBytes(), "text/plain", String.format("Integration %s log", integrationPod.getMetadata().getName()));
            } catch (KubernetesClientException ex) {
            // when the build failed, the integration pod is not ready (`ImagePullBackOff`) In that case, the pod doesn't contain log. That
            // causes that OpenShiftUtils has thrown KubernetesClientException
            }
        }
        log.info("Adding all failed build to the log");
        List<Pod> failedBuilds = OpenShiftUtils.getInstance().pods().list().getItems().stream().filter(p -> p.getMetadata().getName().contains("build") && p.getStatus().getContainerStatuses().stream().anyMatch(c -> c.getState().getTerminated().getReason().equals("Error"))).collect(Collectors.toList());
        for (Pod failedBuild : failedBuilds) {
            scenario.attach(String.format("%s\n\n%s", failedBuild.getMetadata().getName(), OpenShiftUtils.getInstance().getPodLog(failedBuild)).getBytes(), "text/plain", "Log of failed build " + failedBuild.getMetadata().getName());
        }
    }
}
Also used : TestConfiguration(io.syndesis.qe.TestConfiguration) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) CamelK(io.syndesis.qe.resource.impl.CamelK) AfterStep(io.cucumber.java.AfterStep) Scenario(io.cucumber.java.Scenario) Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftUtils(io.syndesis.qe.utils.OpenShiftUtils) Collectors(java.util.stream.Collectors) Assumptions(org.assertj.core.api.Assumptions) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) TestUtils(io.syndesis.qe.utils.TestUtils) After(io.cucumber.java.After) ResourceFactory(io.syndesis.qe.resource.ResourceFactory) Before(io.cucumber.java.Before) Pod(io.fabric8.kubernetes.api.model.Pod) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) AfterStep(io.cucumber.java.AfterStep)

Example 2 with AfterStep

use of io.cucumber.java.AfterStep in project extentreports-cucumber6-adapter by grasshopper7.

the class ScreenShotStepDefinition method afterSite.

@AfterStep(value = "@website")
public void afterSite(Scenario scenario) {
    System.out.println("AFTER SITE");
    TakesScreenshot ts = (TakesScreenshot) driver;
    byte[] screenshot = ts.getScreenshotAs(OutputType.BYTES);
    scenario.log("this is my failure message……….");
    scenario.attach(screenshot, "image/png", "");
    driver.quit();
}
Also used : TakesScreenshot(org.openqa.selenium.TakesScreenshot) AfterStep(io.cucumber.java.AfterStep)

Aggregations

AfterStep (io.cucumber.java.AfterStep)2 After (io.cucumber.java.After)1 Before (io.cucumber.java.Before)1 Scenario (io.cucumber.java.Scenario)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 TestConfiguration (io.syndesis.qe.TestConfiguration)1 ResourceFactory (io.syndesis.qe.resource.ResourceFactory)1 CamelK (io.syndesis.qe.resource.impl.CamelK)1 OpenShiftUtils (io.syndesis.qe.utils.OpenShiftUtils)1 TestUtils (io.syndesis.qe.utils.TestUtils)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Assumptions (org.assertj.core.api.Assumptions)1 TakesScreenshot (org.openqa.selenium.TakesScreenshot)1