Profilo di agentzhHuman & MachineFotoBlogElenchiAltro Strumenti Guida

Blog


19 luglio

Re: [jifty-devel] Idea for Template::Declare::XML

Hi, I've coded up a small script to use Template::Declare to generate some XML code (it's actually XUL, to be more specific):

    http://perlcabal.org/agent/xul/buttons.pl.txt

The output file is

    http://perlcabal.org/agent/xul/buttons.xul

The script used to run buttons.pl.txt is

    http://perlcabal.org/agent/xul/xulgen.pl.txt

It's a lot of fun. Essentially, I extended the tag set in Template::Declare::Tag by the following lines of code:

    Template::Declare::Tags::install_tag($_) for qw(
        window textbox hbox vbox radio radiogroup
        groupbox spacer
    );

The tag list given above is by no means exhaustive. It's just an experiment. :)

Here's another trivial example:

    http://perlcabal.org/agent/xul/findfile.xul
    <=
    http://perlcabal.org/agent/xul/findfile.pl.txt

Enjoy!
agentz
11 luglio

"No More Passwords (with SSH)"

Entering a password everytime logging into a remote machine via SSH is very annoying, especially when using unison to sync stuff using SSH. Here is how to save us:

     http://www.cvrti.utah.edu/~dustman/no-more-pw-ssh/

Note that the dsa thingy is unnecessary for me :) And don't forget changing the permisson of the .ssh/ directory on the server side to 700, or you'll still be prompted with password queries.

And this one may be helpful too:

    http://www.linuxproblem.org/art_9.html

Enjoy!

Setting up Selenium on Ubuntu feisty fawn 7.04

OKay, I've spent huge hours tonight and finally got Selenium servers and clients running on my Ubuntu Feisty Fawn 7.04 + Firefox 2.0.0.4. Here are the steps involved:

* First of all, download the latest Selenium Remote Control package snapshot from:

    http://maven.openqa.org/org/openqa/selenium/selenium-remote-control/0.9.2-SNAPSHOT/

For example, selenium-remote-control-0.9.2-20070707.164746-46-dist.zip works for me :)

Note that there is a serious bug in the current latest version 0.9.0: firefox hangs after server issues "Preparing Firefox profile...". See details at:

   http://jira.openqa.org/browse/SRC-225?decorator=printable

Don't download the .zip from the following location,

   http://www.openqa.org/selenium-rc/download.action

unless 0.9.2 is released ;)

The downloaded .zip file contans both the server and the client-side libraries in various languages.

* And then we need to set up the Sun Java environment if we haven't. Note that ubuntu uses gij (GNU Java bytecode interpreter) by default and this "java" doesn't work with the selenium server. (We'll get a lot of Java exceptions if we use it.)

  $ sudo apt-get install sun-java5-jdk

Then we can update the default "java" our shell sees:

  $ sudo update-alternatives --config java

Make sure the default one is something like

  /usr/lib/jvm/java- 1.5.0-sun/jre/bin/java

rather than something like

  /usr/bin/gij-wrapper-4.1

* Selenum server needs firefox-bin, so let's visible in our PATH:

  $ sudo ln -s /usr/lib/firefox/firefox-bin /usr/bin/

Also, firefox-bin needs some shared library, and we need to tell the system where those libraries are by adding the following line to /etc/ld.so.conf

   /usr/lib/firefox

Then running the following command to update the .conf setting:

   $ ldconfig

If we don't update ld's configuration, we will probably get the following error while running firefox-bin:

    /usr/lib/firefox/firefox-bin: error while loading shared libraries: libmozjs.so: cannot open shared object file: No such file or directory

* Then we can unzip the Selenium Remote Control's .zip package, cd into the selenium-remote-control-0.9.2-SNAPSHOT/selenium-server-0.9.2-SNAPSHOT directory and start the server like this:

    java -jar selenium-server.jar -port 4444

where 4444 is the port the selenium proxy server will listen to.

For other options for this Java program, look at

   http://www.openqa.org/selenium-rc/options.html

* Now it's time to play with the client-side stuff. Let's install the excellent Selenium IDE addon to our Firefox from here:

   http://www.openqa.org/selenium-ide/

Go to Firefox's "Tools" menu, and then click the "Selenium IDE" item to start it.

It's able to record our actions in Firefox and generate source code in various languages, including Perl! Just go to the [Optons] -> [Clipboard Format] in the Selenium IDE window.

After record a series of actions, you can copy the commands generated into a text editor, it will automatically converted to the right language format before entering the clipboard. :)

If we select Perl, then the generated code might look like this:

    $sel->open_ok("/");
    $sel->type_ok("q", "\"Agent Zhang\"");
    $sel->click_ok("btnG");
    $sel->wait_for_page_to_load_ok("30000");
    $sel->click_ok("link=Next");
    $sel->wait_for_page_to_load_ok("30000");

* Then it's time to install the Test::WWW::Selenium module from CPAN to actually run this code:

    $ sudo cpan Test::WWW::Selenium

* After installing this module, we can add the following header to that piece of Perl code generated by Selenium IDE:

   use Test::More 'no_plan';
   use Test::WWW::Selenium;
   my $sel = Test::WWW::Selenium->new(
                host => "localhost",

                port => 4444,
                browser => "*firefox",
                rowser_url => "http://www.google.com",
                default_names => 1,
   );

And then run this .t file:

    $ perl google.t
    ok 1 - open, /
    ok 2 - type, q, "Agent Zhang"
    ok 3 - click, btnG
    ok 4 - wait_for_page_to_load, 30000
    ok 5 - click, link=Next
    ok 6 - wait_for_page_to_load, 30000
    1..6

Yes, it's a bit horrible but it works :)