summaryrefslogtreecommitdiffstats
path: root/qa/t/selenium_server_start.t
blob: c08db293c59d7c540a2018ac5d98314d84935d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

use strict;
use warnings;

use constant DISPLAY => 99;
#use constant DISPLAY => 0;

use Test::More tests => 12;
#use Test::More tests => 4;

my $pid;

# Start the Xvfb server first
$pid = xserver_start();
ok($pid, "X Server started with PID $pid on display " . DISPLAY);
ok(open(XPID, ">testing.x.pid"), "Opening testing.x.pid");
ok((print XPID $pid), "Writing testing.x.pid");
ok(close(XPID),  "Closing testing.x.pid");

# Start the VNC service second
ok($pid = vnc_start(), "VNC desktop started with PID $pid");
ok(open(VNCPID, ">testing.vnc.pid"), "Opening testing.vnc.pid");
ok((print VNCPID $pid), "Writing testing.vnc.pid");
ok(close(VNCPID),  "Closing testing.vnc.pid");

# Start the selenium server third
ok($pid = selenium_start(), "Selenium RC server started with PID $pid");
ok(open(SPID, ">testing.selenium.pid"), "Opening testing.selenium.pid");
ok((print SPID $pid), "Writing testing.selenium.pid");
ok(close(SPID),  "Closing testing.selenium.pid");

sleep(10);

# Subroutines

sub xserver_start {
    my $pid;
    my @x_cmd = qw(Xvfb -ac -screen 0 1600x1200x24 -fbdir /tmp);
    push(@x_cmd, ":" . DISPLAY);
    $pid = fork();
    if (!$pid) {
        open(STDOUT, ">/dev/null");
        open(STDERR, ">/dev/null");
        exec(@x_cmd) || die "unable to execute: $!";
    }
    else {
        return $pid;
    }
    return 0;
}

sub vnc_start {
    my @vnc_cmd = qw(x11vnc -viewonly -forever -nopw -quiet -display);
    push(@vnc_cmd, ":" . DISPLAY);
    my $pid = fork();
    if (!$pid) {
        open(STDOUT, ">/dev/null");
        open(STDERR, ">/dev/null");
        exec(@vnc_cmd) || die "unabled to execute: $!";
    }
    return $pid;
}

sub selenium_start {
    my @selenium_cmd = qw(java -jar ../config/selenium-server-standalone.jar
                               -firefoxProfileTemplate ../config/firefox
                               -log ../config/selenium.log
                               -singlewindow);
    unshift(@selenium_cmd, "env", "DISPLAY=:" . DISPLAY);
    my $pid = fork();
    if (!$pid) {
        open(STDOUT, ">/dev/null");
        open(STDERR, ">/dev/null");
        exec(@selenium_cmd) || die "unable to execute: $!";
    }
    return $pid;
}