Take screenshot of entire page

20 views
Skip to first unread message

Ben Frey

unread,
Dec 9, 2020, 9:22:55 AM12/9/20
to Geb User Mailing List
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?

Marcin Erdmann

unread,
Dec 9, 2020, 4:00:08 PM12/9/20
to geb-...@googlegroups.com
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 <sparta...@gmail.com> 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 geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/a303727c-5c40-448d-b194-579feaf4a436n%40googlegroups.com.

Ben Frey

unread,
Dec 9, 2020, 4:04:21 PM12/9/20
to Geb User Mailing List
Thanks, I'll see if AShot is an option.

Ben Frey

unread,
Dec 10, 2020, 8:16:45 AM12/10/20
to Geb User Mailing List
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?

Ben Frey

unread,
Dec 10, 2020, 9:38:16 AM12/10/20
to Geb User Mailing List
Ahh, apparently it's as easy as adding a line to GebConfig.groovy:
reporter = new ScreenshotReporter()

jc

unread,
Dec 10, 2020, 9:42:16 AM12/10/20
to Geb User Mailing List
Hey Ben,
I'd be interested to see how you implemented this if you would be willing to share some of the code?

Ben Frey

unread,
Dec 10, 2020, 10:07:42 AM12/10/20
to Geb User Mailing List
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 }
    }
}

Alexander Kriegisch

unread,
Dec 10, 2020, 8:58:39 PM12/10/20
to geb-...@googlegroups.com
Ben, this would be a great addition to a hypothetical Geb FAQ or
knowledge base. I remember that 1-2 years ago I played around with AShot
for half a day or so in order to answer a similar question, maybe on
StackOverflow, I do not quite remember. But I seem to recall that I had
some cross-browser issues with AShot. How broadly did you test your
reporter in that regard? Just being curious.

--
Alexander Kriegisch
https://scrum-master.de
>>>>>>> <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 geb-user+u...@googlegroups.com
> <mailto:geb-user+u...@googlegroups.com> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/geb-user/1ca8028d-d2d6-4551-9b7e-fea95c434397n%40googlegroups.com
> <https://groups.google.com/d/msgid/geb-user/1ca8028d-d2d6-4551-9b7e-fea95c434397n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .

Ben Frey

unread,
Dec 10, 2020, 9:02:20 PM12/10/20
to geb-...@googlegroups.com
Just with Chrome. I'm working on transitioning regression scripts from Selenium, so I really only need one browser. A teammate is helping investigate running it on my company's SauceLabs instance. If that pans out, I'll try throwing a few other browsers at it and see how AShot works. 

You received this message because you are subscribed to a topic in the Google Groups "Geb User Mailing List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/geb-user/HHcecs4twpw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/20201211015837.AAB5E3380730%40dd39516.kasserver.com.

Alexander Kriegisch

unread,
Dec 10, 2020, 9:14:11 PM12/10/20
to geb-...@googlegroups.com
Hm, maybe I remembered wrong or there used to be IE issues. I just found
my old AShot test, taking screenshots of the full page, a group of
selected elements and a single element onthe page, all runf fine in
PhantomJS, Chrome, Chrome Headless, Firefox, Edge (Chromium), Opera. I
did not use your reporter, just called AShot from my old test. IE test
did not start, but that was probably rather a webdriver than an AShot
problem.

Thanks for reminding me of AShot again, just in case I ever need it.
Then maybe I shall use your custom reporter. :-)

--
Alexander Kriegisch
https://scrum-master.de

Ben Frey schrieb am 11.12.2020 09:02 (GMT +07:00):
>
> Just with Chrome. I'm working on transitioning regression scripts from
> Selenium, so I really only need one browser. A teammate is helping
> investigate running it on my company's SauceLabs instance. If that pans
> out, I'll try throwing a few other browsers at it and see how AShot works.
>
>
> On Thu, Dec 10, 2020, 8:58 PM Alexander Kriegisch
> <alex...@kriegisch.name <mailto:alex...@kriegisch.name>
>> >>>>> marcin....@proxerd.pl <mailto:marcin....@proxerd.pl>
>> <mailto:geb-user%2Bu...@googlegroups.com> .
>> >>>>>>> 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 geb-user+u...@googlegroups.com
>> <mailto:geb-user%2Bunsu...@googlegroups.com>
>> > <mailto:geb-user+u...@googlegroups.com
>> <mailto:geb-user%2Bunsu...@googlegroups.com> > .
>> > To view this discussion on the web visit
>> >
>> https://groups.google.com/d/msgid/geb-user/1ca8028d-d2d6-4551-9b7e-fea95c434397n%40googlegroups.com
>> >
>> <https://groups.google.com/d/msgid/geb-user/1ca8028d-d2d6-4551-9b7e-fea95c434397n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> > .
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Geb User Mailing List" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/geb-user/HHcecs4twpw/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> geb-user+u...@googlegroups.com
>> <mailto:geb-user%2Bunsu...@googlegroups.com> .
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/geb-user/20201211015837.AAB5E3380730%40dd39516.kasserver.com.
>
> --
> 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 geb-user+u...@googlegroups.com
> <mailto:geb-user+u...@googlegroups.com> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/geb-user/CAG7nOphz8GjSKC%3DAzohN3cqL7Ydq-3V2RheWnGvxBFmLX3uxAQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/geb-user/CAG7nOphz8GjSKC%3DAzohN3cqL7Ydq-3V2RheWnGvxBFmLX3uxAQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .

Alexander Kriegisch

unread,
Dec 10, 2020, 9:17:54 PM12/10/20
to geb-...@googlegroups.com
Okay, re-checked IE: It is an AShot issue, browser starts and default
Geb screenshot (viewport-sized) works. So that was maybe what I
remembered. (Don't say it: We all hate IE and the fact that some of us
even still have to support it. I don't have to, but some of the teams I
coach do.)


Alexander Kriegisch schrieb am 11.12.2020 09:14 (GMT +07:00):

> Hm, maybe I remembered wrong or there used to be IE issues. I just found
> my old AShot test, taking screenshots of the full page, a group of
> selected elements and a single element onthe page, all runf fine in
> PhantomJS, Chrome, Chrome Headless, Firefox, Edge (Chromium), Opera. I
> did not use your reporter, just called AShot from my old test. IE test
> did not start, but that was probably rather a webdriver than an AShot
> problem.
>
> Thanks for reminding me of AShot again, just in case I ever need it.
> Then maybe I shall use your custom reporter. :-)
>
>
> Ben Frey schrieb am 11.12.2020 09:02 (GMT +07:00):
>>
>> Just with Chrome. I'm working on transitioning regression scripts from
>> Selenium, so I really only need one browser. A teammate is helping
>> investigate running it on my company's SauceLabs instance. If that pans
>> out, I'll try throwing a few other browsers at it and see how AShot works.
>>
>>
>> On Thu, Dec 10, 2020, 8:58 PM Alexander Kriegisch
>> <alex...@kriegisch.name <mailto:alex...@kriegisch.name>
>> > wrote:
>>
>>> Ben, this would be a great addition to a hypothetical Geb FAQ or
>>> knowledge base. I remember that 1-2 years ago I played around with AShot
>>> for half a day or so in order to answer a similar question, maybe on
>>> StackOverflow, I do not quite remember. But I seem to recall that I had
>>> some cross-browser issues with AShot. How broadly did you test your
>>> reporter in that regard? Just being curious.
>>>
>>>
> to geb-user+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/geb-user/20201211021408.E51E0338084F%40dd39516.kasserver.com.
>
>
Reply all
Reply to author
Forward
0 new messages