?

Log in

No account? Create an account

GEEK: How to install Firewatir on Mac OS X Tiger (Intel) - Open Knowledge

Apr. 17th, 2007

01:21 pm - GEEK: How to install Firewatir on Mac OS X Tiger (Intel)

Previous Entry Share Next Entry

Imagine that you've just created a wonderful new website. You're excited, and you want to release it, but you also want to make sure that it works correctly. How do you test it?

One way to test it would be to hire someone to exercise your site manually. This works okay for small, simple sites, but quickly becomes untenably laborious for sites of any size or complexity.

Watir (and the other flavors of Watir, such as FireWatir and SafariWatir) can help. Watir is a web application testing framework, designed to drive Internet Explorer with automated test scripts (written in ruby).

So instead of testing your website manually over and over again, you can write a Watir test script once, and then just run the script whenever you want to test. Assuming that your user interface doesn't change dramatically from development cycle to development cycle, Watir can help you increase your testing coverage and lower labor costs.

Eventually all of the flavors of Watir will be incorporated into the main Watir code base. So you will be able to write a single Watir script and run it against multiple browsers without changes.

In the meantime, each of the flavors of Watir is designed to work with a different browser: Watir/Internet Explorer, FireWatir/Firefox, SafariWatir/Safari. The developers of each flavor try to maintain consistency across browsers/platforms, so that a script written for one version will work with minimal changes on the other versions of watir.

This tutorial describes how I got FireWatir/Firefox running on Mac OS X Tiger (Intel). If you follow the instructions below, you should have a working firewatir installation at the end. (For historical purposes, you can find my previous attempt here.)

You can find additional documentation at the google code repository for firewatir and general watir information at the watir web site. The best place to report bugs and or ask for help is either the watir mailing list or the firewatir mailing list. Brett Pettichord is the leader of the Watir project, and Angrez Singh is one of the principal leaders of the firewatir project.

About my setup

I assume you have the following already installed:
Mac OS X 10.4.8 (Intel)
XCode 2.4.1

Install ruby and rubygems

  1. Follow the instructions for installing ruby, and rubygems at Hive Logic.
  2. Test that your ruby installation is correct by running the self-tests:
    $ cd /usr/local/src/ruby-1.8.6 
    $ sudo make test-all 
    Password:
    ./miniruby  ./runruby.rb --extout=.ext -- "./test/runner.rb" --basedir="./test" --runner=console 
    Loaded suite .
    Started
    ...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
    Finished in 91.144621 seconds.
    
    Ideally, you should see no failures. However, I saw one failure when I ran the tests:
      1) Failure:
    test_s_open_error(TestSDBM) [./test/sdbm/test_sdbm.rb:123]:
     exception expected but none was thrown.
    
    1533 tests, 14730 assertions, 1 failures, 0 errors
    make: *** [test-all] Error 1
    
    I'm not sure what caused the test to fail, and I didn't want to take the time to debug it, so I moved on. Whatever caused the failure does not seem to cause any of the firewatir self-tests to fail.
  3. Now try starting irb. You should see this:
    $ irb
    irb(main):001:0> 
    

    However, you may see something like this error message:

    dyld: NSLinkModule() error
    dyld: Symbol not found: _rl_filename_completion_function
    Referenced from: /usr/local/lib/ruby/1.8/i686-darwin8.8.1/readline.bundle
    Expected in: flat namespace
    
    Trace/BPT trap
    
    If you do, try the following (ganked from here and here):
    $ cd /usr/local/src/ruby-1.8.6 
    $ cd ext/readline/ 
    $ ruby extconf.rb 
    $ rm *.o *.bundle 
    $ make 
    $ sudo cp readline.bundle /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.8.1 
    
    If you do the above steps, irb should work. Here's the output you should see at each step:
    $ cd /usr/local/src/ruby-1.8.6
    $ cd ext/readline/
    $ ruby extconf.rb
    checking for tgetnum() in -lncurses... yes
    checking for readline/readline.h... yes
    checking for readline/history.h... yes
    checking for readline() in -lreadline... yes
    checking for rl_filename_completion_function... yes
    checking for rl_deprep_term_function... yes
    checking for rl_completion_append_character... yes
    checking for rl_basic_word_break_characters... yes
    checking for rl_completer_word_break_characters... yes
    checking for rl_basic_quote_characters... yes
    checking for rl_completer_quote_characters... yes
    checking for rl_filename_quote_characters... yes
    checking for rl_attempted_completion_over... yes
    checking for rl_library_version... yes
    checking for rl_event_hook... yes
    checking for rl_cleanup_after_signal()... yes
    checking for rl_clear_signals()... yes
    checking for rl_vi_editing_mode()... yes
    checking for rl_emacs_editing_mode()... yes
    checking for rl_clear_signals()... yes
    checking for replace_history_entry()... yes
    checking for remove_history()... yes
    creating Makefile
    $ rm *.o *.bundle
    $ make 
    gcc -fno-common -g -O2 -pipe -fno-common  -I. -I/usr/local/lib/ruby/ 
    1.8/powerpc-darwin8.1.0 -I/usr/local/lib/ruby/1.8/powerpc- 
    darwin8.1.0 -I. -DHAVE_READLINE_READLINE_H - 
    DHAVE_READLINE_HISTORY_H -DHAVE_RL_FILENAME_COMPLETION_FUNCTION - 
    DHAVE_RL_DEPREP_TERM_FUNCTION -DHAVE_RL_COMPLETION_APPEND_CHARACTER  
    -DHAVE_RL_BASIC_WORD_BREAK_CHARACTERS - 
    DHAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS - 
    DHAVE_RL_BASIC_QUOTE_CHARACTERS - 
    DHAVE_RL_COMPLETER_QUOTE_CHARACTERS - 
    DHAVE_RL_FILENAME_QUOTE_CHARACTERS - 
    DHAVE_RL_ATTEMPTED_COMPLETION_OVER -DHAVE_RL_LIBRARY_VERSION - 
    DHAVE_RL_EVENT_HOOK -DHAVE_RL_CLEANUP_AFTER_SIGNAL - 
    DHAVE_RL_CLEAR_SIGNALS -DHAVE_RL_VI_EDITING_MODE - 
    DHAVE_RL_EMACS_EDITING_MODE -DHAVE_RL_CLEAR_SIGNALS - 
    DHAVE_REPLACE_HISTORY_ENTRY -DHAVE_REMOVE_HISTORY  -c readline.c
    cc -dynamic -bundle -undefined suppress -flat_namespace  -L"/usr/ 
    local/lib" -o readline.bundle readline.o  -lreadline -lncurses  - 
    ldl -lobjc
    $ sudo cp readline.bundle  /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.8.1
    

