Win32OLE: Is getting MSIE HTTP status possible?

Hi,

I’m using Ruby, Win32OLE, Microsoft Internet Explorer and Test::Unit
to automate web testing (hopefully to eliminate any need for our team
to use WinRunner + WebTest for most of our testing).

Is there any way to get the HTTP status code from IE through COM?
As in, to tell if the page displayed was HTTP status 200 OK vs.
404 Not Found or 500 Server Error, etc.?

Parsing the displayed page works in the specific case, but not in
the general case – where we may not be able to control the 404
display, or the 404 page is a javascript or meta-refresh redirect
to another page. I still need to know that the original URL that
was navigated to returned HTTP status 404 from the webserver.

I think I’m out of luck here, but I figured I’d ask the gurus
first, before giving up hope.

– Dossy

···


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Hi,

I’m using Ruby, Win32OLE, Microsoft Internet Explorer and Test::Unit
to automate web testing (hopefully to eliminate any need for our team
to use WinRunner + WebTest for most of our testing).

Is there any way to get the HTTP status code from IE through COM?
As in, to tell if the page displayed was HTTP status 200 OK vs.
404 Not Found or 500 Server Error, etc.?

Could you pass all requests and responses through a proxy filter that simply
records what it sees, and then passes everything on? You would get all the
raw headers and such before IE decides to do anything with the response.

James

“Dossy” dossy@panoptic.com wrote in message
news:20020716172105.GJ2284@panoptic.com

Hi,

I’m using Ruby, Win32OLE, Microsoft Internet Explorer and Test::Unit
to automate web testing (hopefully to eliminate any need for our team
to use WinRunner + WebTest for most of our testing).

Is there any way to get the HTTP status code from IE through COM?
As in, to tell if the page displayed was HTTP status 200 OK vs.
404 Not Found or 500 Server Error, etc.?

Parsing the displayed page works in the specific case, but not in
the general case – where we may not be able to control the 404
display, or the 404 page is a javascript or meta-refresh redirect
to another page. I still need to know that the original URL that
was navigated to returned HTTP status 404 from the webserver.

I think I’m out of luck here, but I figured I’d ask the gurus
first, before giving up hope.

– Dossy


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I think its kinda strange to use Ruby to do this, but to each his own.

For further questions regarding IE/automation I would recommend going to an
IE/vbcript newsgroup.

That said, the following vbscript code does what you want:

set oHTTP = CreateObject (“msxml2.XMLHTTP”)

oHTTP.open “GET”, “http://www.yahoo.com/”, false
oHTTP.send sRequest

Wscript.echo "Status = " & oHTTP.status
Rem Wscript.echo oHTTP.responseText

It uses the msxml component. I did not have a sample for how to do this
with the internet explorer control per se. That information, if it exists,
will be available by asking in an IE programming newsgroup.

HTH John.

Then the challenge becomes automating communication between the
Test::Unit tests and this “proxy” mechanism that you’re talking
about.

– Dossy

···

On 2002.07.17, james@rubyxml.com james@rubyxml.com wrote:

Could you pass all requests and responses through a proxy filter that simply
records what it sees, and then passes everything on? You would get all the
raw headers and such before IE decides to do anything with the response.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I think its kinda strange to use Ruby to do this, but to each his own.

What do you recommend?

For further questions regarding IE/automation I would recommend going to an
IE/vbcript newsgroup.

Thanks. Can you recommend one?

That said, the following vbscript code does what you want:

set oHTTP = CreateObject (“msxml2.XMLHTTP”)

oHTTP.open “GET”, “http://www.yahoo.com/”, false
oHTTP.send sRequest

Wscript.echo "Status = " & oHTTP.status
Rem Wscript.echo oHTTP.responseText

It uses the msxml component. I did not have a sample for how to do this
with the internet explorer control per se. That information, if it exists,
will be available by asking in an IE programming newsgroup.

I know how to perform an HTTP request and get the status. I know
how to automate and control IE via COM. What I don’t know is how
to get the status from IE via COM.

I don’t want to hit every URL twice – once to get the status and
a second time to test via automated IE.

– Dossy

···

On 2002.07.17, John nojgoalbyspam@hotmail.com wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

“Dossy” dossy@panoptic.com wrote in message
news:20020716180059.GN2284@panoptic.com

I think its kinda strange to use Ruby to do this, but to each his own.

What do you recommend?

For further questions regarding IE/automation I would recommend going to
an

IE/vbcript newsgroup.

Thanks. Can you recommend one?

That said, the following vbscript code does what you want:

set oHTTP = CreateObject (“msxml2.XMLHTTP”)

oHTTP.open “GET”, “http://www.yahoo.com/”, false
oHTTP.send sRequest

