I can't create a gist on GitHub from work, so I'll have to share the code
here, which totally borks formatting; sorry in advance.
class ScreenshotReporter extends ReporterSupport implements Reporter {
private def aShot = new AShot()
@Override
void writeReport(ReportState reportState) {
def screenshot =
aShot.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(reportState.browser.driver)
def outputStream = new ByteArrayOutputStream()
ImageIO.write(screenshot.getImage(), 'png', outputStream)
saveScreenshotPngBytes(reportState.outputDir, reportState.label,
outputStream.toByteArray())
}
@Override
void addListener(ReportingListener listener) {
// No need to have listeners
}
protected void saveScreenshotPngBytes(File outputDir, String label,
byte[] bytes) {
def file = getFile(outputDir, label, 'png')
file.withOutputStream { it << bytes }
}
}
On Thursday, December 10, 2020 at 9:42:16 AM UTC-5 jc wrote:
> Hey Ben,
> I'd be interested to see how you implemented this if you would be willing
> to share some of the code?
>
> On Thursday, December 10, 2020 at 8:38:16 AM UTC-6 Ben Frey wrote:
>
>> Ahh, apparently it's as easy as adding a line to GebConfig.groovy:
>> reporter = new ScreenshotReporter()
>>
>> On Thursday, December 10, 2020 at 8:16:45 AM UTC-5 Ben Frey wrote:
>>
>>> Alright, I think I can figure out how to implement the Reporter
>>> interface, but I don't know how to register that reporter with the
>>> browser/driver so that the report command uses that Reporter. How is that
>>> done?
>>>
>>> On Wednesday, December 9, 2020 at 4:04:21 PM UTC-5 Ben Frey wrote:
>>>
>>>> Thanks, I'll see if AShot is an option.
>>>>
>>>> On Wednesday, December 9, 2020 at 4:00:08 PM UTC-5
>>>> [email protected] wrote:
>>>>
>>>>> I believe this is WebDriver implementation specific. I know that
>>>>> Firefox, at least at some point in the past, would take screenshots of
>>>>> the
>>>>> whole page and not just the viewport and that's what would end up in Geb
>>>>> reports when using Firefox as the browser. If you would like a cross
>>>>> browser solution for that then you need to write a custom reporter which
>>>>> would employ something like AShot(https://github.com/pazone/ashot).
>>>>> This section of their docs might be helpful:
>>>>> https://github.com/pazone/ashot#capturing-the-entire-page.
>>>>>
>>>>> On Wed, Dec 9, 2020 at 2:22 PM Ben Frey <[email protected]> wrote:
>>>>>
>>>>>> Currently, when using the default reporter, the report command
>>>>>> results in a screenshot of the current viewport. Is there a way to
>>>>>> capture
>>>>>> the entire rendered page without manual scrolling?
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Geb User Mailing List" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/geb-user/a303727c-5c40-448d-b194-579feaf4a436n%40googlegroups.com
>>>>>>
>>>>>> <https://groups.google.com/d/msgid/geb-user/a303727c-5c40-448d-b194-579feaf4a436n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>>
--
You received this message because you are subscribed to the Google Groups "Geb
User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/geb-user/1ca8028d-d2d6-4551-9b7e-fea95c434397n%40googlegroups.com.