Create a new profile for firewatir

In order to run your tests on a "clean" copy of Firefox (without any other custom configurations), you may wish to run Firefox+jssh with a separate profile. To create a new profile, follow these steps:
  1. Close Firefox completely (select File > Exit from the main menu of Firefox).
  2. Start the firefox with the -ProfileManager flag:
    /Applications/Firefox.app/Contents/MacOS/firefox -ProfileManager
    
  3. Click "Create Profile", read the Introduction, then click "Continue"
  4. Enter the new profile name. I chose "firewatir"
  5. Choose the folder to store your profile. I chose the suggested default folder.
  6. Start firefox with the selected profile (either from with ProfileManager, or from the command line as follows:
     
    $ /Applications/Firefox.app/Contents/MacOS/firefox -P firewatir
    
  7. Note that, on Mac OS X, the Profile path is usually:
    ~/Library/Application Support/Firefox/Profiles/xxxxxxxx.default/

Enable JSSh

FireWatir depends on the jssh extension in order to work. JSSh is a Mozilla C++ extension module that allows other programs (such as firewatir) to establish JavaScript shell connections to a running Mozilla process via TCP/IP.
To get JSSh working, you can do one of the following:
  1. Compile Firefox with the jssh extension
  2. Install it as a plugin (Courtesy of Aleph Zarro.) NOTE: as of this writing (05/13/2007), the Aleph Zarro version of the plugin is the only one that works.
  3. Use a precompiled Deerpark version of firefox, available here (Courtesy of "Dave") [Editor's note: anyone know who Dave is?].
These instructions will assume that you download and install the precompiled version of Firefox (Deerpark). However, I've also provided instructions for installing JSSh with the plugin. Both the version of Firefox precompiled with jssh and Firefox with jssh installed via a plugin seem to work equally well.

How to install JSSh with the XPI plugin

  1. Download the JSSh xpi, and save it to a file.
  2. Open the file in Firefox by selecting "File->Open File->[location of file]" from your browser's top menu. When you open the file, the XPI installation window will pop up. After the countdown, click "Install Now". You should see a window that says "JSSh 0.1, restart to complete the installation". Click "Restart Firefox"

How to install Firefox precompiled with jssh

  1. Download the deerpark.en-US.mac.dmg.
  2. Double click on it.
  3. Copy the Deerpark app to your Applications folder

Test your jssh installation

  1. Start Firefox manually with the jssh extension as follows:
    $ /Applications/DeerPark.app/Contents/MacOS/firefox -P firewatir -jssh &
    
  2. If the jssh installation works, you should be able to telnet to port 9997:
    $ telnet localhost 9997
    Trying ::1...
    telnet: connect to address ::1: Connection refused
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    Welcome to the Mozilla JavaScript Shell!
    
  3. Within telnet, try the javascript/telnet walkthrough:
    var w0 = getWindows()[0]
    var browser = w0.getBrowser()
    browser.loadURI("http://www.croczilla.com/svg/")
    

Configure Firefox preferences

  1. Turn off popup blocking. Select "Firefox-->Preferences-->Content" and uncheck the "Block pop-up windows checkbox"
  2. Configure Firefox to open new pages in a new window rather than a new tab. Select "Firefox"-->Preferences-->Tabs", then check the radio button for "New pages should be opened in a new window".

Install the firewatir gem

  1. You can find the gem at the firewatir code repository: Once you've downloaded it, cd to the download directory and install as follows:
    $ cd ~/Desktop
    $ sudo gem install --local firewatir-1.0.2.gem
    
    You should see:
    Password:
    Successfully installed firewatir, version 1.0.2
    Installing ri documentation for firewatir-1.0.2...
    Installing RDoc documentation for firewatir-1.0.2...
    
  2. You should now be able to follow the example code:
    $ irb
    irb(main):001:0> require 'rubygems'
    => true
    irb(main):002:0> require 'firewatir'
    => true
    irb(main):003:0> include FireWatir
    => Object
    irb(main):004:0> ff=Firefox.new
    => #
    irb(main):005:0> ff.goto("http://mail.yahoo.com")
    
  3. To more fully test your firewatir installation, go to the unit tests directory in the firewatir gem install, and run them as follows:
    $ cd /usr/local/lib/ruby/gems/1.8/gems/firewatir-1.0.2/unittests
    $ ruby mozilla_all_tests.rb 
    
    Here are the results I got:
    Loaded suite mozilla_all_tests
    Started
    [deleted for brevity]
    Finished in 28.202549 seconds.
    
    199 tests, 1233 assertions, 0 failures, 0 errors
    

Troubleshooting

  1. If you install the wrong version of the XPI, your app will hang until you manually interrupt it:
    $ ruby mozilla_all_tests.rb 
    Loaded suite mozilla_all_tests
    Started
    ^C./../container.rb:842:in `recv': Interrupt
            from ./../container.rb:842:in `read_socket'
            from ./../container.rb:837:in `each'
            from ./../container.rb:837:in `read_socket'
            from ./../firewatir.rb:547:in `wait'
            from ./../firewatir.rb:259:in `goto'
            from ./unittests/bug_fixes_test.rb:8:in `setup'
            from /usr/local/lib/ruby/1.8/test/unit/testcase.rb:77:in `run'
            from /usr/local/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
             ... 9 levels...
            from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
            from /usr/local/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
            from /usr/local/lib/ruby/1.8/test/unit.rb:278
            from mozilla_all_tests.rb:15
    
    To fix it, you will need to re-install the correct XPI (as of this writing, Aleph Zarro's plugin is the only one that works), or use the precompiled Firefox+JSSh. Although Aleph's plugin was written for Firefox on Linux, it appears to work equally well with Firefox on Mac OS X.
  2. If you forget to configure the browser to allow popups, you will see the following errors when you run the firewatir unit tests:
      1) Error:
    test_simply_attach_to_new_window_using_title(TC_NewWindow):
    FireWatir::Exception::NoMatchingWindowFoundException: Unable to locate window, using title and Pass Page
        ./../firewatir.rb:387:in `attach'
        ./unittests/attach_to_new_window_test.rb:16:in `test_simply_attach_to_new_window_using_title'
    
      2) Error:
    test_simply_attach_to_new_window_using_url(TC_NewWindow):
    FireWatir::Exception::NoMatchingWindowFoundException: Unable to locate window, using url and (?-mix:pass\.html)
        ./../firewatir.rb:387:in `attach'
        ./unittests/attach_to_new_window_test.rb:24:in `test_simply_attach_to_new_window_using_url'
    
    199 tests, 1231 assertions, 0 failures, 2 errors
    
    If you turnoff popup blocking and rerun the tests, all of them should complete successfully.

Comments:

From:(Anonymous)
Date:April 20th, 2007 04:09 am (UTC)

Thanks

(Link)
Hi,

Thanks for the tutorial. But I am still thinking how you are able to use Linux XPI for JSSh on Mac machine. Once again thanks a lot for tutorial.

Regards,
Angrez
(Reply) (Thread)
From:(Anonymous)
Date:June 29th, 2007 09:41 am (UTC)

Problem with JSSH in osx

(Link)
Now I'm desperate. I've followed the instructions numerous times trying different things:
- Linux XPI
- Darwin XPI
- Compile Mozilla with JSSH

and I always end up with the same result. I can't connect to port 9997 on localhost/127.0.0.1 and if I try and enter the port number in Tools > JSSH in Firefox I can't click the OK button.

Any idea just what exactly is happening? You seem to be the only one with any real experience in getting this to work on the mac
(Reply) (Thread)
[User Picture]
From:crasch
Date:June 29th, 2007 07:58 pm (UTC)

Re: Problem with JSSH in osx

(Link)
No, I don't know why it's not working. Does the Deerpark version of Firefox work for you? JSSH is pre-installed in the Deerpark version of Firefox.

If you need to install the plugin to a later version of firefox, I check these things:


1. Are you using using the Aleph Zarro version of the JSSH plugin?

2. Are you launching with the correct command line arguments?


/Applications/DeerPark.app/Contents/MacOS/firefox -P firewatir -jssh &



(Reply) (Parent) (Thread)
From:(Anonymous)
Date:June 30th, 2007 04:39 am (UTC)

Re: Problem with JSSH in osx

(Link)
Dave's version of Deerpark seems to have gone missing. Know of anywhere else it is available?
(Reply) (Parent) (Thread)
From:(Anonymous)
Date:June 30th, 2007 05:04 am (UTC)

Re: Problem with JSSH in osx

(Link)
And just so you don't think I'm completely useless, the Alpha 2 download from mozilla isn't compiled with JSSH
(Reply) (Parent) (Thread)
From:(Anonymous)
Date:August 13th, 2007 04:02 pm (UTC)

Re: Problem with JSSH in osx

(Link)
Same problem here;

"I always end up with the same result. I can't connect to port 9997 on localhost/127.0.0.1"

Does anyone have this working?
(Reply) (Parent) (Thread)
From:(Anonymous)
Date:August 15th, 2007 03:36 am (UTC)

Re: Problem with JSSH in osx

(Link)
Some problem here in that I can't connect to 9997 and I can't save settings into the Tools/JSSH config window since the OK button doesn't work.


Anyone got a solution?
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]
From:crasch
Date:September 20th, 2007 09:24 pm (UTC)

