我在使用jenkins连接由诱惑力生成的报告中的屏幕截图时遇到问题。 1.我有一个名为ListenersT
的接口package Test;
import Test.resources.Base;
import io.qameta.allure.Allure;
import io.qameta.allure.Attachment;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class ListenersT extends Base implements ITestListener {
Base b = new Base();
public void onFinish(ITestContext arg0) {
// TODO Auto-generated method stub
}
public void onStart(ITestContext arg0) {
// TODO Auto-generated method stub
}
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestFailure(ITestResult result) {
// TODO Auto-generated method stub
//screenshot
try {
b.getScreenshot(result.getName());
} catch (IOException e) {
e.printStackTrace();
}
Object testClass = result.getInstance();
WebDriver driver = ((Base) testClass).getDriver();
if(driver instanceof WebDriver) {
takeScreenshot(driver);
}
}
@Attachment
public byte[] takeScreenshot(WebDriver driver) {
return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
}
public void onTestSkipped(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestStart(ITestResult arg0) {
// TODO Auto-generated method stub
}
public void onTestSuccess(ITestResult arg0) {
// TODO Auto-generated method stub
}
}
我在此处附有屏幕截图支持
在每个测试中,侦听器“ @Listeners({ListenersT.class})”已添加到开头。
@Listeners({ListenersT.class})
仍然,在生成的报告中看不到屏幕截图
请帮助。