0
0
Selenium Javatesting~10 mins

Allure reporting integration in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a web page, clicks a button, and verifies the result. It uses Allure annotations to add detailed reporting information.

Test Code - JUnit + Selenium + Allure
Selenium Java
import io.qameta.allure.Description;
import io.qameta.allure.Step;
import io.qameta.allure.junit4.DisplayName;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class AllureReportingTest {
    private WebDriver driver;

    @Before
    public void setUp() {
        driver = new ChromeDriver();
    }

    @Test
    @DisplayName("Verify button click changes text")
    @Description("Open the page, click the button, and check if the text changes as expected.")
    public void testButtonClickChangesText() {
        openPage("https://example.com/buttonpage");
        clickButton(By.id("change-text-btn"));
        verifyText(By.id("text-element"), "Text changed!");
    }

    @Step("Open page {url}")
    public void openPage(String url) {
        driver.get(url);
    }

    @Step("Click button located by {by}")
    public void clickButton(By by) {
        WebElement button = driver.findElement(by);
        button.click();
    }

    @Step("Verify element located by {by} has text '{expectedText}'")
    public void verifyText(By by, String expectedText) {
        WebElement element = driver.findElement(by);
        String actualText = element.getText();
        Assert.assertEquals(expectedText, actualText);
    }

    @After
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test startsJUnit test runner initializes the test class-PASS
2Browser opens ChromeDriverChrome browser window opens, ready for commands-PASS
3Navigates to https://example.com/buttonpageBrowser loads the page with a button and a text element-PASS
4Finds button element by id 'change-text-btn'Button element is present and visible on the page-PASS
5Clicks the buttonButton click triggers text change on the page-PASS
6Finds text element by id 'text-element'Text element is present on the page-PASS
7Checks if text element's text equals 'Text changed!'Text element's text is 'Text changed!'Assert.assertEquals("Text changed!", actualText)PASS
8Test ends and browser closesBrowser window closes, test resources cleaned-PASS
Failure Scenario
Failing Condition: Button element with id 'change-text-btn' is not found on the page
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the button?
AThe text of an element changes to 'Text changed!'
BThe button becomes disabled
CA new page loads
DAn alert popup appears
Key Result
Using Allure annotations like @Step and @Description helps create clear, readable reports that show each test action and its purpose, making debugging easier.