It goes like this: Firewatir, the Firefox port of WATIR, depends on JSSh. And JSSh does not install & run nicely on Linux. Clear ?
Annoyed by this situation, I looked what’s the problem with this JSSh. To make the story short, success - downlaod the working JSSh for Linux here.
Update 2007-04-11: modified to work also with FF 1.5.3+

Oh, by the way, JSSh stands for JavaScript Shell and it allows you remotely manipulate Firefox remotely. Firewatir gives you a higher-level toolkit for “Web Application Testing in Ruby” (of course not Web scraping ;>>> ). Talking about it let me show how to install the whole thing:

(0. I would recommand to create a dedicated Firefox profile run Firefox in a dedicated profile firefox -ProfileManager)

1. Downlaod and install JSSh extension to Firefox and restart it.

2. Start Firefox:
firefox -P testyard -jssh

The JSSh should be up, listening on port 9997 (note: consider security issues). You should be able to communicate with Firefox via telnet. For example:

>telnet localhost 9997
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Welcome to the Mozilla JavaScript Shell!
> 1+1
2
> help()
....
> exit()

3. Dowload firewatir (you have to do it from its homepage, it is not on rubyforge yet). Use the mswin32 version, although you are on Linux. Install:
sudo gem install firewatir-1.0.1-mswin32.gem

3. Get to the real ruby test. For example:

  1. require ‘rubygems’
  2. require ‘firewatir’
  3. include FireWatir
  4.  
  5. ff=Firefox.new
  6. ff.goto("http://www.google.com/ncr")
  7. ff.text_field(:name,"q").set("ruby")
  8. ff.button(:value,"Google Search").click
  9. puts ff.element_by_xpath("//a[@class=’l']").text
  10. ff.close

PS: For those interested in what did I fix: I took one of the latest builds from Dave, repackaged it so that it installs “properly” - as an extension of “21st century” - and added the config GUI shipped originally with the JSSh. It was tested with FF 2.0.0.1 on Ubuntu (Eft), Kubuntu, Gentoo. Update: tested also on FF 1.5(.0.7)



18 Responses to “JSSh for Firefox on Linux (because Firewatir loves it)”  

  1. 1 Abel Muiño

    That’s a great job.

    I think that most web testing frameworks are well suited as a base for web scraping. They’ll handle the hard part (getting to the data) and provide access to the HTML, so the scrapping part do its job.

    It would be cool if both firewatir and your fix could get integrated in the main development branch of watir and jssh. Have you sent any patches to Dave?

  2. 2 brainstorm

    I’ve notified jssh’s author to include your changes upstream (I need them for a project), thanks for your fixes :-)

  3. 3 Alex Fritze

    Hi Viktor,

    Do you have a patch for JSSh that I can merge to Mozilla CVS?

    Cheers, Alex

  4. 4 TomTom

    First, thanks this is more than great!

    Finally i set up everything, but when i run your test case i get the following error:

    irb(main):015:0> puts ff.element_by_xpath(”//a[@class=’l’]”).text
    NoMethodError: undefined method `text’ for nil:NilClass
    from (irb):15
    from /usr/lib/ruby/1.8/rubygems/specification.rb:292

    However if i change @class=’1′ to simply @class it works but i can’t get anything but the ‘images’

    irb(main):016:0> puts ff.element_by_xpath(”//a[@class]”).text
    Images
    => nil

    Does anybody have any idea why is this? I’m using suse 10.1. i386

  5. 5 Angrez

    Hi,

    Thanks a lot for the XPI. But did you tested it on Firefox 1.5.x. As far as the .rdf file goes it supports this version. Is there any difference in using it on Red Hat Linux?

    - Angrez

  6. 6 viz

    Hi TomTom,

    The problem is simple. The result page the Google returned just does not contain the node you search for in your XPath. 1) Google may change the page, 2) you said you changed @class=’1′ - however in my example there was letter ‘l’, not number ‘1′.

    However, the small example I wrote still works for me.

  7. 7 viz

    Angrez, frankly: no, I haven’t test it on FF15 ;)
    But now I tried it and found there was a slight formal problem - fixed. Now it works. I tested it on FF 1.5.0.3. The xpi to download is updated (although having the same filename).

  8. 8 tomtom

    Hi viz

    Thanks for your answer. However i’m still stucked with the example. Anyway i put together some tests for the app i recently develop but some questions come up and i think i have to deepen my knowledege about xpath. Could you please give me some links where i can read about how to use “element_by_xpath”?

  9. 9 Angrez

    Hi Viz,

    Thanks a lot for the change. I’ll try it on my machine and will let you know.

    - Angrez

  10. 10 Tomtom

    Works properly with ff 1.5.0.7 and the example works too ;)

  11. 11 Christopher Rasch

    The plugin seems to work with FireWatir 1.0.2 and Firefox 2.0.0.2 on Mac OS X Tiger (Intel). I’ve detailed how I got it working here:

    http://crasch.livejournal.com/550521.html

  12. 12 Daxomatic

    Thanks for the cool how-to/explanation.
    For me it works on FF 2.0.0.3 gentoo ruby 1.8 firewatir-1.0.2 example too.
    Rgds
    Daxomatic

  13. 13 pooch

    Nice work, viz! Any chance you can publish the patch so we don’t have to wait for integration? Please (with begging)?

    Dave

  14. 14 Hari

    Hi
    I am running on a 64 bit machine . I have managed to compile Firefox 1.8 branch with the jssh extension . (using the -j4 flag )

    But on starting up the firefox with the -jssh option I get
    Error: Components.classes[’@mozilla.org/jssh-server;1′] has no properties
    Source File: file:///home/hvram/mozilla/ff-jssh/dist/bin/components/nsJSShStarter.js
    Line: 132

    I have tried the following but of no help
    a) Starting with a -P option for a separte profile
    b) Deleting the compreg.dat in the profile to allow registration

    I can see that the extensions directory under bin does not contain jssh but the jssh.manifest and the associated directores is present in the chrome directory .

    I would appreciate if you can point me to any specific pointers on getting the “21st century method “

  15. 15 Rutger

    Hi,
    I hope somebody can help met but the jssh extension does not work for me. I followed the instructions but the after starting FF with the extnsion I’m can’t chenge the setting of the extension. Pressing OK doesn’t do anything. Anybody any advice? FF2.0.0.11 OSX10.5.1 PPC

    Cheers,

    Rutger

  16. 16 jigar

    Hi rutger I too am facing same problem on
    Red hat 9
    firefox 2.0.0.11
    jssh-20070312-linux.xpi

    how to use the jssh extension working for firewatir.

  17. 17 F. Morgan Whitney

    I am trying to get this going on Ubuntu 7.10 with Firefox 2.0.0.12 and it won’t work. I tried installing your jssh plugin with no difference in results. I can launch firefox with the -jssh option and it opens, but when i try to telnet to it it refuses the connection.

    >telnet localhost 9997
    Trying 127.0.0.1…
    telnet: Unable to connect to remote host: Connection refused
    >

    I found a forum thread saying to launch FF and then use netstat, i dont see anything in that output that looks like firefox or that mentions that port. Ant ideas? :)

  18. 18 Peter Vandenabeel

    Hi,

    I just tested on Ubuntu 7.10, FireFox 2.0.0.13 and seemingly brand new firewatir-1.1.1.gem (from http://code.google.com/p/firewatir/downloads/list , uploaded just 13 hours ago) and the example in point 3 above works perfect out of the box.

    Will now start testing version 4.01 of scrubyt.org

Leave a Reply