Re: This doesn't work

(Link)
Well, for one thing, as written above..."NOTE: as of this writing (05/13/2007), the Aleph Zarro version of the plugin is the only one that works." If you're using the Darwin XPI, it won't work (or at least, it didn't the last time I tried).

Second, I did get it to work on my machine. People only tend to write when they can't get it to work, so those are the comments you see.

Third, software changes, things break. What worked for me at the time may not work for you now. I don't have time to debug it because I'm not using the Mac version right now.

Rather than make snotty comments, why don't _you_ write up a fix? Or offer some money to debug the problem?
(Reply) (Parent) (Thread)
From:(Anonymous)
Date:February 5th, 2008 03:14 pm (UTC)

Re: This doesn't work

(Link)
Hi,
no snotty comments from me ;-) but I do have the same problem as described above. Anybody any solutions yet? FF 2.0.0.11 OSX 10.5.1

Cheers,

Rutger
(Reply) (Parent) (Thread)
[User Picture]
From:crasch
Date:February 6th, 2008 08:11 am (UTC)

Re: This doesn't work

(Link)
Hi Rutger,

Unfortunately, I don't have any answers for you. I recommend getting on the watir mailing list, and asking there, if you haven't already.

Sorry I can't be of more help.
(Reply) (Parent) (Thread)
From:ext_97894
Date:April 30th, 2008 02:27 pm (UTC)

You'd saved a life

(Link)
Man. You saved my life. I'm on OSX 10.5 (darwin9.x) and I had the Symbol not found: _rl_filename_completion_function bug in irb (caused by readline.bundle).

But along with the other article (http://secretdiaryofhan.wordpress.com/2007/12/26/building-readline-52-on-os-x-leopard/) and with yours, I finally get rid of that dawm bug.

Thanks!
(Reply) (Thread)
[User Picture]
From:crasch
Date:May 1st, 2008 07:53 am (UTC)

Re: You'd saved a life

(Link)
Awesome! Glad it helped.
(Reply) (Parent) (Thread)