没有在移动 ios 魅力报告中获取屏幕截图
Posted
技术标签:
【中文标题】没有在移动 ios 魅力报告中获取屏幕截图【英文标题】:Not getting screenshot in mobile ios allure reports 【发布时间】:2021-09-11 10:29:18 【问题描述】:我尝试在 ios 真实设备上使用 Appium 在我的魅力报告中截取屏幕截图,但我没有得到它,我所做的是: 在我的 mainRunner 中:
@Listeners( utilities.AllureListeners.class )
在我的 Allurelisteners 中:
public class AllureListeners implements ITestListener
IOSBaseTest iosBaseTest = new IOSBaseTest();
public void onTestStart(ITestContext iTestContext)
System.out.println("I am on start method "+ iTestContext.getName());
iTestContext.setAttribute("Driver", iosBaseTest.driver);
@Override
public void onTestSuccess(ITestResult result)
System.out.println("I am on start method "+ getTestMethodName(result));
@Override
public void onTestFailure(ITestResult result)
System.out.println("I am on testFailure method " + getTestMethodName(result)+" failed");
//Object testClass = result.getInstance();
//ITestContext context = result.getTestContext();
//WebDriver driver = (WebDriver) context.getAttribute("driver");
IOSDriver<MobileElement> driver = iosBaseTest.getdriver();
if (driver instanceof WebDriver)
System.out.println("Screenshot captured for test case: "+getTestMethodName(result));
saveFailureScreenShot(driver);
saveTextLog(getTestMethodName(result) + "failed and screenshot taken!");
@Override
public void onTestSkipped(ITestResult result)
System.out.println("I am on test skipped method "+getTestMethodName(result)+" skipped");
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result)
@Override
public void onTestFailedWithTimeout(ITestResult result)
@Override
public void onStart(ITestContext context)
@Override
public void onFinish(ITestContext context)
private static String getTestMethodName(ITestResult iTestResult)
return iTestResult.getMethod().getConstructorOrMethod().getName();
// Screenshot attachments for allure
@Attachment (value ="page screenshot", type = "image/png")
public byte[] saveFailureScreenShot(WebDriver driver)
return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
// Text attachments for allure
@Attachment(value= "0", type = "text/plain")
public static String saveTextLog(String message)
return message;
//html attachments for allure
@Attachment(value= "0", type = "text/html")
public static String attachHtml(String html)
return html;
在我的基础测试中,我有方法:
public IOSDriver<MobileElement> getdriver()
return driver;
我的 xml 是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<listeners>
<listener class-name="utilities.AllureListeners" />
</listeners>
<test name="tester">
<groups>
<run>
<include name="add favorite contact" />
</run>
</groups>
<classes>
<class name="tests.IOSMainRunner">
</class>
</classes>
</test>
</suite>
但我的报告看起来没有屏幕截图:
【问题讨论】:
【参考方案1】:试试这个。
public void allureSaveDeviceScreenshot()
Allure.addAttachment("screenshot", new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES)));
【讨论】:
以上是关于没有在移动 ios 魅力报告中获取屏幕截图的主要内容,如果未能解决你的问题,请参考以下文章