java自动化之_Allur报表展示结果

本文介绍了如何在Java自动化测试中使用Allure报告,包括在pom.xml中导入Allur坐标和Surefire插件,以及通过命令展示报告结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、pom导入Allur坐标

<dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.13.5</version>
            <!--<scope>test</scope>-->
</dependency>

2、导入surefire插件

<build>
        <plugins>
            <plugin>
                <!-- maven-surefire-plugin 配合testng/junit执行测试用例的maven插件 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <!-- 测试失败后,是否忽略并继续测试 -->
                    <testFailureIgnore>true</testFailureIgnore>
                    <suiteXmlFiles>
                        <!-- testng配置文件名称  -->
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <!--设置参数命令行 -->
                    <argLine>
                        <!-- UTF-8编码 -->
                        -Dfile.encoding=UTF-8
                        <!-- 配置拦截器 -->
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <systemProperties>
                        <property>
                            <!-- 配置 allure 结果存储路径  -->
                            <name>allure.results.directory</name>
                            <value>${project.build.directory}/allure-results</value>
                        </property>
                    </systemProperties>
                </configuration>
                 <!--https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
                <dependencies>
                    <!-- aspectjweaver maven坐标 -->
                    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

3、上代码

package com.aosschool.wechatmini.listener;

import cn.hutool.core.io.FileUtil;
import com.aosschool.wechatmini.common.BasePage;
import io.qameta.allure.Attachment;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.testng.IHookCallBack;
import org.testng.IHookable;
import org.testng.ITestResult;

import java.io.File;

/**
 * @author: wuqi
 * @date: Created in 2021/6/8
 * @description:
 * @version:
 */
public class AllureScreenShotListener implements IHookable {


    @Override
    public void run(IHookCallBack iHookCallBack, ITestResult iTestResult) {
        iHookCallBack.runTestMethod(iTestResult);

        if (iTestResult.getThrowable()!=null){
            Object object = iTestResult.getInstance();

            BasePage basePage = (BasePage) object;//case对象强转成父类BaseCase,向上转型
            TakesScreenshot screenshot = (TakesScreenshot)basePage.androidDriver;

            byte[] screenshotAs = screenshot.getScreenshotAs(OutputType.BYTES);
            saveScreenShot(screenshotAs);

        }

    }

    @Attachment(value = "page screen", type = "image/png")
    public byte[] saveScreenShot(byte[] screenshot){
        return screenshot;
    }
}

io.qameta.allure:allure-maven:serve

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值