Capturing Java Script Errors

96 views
Skip to first unread message

dt_nz

unread,
Oct 8, 2009, 11:15:51 PM10/8/09
to Watir General
Hi
I was hoping someone could point me in the right direction to get some
help capturing java script errors. We have a rather large number of
tests that are executed during our regression run, and there can be a
significant amount of page reloads etc that sometimes cause java
script errors. In the past we have simply turned java scripts off
from popping up so our tests continue without stopping, and relied on
manual testing to pick the errors up.

Any help would be appreciated

Jarmo Pertman

unread,
Oct 9, 2009, 6:16:57 AM10/9/09
to Watir General
Hello.

We used AutoIt for opening the javascript error message window, then
make a screenshot of the error message itself and close the window,
not that IE js error messages would be useful on most of the times.
This is a little dirty hack, but it works for us sort of.

Jarmo

Bret Pettichord

unread,
Oct 10, 2009, 2:04:32 AM10/10/09
to watir-...@googlegroups.com
I would also be interested in a solution to this. Especially if it were
more elegant to Jarmo's solution. I'd really like to be able to pull the
text of the javascript error so i could post it to a log. Any one?

Bret
--
Bret Pettichord
Lead Developer, Watir, www.watir.com
Blog, www.io.com/~wazmo/blog
Twitter, www.twitter.com/bpettichord

Marlon MxM

unread,
Oct 11, 2009, 11:01:08 PM10/11/09
to watir-...@googlegroups.com
have you tried the solutions listed here http://wiki.openqa.org/display/WTR/Pop+Ups?

Bret Pettichord

unread,
Oct 11, 2009, 11:15:57 PM10/11/09
to watir-...@googlegroups.com
Marlon MxM wrote:
> have you tried the solutions listed here
> http://wiki.openqa.org/display/WTR/Pop+Ups?
Mostly that consists of variations on using AutoIt.

I'm looking for more creative approaches.

E.g. as regards this dialog:
http://wiki.openqa.org/display/WTR/Security+Information

I got rid of this simply by changing the security setting of the browser
(manually) to stop displaying this window.

I know that there must be some hook that is available to trap the
javascript errors. If you have Visual Studio installed, instead of
getting this dialog, the visual studio debugger is started up. So there
is a hook there.

I was thinking it would be cool to hook in our own code to that hook,
and was wondering if any one had already done this.

Bret

Pallavi Sharma

unread,
Oct 14, 2009, 9:23:34 AM10/14/09
to watir-...@googlegroups.com
Hi Jarmo

Can you share the code for the AutoIt if its not an issue. I would be interested in something similar for our work.

Pallavi Sharma

unread,
Oct 14, 2009, 9:24:27 AM10/14/09
to watir-...@googlegroups.com
Hi Bret

Is there a way in watir I can fetch the warning message which appears in the status bar of IE during a JS error?

Can that be a solution for this issue?

Please let me know.

Thanks

Pallavi.

Bret Pettichord

unread,
Oct 14, 2009, 10:18:58 AM10/14/09
to watir-...@googlegroups.com
Good idea. "browser.status" will report the status message. Could you
check this out and let us know if it has promise?

Bret
> Lead Developer, Watir, www.watir.com <http://www.watir.com>
> Blog, www.io.com/~wazmo/blog <http://www.io.com/%7Ewazmo/blog>
> Twitter, www.twitter.com/bpettichord
> <http://www.twitter.com/bpettichord>
>
>
>
>
>
> >

Paul Rogers

unread,
Oct 14, 2009, 10:36:41 AM10/14/09
to watir-...@googlegroups.com
i tried this aqpproach a long time ago, and it didnt work if I remember. I have recollections of trying to see if the js error icon was there too.  think in the end I just switched 'display js errors' on so the test would stop if there was an error.

Paul

Rohan Ojha

unread,
Oct 14, 2009, 11:32:58 PM10/14/09
to watir-...@googlegroups.com

Hi,

 

The AutoIt code to check for the pop-up text is as follows:

 

Code courtesy: http://altentee.com/watir/

 

 

require 'watir'
require 'rubygems'
require 'win32ole'
autoit = WIN32OLE.new('AutoItX3.Control') 
@b.goto('http://justaddwatir.com/watir/test_html/tc_0101_0200/test_0107.html')
@b.text_field(:name,"text1").set("This is the text in the popup")
@b.button(:name,"submit").click_no_wait
autoit.WinWaitActive("[Class:#32770]")
text = autoit.ControlGetText("[Class:#32770]", "", "Static2")
autoit.ControlClick("[Class:#32770]","","Button1")
puts text

 

 

 

