Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

selenium - Allure generates a viewport screenshot. how to capture a screenshot of the entire document

I am working with Java, TestNG, Selenium and Allure.
And I want to attach the screenshot of 'entire page' in the case of test failure.
But when using 'getScreenshotAs()' method, it attaches only the 'visible viewport' screenshot in the report. partially successful :)

@Attachment(value="Page Screenshot", type="image/png")
public byte[] saveScreenshotPNG(WebDriver driver) {
    return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
} 

And I am not very sure if AShot from ru.yandex.qatools could be helpful here,
As it returns Screenshot not Byte[].


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This should capture the whole page:

Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(2000)).takeScreenshot(driver);
BufferedImage image = screenshot.getImage();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...