Selenium & Saucelenium: installation and dbus-xorg-woes

Tuesday, September 7. 2010
Comments

We're about to launch a new product, and this time it's pretty client-side-intense. The application is powered by a lot of JavaScript(-mvc) and jQuery, which do xhr calls to a ZF/CouchDB powered backend. While js-mvc has unit-testing sort of covetred, I was also looking for some integration testing, multiple browsers and all that.

Selenium vs. Saucelenium

I can't really say if you want one or the other. Revisiting Selenium in general, it's IMHO the only viable and suitable thing for a PHP shop. Primarily of course because all those nifty test cases will integrate into our existing suite of PHPUnit/phpt tests. And while I use Zend_Test already or find projects like SimpleTest's browser or even Perl's www::mechanize very appealing, neither of those executes JavaScript like a browser.

Selenium and Saucelenium have the same root — in fact Saucelenium is a Selenium fork. While the Selenium project seems to focus on 2.x currently, stable 1.x development seems to really happen at Saucelabs. That is if you call a commit from January 22nd of this year active development.

In the process of selecting one or the other, more people recommended that I'd use the Saucelabs distribution than the original one, and so I forked it on github.

Installation

Along with a script to start the damn thing, my fork also contains a README.md. Said README covers the installation part in detail, so I won't have to repeat myself here. All of this is pretty Ubuntu-centric and has been tested on Karmic Koala. I expect things to work just as well on Lucid, or on any other distribution if you get the installation right.

One thing that took me a while to figure out was the following error message:

[email protected]:/usr/src/saucelenium$ sudo ./start.sh 
[...]
[config/dbus] couldn't take over org.x.config: org.freedesktop.DBus.Error.AccessDenied (Connection ":1.17" is not allowed to own the service "org.x.config.display0" due to security     policies in the configuration file)
(EE) config/hal: couldn't initialise context: unknown error (null)
13:17:23.166 INFO - Writing debug logs to /var/log/selenium.log
13:17:23.166 INFO - Java: Sun Microsystems Inc. 16.0-b13
13:17:23.166 INFO - OS: Linux 2.6.32.1-rscloud amd64
13:17:23.176 INFO - v1.0.1 [exported], with Core [email protected]@ [@[email protected]]
13:17:23.296 INFO - Version Jetty/5.1.x
13:17:23.306 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
13:17:23.306 INFO - Started HttpContext[/selenium-server,/selenium-server]
13:17:23.316 INFO - Started HttpContext[/,/]
13:17:23.326 INFO - Started SocketListener on 0.0.0.0:4444
13:17:23.326 INFO - Started [email protected]
^C13:18:09.796 INFO - Shutting down...

After Google'ing for a bit, I came to the conclusion that the above means that I didn't have the xserver installed.

The fix was rather simple: aptitude install xserver-xorg.

Example test

The following is an example test case. It'll open http://www.php.net/ and make sure it finds "What is PHP?" somewhere on that page.

Then it will continue to /downloads.php (by clicking on that link) and will make sure it finds "Binaries for other systems" on that page.

To run this test, execute: phpunit ExampleTestCase.php.

class ExampleTestCase extends PHPUnit_Extensions_SeleniumTestCase
{
    protected function setUp()
    {
        $this->setHost('localhost');
        $this->setPort(4444);
        $this->setBrowser("*chrome");
        $this->setBrowserUrl("http://www.php.net/");
    }

    public function testPHP()
    {
        $this->open('/');
        $this->waitForPageToLoad('30000');
        $this->assertTextPresent('What is PHP?');

        $this->click('//a[@href="/downloads.php"]');
        $this->waitForPageToLoad('30000');
        $this->assertTextPresent('Binaries for other systems');

        // check this out, especially useful for debugging:
        $this->assertEquals('http://www.php.net/downloads.php', $this->drivers[0]->getLocation());
    }
}

That's all.

Thanks for reading, and until next time.

