Debugging Javascript in HtmlUnit

1,269 views
Skip to first unread message

Bob Silverberg

unread,
Jun 1, 2012, 7:02:24 AM6/1/12
to selenium-...@googlegroups.com
I'm looking into adding the color standardization behaviour [1] into the HtmlUnit driver which was done for the atoms.  Tracing through the test at [2], it seems that the Javascript that is executed (which is defined at [3]) is returning null. To me this says that I need to start debugging the js itself and I'm not sure how to do that.

With any other browser I'd just open the browser and start debugging, but I'm not sure how to do that with HtmlUnit. I assume that there's a way of debugging js running in HtmlUnit, and I'm hoping someone can steer me in the right direction.

Thanks for any help you can provide,
Bob

[1] https://code.google.com/p/selenium/issues/detail?id=1885
[2] https://code.google.com/p/selenium/source/browse/trunk/java/client/test/org/openqa/selenium/RenderedWebElementTest.java#48
[3] https://code.google.com/p/selenium/source/browse/trunk/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java#875

--
Bob Silverberg
www.silverwareconsulting.com


--
Bob Silverberg
www.silverwareconsulting.com

Jason Leyba

unread,
Jun 1, 2012, 4:36:32 PM6/1/12
to selenium-...@googlegroups.com
In my experience, you don't.  HtmlUnit strips out the few hooks Rhino has for debugging.  There might be a global "print" function (I don't remember if console exists).

For HtmlUnit, I would just pull the color out and do all your parsing in Java.




--
Bob Silverberg
www.silverwareconsulting.com

--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To post to this group, send email to selenium-...@googlegroups.com.
To unsubscribe from this group, send email to selenium-develo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-developers?hl=en.

Bob Silverberg

unread,
Jun 3, 2012, 9:37:32 PM6/3/12
to selenium-...@googlegroups.com
Thanks Jason. It turns out there was something strange going on in my
test, as when I tested again today I am no longer getting null
returned, but rather the expected color value.

I have another question specific to color conversion for htmlunit
which I am going to post separately.

Bob

On Fri, Jun 1, 2012 at 4:36 PM, Jason Leyba <jml...@gmail.com> wrote:
> In my experience, you don't.  HtmlUnit strips out the few hooks Rhino has
> for debugging.  There might be a global "print" function (I don't remember
> if console exists).
>
> For HtmlUnit, I would just pull the color out and do all your parsing in
> Java.
>


--
Bob Silverberg
www.silverwareconsulting.com

Marc Guillemot

unread,
Jun 1, 2012, 7:18:08 AM6/1/12
to selenium-...@googlegroups.com
Hi,

if you have access to the underlying WebClient, you can call

com.gargoylesoftware.htmlunit.util.WebClientUtils.attachVisualDebugger(webClient)

this will start Rhino's visual debugger.

In fact the JS code in HtmlUnitWebElement could/should probably better
be replaced by direct calls to HtmlUnit's Java methods.

Cheers,
Marc.
--
HtmlUnit support & consulting from the source
Blog: http://mguillem.wordpress.com


Le 01/06/2012 13:02, Bob Silverberg a �crit :
> www.silverwareconsulting.com <http://www.silverwareconsulting.com>
Reply all
Reply to author
Forward
0 new messages