Wscript.echo "Status = " & oHTTP.status
Rem Wscript.echo oHTTP.responseText

It uses the msxml component. I did not have a sample for how to do this
with the internet explorer control per se. That information, if it
exists,

will be available by asking in an IE programming newsgroup.

I know how to perform an HTTP request and get the status. I know
how to automate and control IE via COM. What I don’t know is how
to get the status from IE via COM.

I don’t want to hit every URL twice – once to get the status and
a second time to test via automated IE.

– Dossy


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I would have assumed that you would use vbscript/jscript from windows script
host before Ruby. It doesn’t make a lot of difference. I sure would prefer
to use Ruby where possible :-).

I don’t go to these groups, but from their titles they would be a good place
to start:
microsoft.public.scripting.vbscript
microsoft.public.inetexplorer.scripting

I don’t think that you can get the status code from the IE COM object. That
is why I gave a different sample. I assume you want the IE object model
which is why you would then need to do 2 requests.

If you find a way to do this at a different group would you mind responding
to this thread with the answer?

John.

···

On 2002.07.17, John nojgoalbyspam@hotmail.com wrote:

[snip]

I know how to perform an HTTP request and get the status. I know
how to automate and control IE via COM. What I don’t know is how
to get the status from IE via COM.

I don’t want to hit every URL twice – once to get the status and
a second time to test via automated IE.

– Dossy

I would have assumed that you would use vbscript/jscript from windows
script
host before Ruby. It doesn’t make a lot of difference. I sure would
prefer
to use Ruby where possible :-).

I don’t go to these groups, but from their titles they would be a good
place
to start:
microsoft.public.scripting.vbscript
microsoft.public.inetexplorer.scripting

I don’t think that you can get the status code from the IE COM object.
That
is why I gave a different sample. I assume you want the IE object model
which is why you would then need to do 2 requests.

If you find a way to do this at a different group would you mind
responding
to this thread with the answer?

Hmmm. I can’t answer the question, but I can re-think it.

If I’m off-base here, please let me know.

Instead of asking “Why use Ruby?” let’s ask “Why use IE?” (Not to bash
Microsoft (not to bash those who bash Microsoft.))

Is it because you are manually examining each page in addition to
automated testing?

Could you just hit the URL and retrieve the status?

Other brainstorming:

Would ActiveScriptRuby be of any help here? You can run Ruby within IE
that way (as you do Javascript).

Also: Doesn’t every COM object have some kind of reflection API? (Not
sure – I’m not a COMmie.)

Hal

···

----- Original Message -----
From: “John” nojgoalbyspam@hotmail.com
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 4:46 PM
Subject: Re: Win32OLE: Is getting MSIE HTTP status possible?

Instead of asking “Why use Ruby?” let’s ask “Why use IE?” (Not to bash
Microsoft (not to bash those who bash Microsoft.))

The answer: I’m automating acceptance testing of a web application.

I’m just depressed that Netscape has no similar COM interface for
automating/remote controlling it.

Speaking of which, has anyone wrote any helper/utility classes
around Win32API for easy remote-controlling/automation? Otherwise,
I’m going to start writing them.

Also, interesting thing I just noted:

irb(main):001:0> require 'win32api’
LoadError: 127: The specified procedure could not be found. - Init_win32api
C:/RUBY/lib/ruby/1.6/i586-mswin32/win32api.so
from (irb):1:in `require’
from (irb):1
irb(main):002:0> require 'Win32API’
true

I wouldn’t have expected it to be case-sensitive, but it makes sense
why it was. :slight_smile:

Is it because you are manually examining each page in addition to
automated testing?

No, I’m only automating testing (matter of fact, I’m leaving
visible = false for speed). However, since this is acceptance
testing, it actually NEEDS to be fetched by MS IE so that JavaScript
gets executed and so on – we need to know that the page will
render correctly in versions of IE (5.0, 5.5, and now 6.0).

Yes, we can automate other testing by simply doing a HTTP GET of
a page and parsing the HTML document into a DOM tree and writing
assertions against the tree – this testing would be
browser-independent, probably more suitable for unit testing.
However, the acceptance testing is also important (perhaps even
more important, in my business customer’s eyes) and must be
done by driving the actual browser.

Would ActiveScriptRuby be of any help here? You can run Ruby within IE
that way (as you do Javascript).

Not sure. I haven’t played with ActiveScriptRuby. I’ll try to look
into it.

Also: Doesn’t every COM object have some kind of reflection API? (Not
sure – I’m not a COMmie.)

Yes. However, the information returned is only a list of methods,
not full documentation. :wink:

– Dossy

···

On 2002.07.17, Hal E. Fulton hal9000@hypermetrics.com wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)