Watir, XML,

E

Espen Falkevik

I use the Watir extension to generate automated test
for web pages. To control the test results I retrieve
information from the same web page, but I get the
information from a XML-file.

I use the REXML extension, and when the XML file is
saved on my computer I can retrieve the values from it
using XPath.

How can I get the values from the XML-file, so that I
can compare it with the value I set?


Code:
require 'watir'
require 'rexml/document'
include REXML

ie = Watir::IE.start("http://x.x.x.x/site.ssi")
# ie.show_all_objects
# change one value in the dropdown list
ie.select_list:)name,
"/Configuration/Audio/Inputs/Headset/Level").select_value("7")
puts "Value changed"

#saves
ie.link:)id, "").fire_event("onclick")

# open another browser and get's the xml-file
ie2 =
Watir::IE.start("http://10.47.11.217/getxml?location=/Configuration/Audio/Outputs/Headset/Level")
doc = ie2.document()

#try to use XPath to retrieve the value
node =XPath.first( doc,
"*/Configuration/Audio/Outputs/Headset/Level").get_text.value

The last line gives an error in the xpath_parser
(method_missing)

Hope someone can help me
-espen-





___________________________________________________________

Yahoo! Messenger - NEW crystal clear PC to PC calling
worldwide with voicemail http://uk.messenger.yahoo.com



___________________________________________________________
How much free photo storage do you get? Store your holiday
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
 
J

James Britt

Espen said:
...
# open another browser and get's the xml-file
ie2 =
Watir::IE.start("http://10.47.11.217/getxml?location=/Configuration/Audio/Outputs/Headset/Level")
doc = ie2.document()


What sort of object are you expecting ie2.document() to return?

The call to XPath.first expects a REXML Document object; the WATIR docs
really don't say much on this (it only says that document() returns the
current document. )

But grepping the WATIR source code does not show any references to
REXML, so it appears you'll need to first convert the IE document or
content to a REXML Document object.

Calling ie2.html gets you the DOM rendering of the document HTML; it's
*not* the same as the HTML sent to the browser. If it is not already
XML (and imagine it is not) you'll need to fix it up. Take a look at
Michael Neumann's Mechanize library for some ways to do this. His code
fetches HTML pages and exposes the content via a nice API over an REXML
document.

http://rubyforge.org/projects/wee



James
--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
 
E

Espen Falkevik

Hi
I looked at this project, but I can't seem to find the
examples/code that can help me...
Can anyone tell me how to fetch the HTML code and
convert it into a REXML document?

-Espen-



--- James Britt said:
Watir::IE.start("http://10.47.11.217/getxml?location=/Configuration/Audio/Outputs/Headset/Level")


What sort of object are you expecting ie2.document()
to return?

The call to XPath.first expects a REXML Document
object; the WATIR docs
really don't say much on this (it only says that
document() returns the
current document. )

But grepping the WATIR source code does not show any
references to
REXML, so it appears you'll need to first convert
the IE document or
content to a REXML Document object.

Calling ie2.html gets you the DOM rendering of the
document HTML; it's
*not* the same as the HTML sent to the browser. If
it is not already
XML (and imagine it is not) you'll need to fix it
up. Take a look at
Michael Neumann's Mechanize library for some ways to
do this. His code
fetches HTML pages and exposes the content via a
nice API over an REXML
document.

http://rubyforge.org/projects/wee



James
--

http://www.ruby-doc.org - The Ruby Documentation
Site
http://www.rubyxml.com - News, Articles, and
Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby
Stuff
http://www.jamesbritt.com - Playing with Better
Toys




___________________________________________________________

How much free photo storage do you get? Store your
holiday
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com



___________________________________________________________
How much free photo storage do you get? Store your holiday
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
 
J

James Britt

Espen said:
Hi
I looked at this project, but I can't seem to find the
examples/code that can help me...
Can anyone tell me how to fetch the HTML code and
convert it into a REXML document?


The project is Mechanize (though it is listed on the same main page as
the Wee project; really should get its own page, Michael!).

You can install Mechanize using rubygems.

This example logs into rubyforge.org, using values passed at the command
line:

require 'mechanize'


agent = WWW::Mechanize.new {|a| a.log = Logger.new(STDERR) }
page = agent.get('http://rubyforge.org/')
link = page.links.find {|l| l.node.text =~ /Log In/ }
page = agent.click(link)
form = page.forms[1]
form.fields.find {|f| f.name == 'form_loginname'}.value = ARGV[0]
form.fields.find {|f| f.name == 'form_pw'}.value = ARGV[1]
page = agent.submit(form, form.buttons.first)

puts page.root.class

img_alt = REXML::XPath.first( page.root, "//img" ).attributes[ 'alt' ]

p img_alt


The 'root' method of the Page instance returns a REXML Document.



James Britt
--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top