Allure reports not able to get feature name or add screenshot

24 Views Asked by At

I am using Java, Appium, Allure and Cucumber to write my mobile automation tests. But now I am having problems with Allure reports.

I have no problems generating Allure report everything works as it should. I only have problems with how my tests are displayed and screenshot is not visible on test failure.

My Feature file names are not being displayed with arrow dropdown menu which you should click to see your scenario name and results. I do not see that I ONLY see Scenario name without test body or anything so I can't see screenshot.

I am running my tests with maven using command "mvn clean test -Dos='os'"

What I want is to see a Feature name like it is supposed to. And then have an arrow icon that does a dropdown menu where you see your scenario data. So if it failed, passed and screenshot if it does fail. Not sure if this is correct but every time my test is completed allure generates 3 container.json files and 1 result.json file.

I managed to make it work with this updated code to add screenshot but it shows blue question mark. Doesn't matter tho because its still showing up as scenario name not feature name...

Here is my code:

My feature file:

@dashboard
Feature: Feature for dashboard
  all features for dashboard

  Scenario: Validate homepage sections have interactable content and Validate incorrect security code displays error
    #Validate homepage sections have interactable content
    #Given user is logged in application
    Given user logs in app
    Then validate triglav komplet
    Then validate insurance card
    Then validate news card
    # Validate incorrect security code displays error
    Given user puts app in background
    And Verify entering incorrect security code displays an error message
    Then Verify My profile page is accessible
    Then Verify Messages page is accessible
    Then Verify Notifications page is accessible
    Then Verify entering four incorrect security codes logs the user out

My dashboard test:

public class DashboardSteps {

    private static AppiumDriver driver;

    private static ThreadLocal<AppiumDriver> driverThreadLocal = new ThreadLocal<>();
    private static DriverSetup driverSetup = new DriverSetup();
    private static PageObjectManager screen;

    private static Functions f;
    
    String os = System.getProperty("os");

    protected AppiumDriver getDriver() {
        return driverThreadLocal.get();
    }

    String email = "[email protected]";
    String pass = "Testgeslo123";

    //@BeforeAll
    @Before("@dashboard")
    public static void beforeAll() throws MalformedURLException {

        driver = driverSetup.getDriver();
        driverThreadLocal.set(driver);
        screen = new PageObjectManager(driver);
        f = new Functions(driver);
    }
    
    @Then("validate triglav komplet")
    public void validate_triglav_komplet() {

        screen.dashboardScreen().clickTriglavKomplet();

        screen.triglavKompletScreen().waitForTriglavKompletScreenToBeDisplayed();

        screen.dashboardBottomMenuScreen().clickDomovButton();
    }

    @Then("validate insurance card")
    public void validate_insurance_card() {

        screen.dashboardScreen().clickFirstInsuranceCard();

        screen.insuranceScreen().validateInsurancePageIsDisplayed();

        screen.dashboardBottomMenuScreen().clickDomovButton();
    }

    @Then("validate news card")
    public void validate_news_card() throws Exception {

        String newsText = screen.dashboardScreen().clickFirstNewsAndGetText();
        
        System.out.println("newsText");

        screen.newsScreen().validateTextMatches(newsText);

        screen.dashboardBottomMenuScreen().clickDomovButton();
    }

    @Given("user puts app in background")
    public void user_puts_app_in_background() {

        DriverSetup.backgroundApp(driver);
    }

    @Given("Verify entering incorrect security code displays an error message")
    public void verify_entering_incorrect_security_code_displays_an_error_message() throws Exception {

        screen.loginCodeScreen().waitForHeaderText();

        screen.loginCodeScreen().validateHeaderText();

        screen.loginCodeScreen().insertWrongCodeAndValidateResults();
    }

    @Then("Verify My profile page is accessible")
    public void verify_my_profile_page_is_accessible() {

        screen.dashboardScreen().clickProfilButton();

        screen.myProfile().validateElementsAreDisplayed();

        screen.dashboardBottomMenuScreen().clickDomovButton();
    }

    @Then("Verify Messages page is accessible")
    public void verify_messages_page_is_accessible() {

        screen.dashboardScreen().clickMessagesButton();

        screen.messagesScreen().validateTabsAreDisplayed();

        //f.clickArrowBack();
        screen.dashboardBottomMenuScreen().clickDomovButton();
    }

    @Then("Verify Notifications page is accessible")
    public void verify_notifications_page_is_accessible() {
        
        screen.dashboardScreen().clickNotificationsButton();

        screen.notificationsScreen().validateAllElementsAreDisplayed();
    }

    @Then("Verify entering four incorrect security codes logs the user out")
    public void verify_entering_four_incorrect_security_codes_logs_the_user_out() throws Exception {
        DriverSetup.backgroundApp(driver);

        screen.loginCodeScreen().waitForHeaderText();

        screen.loginCodeScreen().validateHeaderText();

        screen.loginCodeScreen().insertIncorrectCodeFourTimes();

        screen.welcomePageScreen().validateNadaljujButtonIsDisplayed();
    }
    
    @Attachment(value = "Screenshot", type = "image/png")
    public static void getScreenshot(WebDriver driver, Scenario scenario) {
          byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
          scenario.attach(screenshot, "image/png", scenario.getName());
    }
    
    //@AfterAll
    @After("@dashboard")
    public static void before_or_after_all(Scenario scenario) {
                
        
        if(scenario.isFailed()) {
        
            getScreenshot(driver, scenario);
        
        }
        driverSetup.quitDriver();
        driverThreadLocal.remove();
    }

}

My test runner class:

@RunWith(Cucumber.class)
@CucumberOptions(features = {
    "src/test/resources/Features/DashboardFeatures/dashboard.feature",

}, glue = "si.triglav.stepDefinitions",
   monochrome = true, tags = "not @Test")
public class TestRunner {

}

My pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company</groupId>
  <artifactId>projectName</artifactId>
  <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <allure.version>2.24.0</allure.version>
        <aspectj.version>1.9.20.1</aspectj.version>
        <appium.version>8.6.0</appium.version>
        <allure.version>2.24.0</allure.version>
        <aspectj.version>1.9.20.1</aspectj.version>
    </properties>

        <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.1.2</version>
                    <configuration>
                        <argLine>
                            -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                        </argLine>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjweaver</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <release>8</release>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
            </plugin>
            
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/resources/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                      <id>make-assembly</id> <!-- this is used for inheritance merges -->
                      <phase>package</phase> <!-- bind to the packaging phase -->
                      <goals>
                        <goal>single</goal>
                      </goals>
                    </execution>
                  </executions>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-bom</artifactId>
                <version>${allure.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        
        <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>${appium.version}</version>
        </dependency>
        
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-cucumber7-jvm</artifactId>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-junit-platform</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>7.15.0</version>
            <scope>test</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>7.15.0</version>
        </dependency>
        
                <!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>1.10.2</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.10.1</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng 
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.9.0</version>
        </dependency>
        -->

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.17.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.aeonbits.owner/owner -->
        <dependency>
            <groupId>org.aeonbits.owner</groupId>
            <artifactId>owner</artifactId>
            <version>1.0.12</version>
        </dependency>
        

    </dependencies>

</project>

Allure report output using allure serve:

allure screenshot

Can someone please help me with this... This is the only blocker I have atm and I really wanna get this done...

0

There are 0 best solutions below