Tuesday, July 3. 2007
More Moz Repl goodness
In my previous entry, I described how one could set up selenium to runs tests from emacs, via the Moz REPL. The most painful part of all of that is setting up the REPL to run. After every firefox startup, you have to manually go to tools menu, and manually select 'MozLab' and then 'Start REPL'. YUCK.
It would be nice if you could somehow automatically run javascript on Firefox startup.
Enter UserChrome.js. With a little more polish, some documentation, and something more then a MozillaZine forum posting for a website; this little extension is poised to become the new GreaseMonkey. It will be the GreaseMonkey for the hard core.
Once you have installed the extension, you can now run Javascript on the creation of every new Mozilla window (even sub windows like prefs, downloads, etc.) or just the main window. From this point, it is almost painless to start the REPL:
// Anonymous function application to
(function(){
var repl = Components.classes["@hyperstruct.net/mozlab/mozrepl;1"].getService(Components.interfaces.nsIMozRepl);
if (repl && (!repl.isActive()))
{
repl.start(4242);
}
})();
This gives you a good example of how to interact with other Firefox plugins/addons through Javascript.
Monday, June 25. 2007
Automated Web Developer Tests using Selenium, Emacs, and MozRepl
Enter Selenium IDE. The Selenium IDE provides you with a method to record and execute automated tests of your website. It is easy to use, and hella cool. It can test things like the existence of an element, the text contained inside of an element, its width, height, position, etc. Using selenium, you can build yourself unit tests. This is especially useful and powerful if you happen to be one of the unlucky bastards faced with writing code in JSTL, SMARTY, or some other templating-language-that-needs-to-die. Now you finally have unit tests.
Using Selenium, the testing process is a little more automated. More importantly, you can build a series of regression tests, to ensure the stability of your web application.
There is another piece of the web-development puzzle here, and that is the Moz Repl. An REPL is a Read Eval Print Loop, basically an interactive command interpreter that you can feed commands to, and experiment with. the Moz REPL is a javascript version, that lets you inspect and modify any Javascript object in the browser. This REPL is telnet enabled, in fact, there is even a way to make Emacs talk to this REPL, so you can poke around the browser from within your text editor. This is amazingly powerful in two regards:
- you can script your browser from emacs
- you can edit code inside emacs, and send it right to the javascript interpreter for testing, and evn install it on the current page
So the final piece of the puzzle is something I call Selenemacs. It is a global emacs minor mode, in conjunction with some simple javascript that will script selenium, and provide you with feedback on whether or not its tests pass or fail.
Update 2007-07-09: new versions (Version 0.2) added
Here are the two files:
Here is how you use them:
First, download the MozREPL and Selenium IDE extensions for firefox
Edit selenemacs.el to make sure that the variable selenemacs-js-file points to selenemacs.js
Enable the MozRepl (Tools->MozLab->StartREPL)
Load up selenemacs.el inside emacs (load-file "path/to/selenemacs.el") works
Enable the minor mode selenemacs-minor-mode
Record your test in SeleniumIDE
Use the emacs command selenemacs-execute-test to launch the test, its shortcut is C-c C-s C-e
Emacs tells you if the test passed or failed.
The idea here is that you write your test, and stop using your eyes to test the results of your coding to the browser, but instead use Selenium. This is especially good if you are doing multi-stage and repetitive like testing logins, searches, etc. You can code and test right inside emacs, and only have to switch to the browser to verify that your tests actually passed.
These files also show an interesting way to script mozilla through emacs. The next step of course is to get emacs to start interacting with Firebug.
Friday, March 18. 2005
Javascript Goodness
There are 2 big things on my Javascript Radar: GreaseMonkey which has got to be one of the. Most. Empowering. Javascript. Extensions. Ever. Basically, GreaseMonkey is a website filter framework. A user can add little 'filterlets' (filets?) to change the behaviour of a website, including, (but not limited to) filtering adds, filtering posts from particular users. But its not limited to destructive filtering. GreaseMonkey can make sure that every web address (http://, ftp://, email addresses etc.) actually turns into a hyper link. No more annoying unlinked web. These user scripts are surprisingly easy to create if you know a little Javascript and HTML. Check this one that removes Xeni Jardins posts from Boing Boing. Or the previously mentioned Linkifyer. And as the GreaseMonkey docs mention, you don't have to worry about cross-platform JS, because it is a Mozilla extension... opening you up to some interesting possibilities.
And speaking of XMLHttpRequest... Sajax looks pretty freaking slick. Truly cross platform implementation of Ajax. Ajax is a method to pass Javascript objects between the browser and server, without initiating a page load. The Ice-cubes, Hearts, and Happy faces of orkut are implemented with this. This is not a new idea by a long shot, but is probably the slickest implementation yet. This is going to change web-application development forever. Now, not only is Sajax simple and small, but like I said earlier, it's cross platform. It works in IE, Gecko based browsers (Netscape 6+, Mozilla, Firefox, Camino, etc.), and KHTML based browsers (Konqurer, Safari) which is obviously important. The kicker is that it works in Io, Lua, Perl, PHP, Python and Ruby. Impressive. From what I understand, the interfaces are the same across each server side implementation. Niiiice.
Tuesday, February 22. 2005
Firefoxes missing bookmarks...
If you got here because this has happened to you, here is a list of things to do:
- Make sure you aren't running 2 firefoxes under a different profile.. Check this post here for some information
- do a search for bookmarks.html on your system. Make sure you DO search hidden files! Open them up with your browser, and if it is your bookmarks, then you are safe. Away you go!
- Do a disk-repair and check. your bookmarks might be in a file called fileXXXX.chk (where XXXX is a 4 digit number, like 0001). What you should do is open the file with a text editor, (notepad if you have to), and you are looking for HTML, with a list of all your bookmarks.. (good luck).
- Use an undelete utility, and look for the file bookmarks.html.moztmp. Apparently that might be your bookmarks file, but it may take some massaging.
- Start backing up! learn from your mistakes. Bookmark Backup is pretty cut and dry, but there are other solutions out there.
- This is bad, this is a very big, bad scary bug with Firefox. But the grass probably isn't all that greener on the other side. IE is still not terribly secure, and, depending on your system, can crash if you even look at it wrong. I don't know about Opera.
- There has been some discussion on bugzilla about this problem, so it will hopefully be addressed and fixed.
Tuesday, February 1. 2005
Anime Personification of Operating Systems. Way Cool.
Firefox tan getting hassled by a mouse-eared tan of some kind
The 'movement' isn't limited to operating systems either, there are also tans for programs as well. Norton Anti-virus and McAffee are represented, but so is Outlook and her mortal enemy Thunderbird. Firefox gets representation as well. Whute!
This is just so damn cool on so many levels. I can't exactly verbalize why I dig this so much.