Nginx+PHP+FastCGI: Testing your web application with bleeding edge PHP

Sunday, July 5. 2009
Comments

So, every once in a while I find myself in need of trying out newer, maybe, not-yet-released features in PHP. For example, recently, I wanted to test RoundCube PHP6 — this is how I did it.

On a side note, the same setup would also work for testing code with previous versions of PHP.

Toolbox

I used nginx and the PHP source with a little bit of ./configure and make — for kicks!

My O.S. of choice is FreeBSD and therefor the installation steps covered are tailored to it. With a small amount of Linux/Unix-fu, anyone should make it work on another distribution regardless.

Install nginx

First off, install nginx. On FreeBSD, this should be all:

  • cd /usr/ports/www/nginx-devel && make install distclean

On other systems, this maybe a:

  • apt-get install nginx
  • emerg nginx
  • rpm -shoot-myself nginx

The next step includes the infamous spawn-fcgi which many people use to control the php-cgi processes. A lot of tutorials on the net suggest to install lighttpd because it's a part of it, but on FreeBSD, you may skip that and do the following instead:

  • cd /usr/ports/www/spawn-cgi && make install distclean

Pretty cool, huh?

So once this is done, the usual tasks need to be completed — in no particular order:

  • edit the nginx config and enable fastcgi in nginx (/usr/local/etc/nginx/nginx.conf)
  • enable nginx itself in /etc/rc.conf (nginx_enable="YES")
  • get another nifty start script (see Shell Script) to wrap spawn-cgi

... and done!


Continue reading "Nginx+PHP+FastCGI: Testing your web application with bleeding edge PHP"

Great success!

Monday, May 11. 2009
Comments

Even though I didn't like the Borat movie very much, I still like to use his line, Great success!. But on to more important things! ;-)

Last weekend, we — the Berlin PHP UserGroup (and Christian Weiske from Leipzig) — took part in what some people labeled the European PHP TestFest 2009. In a nutshell, we were writing tests to cover different PHP extensions.

Here's the outcome (numbers courtesy of Falko Menge):

Extension  Code Coverage    Line Coverage            New Tests
gettext    62.8 -> 98.8 %    54 ->  85 /  86 lines   19
intl/idn   11.6 -> 81.4 %     5 ->  35 /  43 lines    3
sockets    32.9 -> 70.5 %   282 -> 604 / 857 lines   23
posix      47.9 -> 70.0 %   147 -> 215 / 307 lines   16
xsl        67.3 -> 77.1 %   350 -> 401 / 520 lines   19

Our tests are available on a github repository and synced to the offical TestFest subversion repository.

I think we had a lot of fun, even recruited a couple newbies :-) to the whole testing thing. I want to extend my gratitude once more to everyone (Tim, Moritz, Robin, Falko, Christian, Jan and Florian) who showed up and helped us to improve PHP.

Great effort!

Slides: Testing (with) PHP

Thursday, May 7. 2009
Comments

German content: These are my slides from the BEPHPUG user group meeting (2009/05/06). I hope these help others to get an overview on testing with PHP and PHP itself. I certainly hope it's all correct too! :-)

BEPHPUG: Testen mit PHP -- Eine Einfuehrung in phpt

Wednesday, May 6. 2009
Comments

German content ahead: An invite to the local PHP usergroup meeting, today/tomorrow 6th May, 2009. It's all free and the venue is located at Z-Bar on Bergstr. 2, Berlin-Mitte!

Wir laden heute (6. Mai, 2009) zu einem kleinen Vortrag in der BEPHPUG ein.

  • Was: Testen mit PHP, eine Einfuehrung in phpt
  • Wann: 20:30 Uhr, 6. Mai, 2009
  • Wo: Z-Bar, Bergstr. 2, Berlin-Mitte
  • Eintritt: frei

... und weiter geht's am Samstag (9. Mai, 2009) mit dem TestFest!