#!/usr/bin/perl -w
use strict;
use warnings;

use WWW::Selenium;
use Time::HiRes;

sub screenshot {
    my ( $sel, $basename, $id ) = @_;
    $sel->capture_entire_page_screenshot(
        $basename . sprintf( '%02d', $id ) . '.png', '' );
    Time::HiRes::usleep(150);
}

my $url = 'file:///home/petre/Desktop/slides-februarie/index.html';

my $rc = WWW::Selenium->new(
    host        => 'localhost',
    port        => 4444,
    browser     => '*firefox',
    browser_url => 'http://localhost/',
);

$rc->start;
$rc->open($url);
$rc->window_maximize;
$rc->refresh;
$rc->wait_for_page_to_load(1000);
my $last_slide = $rc->get_eval('window.smax');
my $num        = 1;

screenshot( $rc, '/tmp/slides-', $num );

while ( $rc->get_eval('window.snum') < ( $last_slide - 1 ) ) {
    $rc->click_at( q{//div[@class='presentation']}, '10,10' );
    screenshot( $rc, '/tmp/slides-', ++$num );
}

$rc->stop;