Thanks,
Rohan Ojha
 
Blue Star Infotech lÈ+91 900 4955058l ( +91 22 6688 6969 l 6 +91 22 6688 6999 l * rohan...@bsil.com
 
www.bsil.com
- Where Partnerships Are Built on Trust

 

 


Jarmo Pertman

unread,
Oct 15, 2009, 9:07:36 AM10/15/09
to Watir General
Hello.

I've created something like this. Commented it also to make it more
obvious. You should create method for saving screenshots also. Hope it
helps.

def save_javascript_error
if $browser.is_a?(Watir::IE) && $browser.getIE.StatusText =~ /Error
on page/
$autoit.AutoItSetOption("MouseCoordMode", 0) # set mouse
coordinates to be treated relative to active window
$autoit.ControlClick("[TITLE:#{$browser.title}]", "",
"[CLASS:msctls_statusbar32]", "left", 2) # perform double click on
statusbar
$autoit.WinWait("Internet Explorer", "", 10) # wait for javascript
error details window to open
puts "save screenshot" # with win32screenshot
$autoit.WinClose("Internet Explorer") #close popup window
end
end

$browser = Watir::IE.attach :url, //
$browser.button(:id => 'button').click
save_javascript_error

On Oct 14, 4:23 pm, Pallavi Sharma <write2pall...@gmail.com> wrote:
> Hi Jarmo
> Can you share the code for the AutoIt if its not an issue. I would be
> interested in something similar for our work.
>
> On Fri, Oct 9, 2009 at 3:46 PM, Jarmo Pertman <jarm...@gmail.com> wrote:
>
> > Hello.

dt_nz

unread,
Oct 15, 2009, 10:30:57 PM10/15/09
to Watir General
Hi
To capture a java script error, how do you call theses methods. Do
you have a separate thread that is always running
save_javascript_error in a loop, or is save_javascript_error called
after each action on a page?

We have an existing framework that runs a lot of tests in our
regression runs and am ideally looking for a solution to incorporate
it into our existing structure.

Jarmo Pertman

unread,
Oct 16, 2009, 5:44:18 AM10/16/09
to Watir General
We are using RSpec to run our tests (http://rspec.info) and I've
created my own HTMLFormatter class which extends their
Spec::Runner::Formatter::HtmlFormatte and then using
#extra_failure_content method, which will be invoked if some test
fails by RSpec itself. So, if test fails, I'm also checking if page
had any JS errors and then make a screenshot of it. Otherwise (if test
passes) JS errors will be ignored.

Jarmo

Alan Baird

unread,
Oct 17, 2009, 4:21:19 PM10/17/09
to watir-...@googlegroups.com
Jarmo -

I would be interested in seeing an example of your Formatter.  I know there is one already out there from the RSpec team, but if you have something different and the time I think it would make a great blog post or addition to the wiki.

Alan

Pallavi Sharma

unread,
Oct 19, 2009, 2:01:37 AM10/19/09
to watir-...@googlegroups.com
Hi Everyone


for reporting JS error, has anyone here tried this.


Also please let me know if the alert message for JS in the browser is off, is there a way i can still detect the error in the browsers?

Please let me know.


Thanks

Pallavi.

Bret Pettichord

unread,
Oct 21, 2009, 12:42:00 AM10/21/09
to watir-...@googlegroups.com
Pallavi,

Thanks for posting that. This is new to me, but it looks like a good
solution.

Bret
> <mailto:david.tay...@sungard.com>> wrote:
> > Hi
> > To capture a java script error, how do you call theses
> methods. Do
> > you have a separate thread that is always running
> > save_javascript_error in a loop, or is save_javascript_error
> called
> > after each action on a page?
> >
> > We have an existing framework that runs a lot of tests in our
> > regression runs and am ideally looking for a solution to
> incorporate
> > it into our existing structure.
>
>
>
>
>
>
> >


--
Bret Pettichord
Lead Developer, Watir, www.watir.com
Blog, www.io.com/~wazmo/blog
Twitter, www.twitter.com/bpettichord

Reply all
Reply to author
Forward
0 new messages