Friday, January 20, 2023

allure reports

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.qameta.allure.Allure;
import io.qameta.allure.Step;
import io.qameta.allure.model.Status;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class SeleniumAllureTest {
    WebDriver driver;

    @BeforeClass
    public void setUp() {
        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
        driver = new ChromeDriver();
    }

    @Test
    public void testGoogleSearch() {
        // Allure report at the class level
        Allure.createTest("Search Google for Allure")
                .description("This test searches for the Allure framework on Google")
                .startStep("Open Google home page")
                .addAttachment("Google home page", "image/png", driver.getScreenshotAs(OutputType.BYTES))
                .step("Search for Allure")
                .step("Validate search results")
                .status(Status.PASSED)
                .startStep("Open Google home page")
                .addAttachment("Google home page", "image/png", driver.getScreenshotAs(OutputType.BYTES))
                .step("Search for Allure")
                .step("Validate search results")
                .status(Status.PASSED);

        driver.get("https://www.google.com");

        // Allure report at the page level
        Allure.step("Open Google home page", () -> {
            Allure.addAttachment("Google home page", "image/png", driver.getScreenshotAs(OutputType.BYTES));
        });

        Allure.step("Search for Allure", () -> {
            // perform search
        });

        Allure.step("Validate search results", () -> {
            // validate search results
        });
    }

    @AfterClass
    public void tearDown() {
        driver.quit();
    }
}

No comments:

Post a Comment