Question: dump the current dom tree of a page into system.out

5 views
Skip to first unread message

clemens...@gmail.com

unread,
Nov 10, 2020, 6:33:13 AM11/10/20
to Geb User Mailing List
Dear all,
we have a requirement (for official documentation) - to dump the current dom tree that is the basis of various test assertions into system out. 

Anyone an idea on how to do this ... (preferrably in a formatted ("with intends") way ..

thanks much

Marcin Erdmann

unread,
Nov 10, 2020, 6:41:11 AM11/10/20
to geb-...@googlegroups.com
Can you please define what you mean by "current dom tree"? Do you mean page source? Or do you mean inner html of some of the elements you inspect in your test?

Marcin

--
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/2d687da9-5386-4052-9581-69136bee3776n%40googlegroups.com.

clemens utschig

unread,
Nov 10, 2020, 2:14:08 PM11/10/20
to geb-...@googlegroups.com
The current (fully rendered?) page that is used in my test..

So if i have an assertion, e.g. $some.path == 1, i can find that *some.path* in the dump (that will serve as evidence to an auditor that the assertion part and value truly existed at the point of test)

Please lets not argue about the why here. Its a hard requirement



Marcin Erdmann

unread,
Nov 12, 2020, 4:09:26 AM11/12/20
to geb-...@googlegroups.com
I was by no means arguing the why, I just needed some clarification on what exactly you are after.

If it's the html of the whole page then you can use WebDriver.getPageSource() (https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebDriver.html#getPageSource--). You can obtain an instance of WebDriver from Browser.getDriver() (https://gebish.org/manual/current/api/geb/Browser.html#getDriver()).

Marcin

clemens utschig

unread,
Nov 12, 2020, 4:12:06 AM11/12/20
to geb-...@googlegroups.com
Hey Marcin- Thanks much. Will this also contain any modified dom elements?

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/JQpKgvzxIb8/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/CA%2B52dQQByx5F7KvEZQ%2Bva9rQTo6vdkttYOzHs2S4Mb_wRnK%3Daw%40mail.gmail.com.

clemens utschig

unread,
Nov 12, 2020, 4:19:21 AM11/12/20
to geb-...@googlegroups.com
(e.g. because the page is based on a dom modifying framework, e.g. react) ... the key is to get the "thing" (in a human readable fashion) that is the basis of the assertion .. 

clemens...@gmail.com

unread,
Nov 16, 2020, 7:20:22 AM11/16/20
to Geb User Mailing List
Marcin - we found a way .. - pretty much thru Navigator:children / .text &.value ... with a recursive strategy ... maybe we could add that to the Navigator (e.g. printContentRecursively(....))

Marcin Erdmann

unread,
Nov 16, 2020, 8:27:11 AM11/16/20
to geb-...@googlegroups.com
Wouldn't using Element.innerHtml (https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML) over Geb's javascript integration (https://gebish.org/manual/current/#js-object) be a simpler solution?

Reply all
Reply to author
Forward
0 new messages