5

I'm using allure report to generate a report for my tests. earlier I used to use extent report. as you know, in extent report you can add logs and screenshot in order of creating them but in allure reports, all the screenshots are going to be shown at the end of steps.

My Question: Is it possible to show the screenshots between steps? I want to create a screenshot after each step and I want to see them in the right place and not at the end of the report.enter image description here enter image description here Thanks for your help :)

0xM4x
  • 460
  • 1
  • 8
  • 19

1 Answers1

5

You can call method with taking screenshot in the step:

@Test(description = "Screenshot in Step")
public void screenshotInStepTest() {
    driver.get("https://www.google.com");
    step1();
    step2();
    step3();
}

@Step("Step 1")
public void step1(){
    System.out.println("step 1");
}
@Step("Step 2 with screenshot")
public void step2(){
    System.out.println("step 2");
    screenshot();
}
@Step("Step 3")
public void step3(){
    System.out.println("step 3");
}

@Attachment(value = "Screenshot", type = "image/png")
public byte[] screenshot() {
    return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}

Update:

import java.io.ByteArrayInputStream;
//...
@Step("Step 1")
public void step1(){
    //...

    Allure.addAttachment("Any text", new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES)));
}

Report: enter image description here

Sers
  • 12,047
  • 2
  • 12
  • 31
  • Thanks for your response. but still if I have some steps in one method, the screenshots will appear at the end. right? I attached another image to the question. – 0xM4x Nov 06 '19 at 12:57
  • All `@Step` s with `screenshot()` method inside will have a screenshot. Add `screenshot()` method to the `Check if the Log in was successful` and you'll get screenshot as you need. – Sers Nov 06 '19 at 13:39
  • But it's not possible to have it for `Allure.step("something")` inside of a method. right? – 0xM4x Nov 06 '19 at 13:47
  • 2
    You can use `Allure.addAttachment()`, check the answer update – Sers Nov 06 '19 at 15:44
  • I tested also this method. changing the attached file name can be helpful to find it easier. but still it appears at the end and not where it has to. – 0xM4x Nov 07 '19 at 07:35
  • What Allure version do you use. I tested with 2.12.1 – Sers Nov 07 '19 at 11:30
  • I'm using **Gradle** so my dependency is `compile group: 'io.qameta.allure', name: 'allure-gradle', version: '2.8.1'` – 0xM4x Nov 07 '19 at 11:41
  • Try with 2.12.1 version – Sers Nov 07 '19 at 13:34
  • I'm using Maven and allure version is : 2.13.2. Still not work. – cocobear Jan 13 '21 at 03:28
  • @Sers, please tell me where to put it – Михаил Чаушевский Jan 26 '22 at 06:49
  • For @Step annotation to work, you need aspectJ library available. In case you for some reason cannot use it, then you can Allure.getLifecycle().startStep(...) and Allure.getLifecycle().stopStep(...) around screenshot generation. You also wight have to use Allure.addAttachment(...) to make screenshot available for allure. – Lauri Mar 30 '22 at 08:57