¿Automatizar el navegador sin una ventana real del navegador?

I need to do an automated script that fills two text fields and clicks a button on a web page, and stores all resulting text to a string variable.

I know how to do this with Watir, but the problem is that this script will be running on a Windows server (with no physical monitor attached).

So this needs some kind of "emulated browser" without actual browser window... I have never before done anything like this, but after google search I think that Ruby gems "mechanize" or "capybara" might be able to do the trick.

But because I don't have any experience with either capybara or mehcanize, I'm asking a little help here...

Here is what I'm trying to do, written in Watir code. I would really appreciate it if someone could tell me how to do the same thing with either "mechanize" or "capybara". Or, if there is some other way to do this, all suggestion are welcomed:

require "watir"
ie = Watir::Browser.new
ie.goto "http://www.vero.fi/vere/Tarkistus/VeronumeronTarkistus.aspx/"
ie.text_field(:id, "tbNimi").set "John Smith"
ie.text_field(:id, "tbVerotunnus").set "123456789012"
ie.button(:id, "btnHae").click
info = ie.text

preguntado el 28 de agosto de 12 a las 13:08

Why does 'not having a monitor attached' mean that you can't use a browser-driver? It's pretty common to have such tests running in continuous integration environments (i.e. on headless servers) -

Well now that I think about it, it really should be possible (normal Windows computer does not need physical monitor to run any applications...) Server-maintaining guy (not me) just said, "there is no desktop so any windowed application won't work"... Maybe he was wrong, I have to discuss about this more with him... -

Exactly what I thought! If you have a working solution then you may as well use it if possible, and I've done a lot of testing with browsers on Windows-based continuous integration servers which run without a desktop, it's certainly possible. -

3 Respuestas

También podrías usar celeridad. It drives headless browser using Watir API.

Respondido 28 ago 12, 14:08

Thanks! I't good to be able to do this with familiar Watir syntax (may be useful also in the future). (I have heard word "Celerity" before but I had no idea what it was...) - apk

Poder Selenio Help With with Selenium Server Running and Firefox Running in headless state

I have basically wrote an article in this over aquí

Espero que esta ayuda

Respondido 30 ago 12, 17:08

yo suelo PhantomJS for this (with the Capybara driver duende). It runs a headless WebKit (Safari and Chrome's browser engine) and Capybara tells it what to do. It's the simplest-to-setup implementation of this concept that I've found.

El código se vería así:

visit "http://www.vero.fi/vere/Tarkistus/VeronumeronTarkistus.aspx/"
fill_in "tbNimi", :with => "John Smith"
fill_in "tbVerotunnus", :with => "123456789012"
click_on "btnHae"
info = page.html

Respondido 28 ago 12, 17:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.