Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
version: '2'
services:
chrome:
image: robcherry/docker-chromedriver:latest
environment:
CHROMEDRIVER_WHITELISTED_IPS: ""

geckodriver:
image: quay.io/cvlibrary/geckodriver
logging:
Expand All @@ -15,6 +20,20 @@ services:
depends_on:
- geckodriver
- httpd
environment:
WEBDRIVER_HOST: geckodriver
WEBDRIVER_CAPABILITIES: '{ "moz:firefoxOptions" : { "args" : ["-headless"] } }'
volumes:
- .:/root

test-chrome:
build: .
depends_on:
- chrome
- httpd
environment:
WEBDRIVER_HOST: chrome
WEBDRIVER_CAPABILITIES: '{ "chromeOptions" : { "binary" : "/usr/bin/google-chrome", "args": ["--headless"] } }'
volumes:
- .:/root

14 changes: 10 additions & 4 deletions lib/WebDriver/Tiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ sub new($class, %args) {
$args{base_url} // '',
], $class;

my $req_args = { desiredCapabilities => $args{capabilities} // {} };
$req_args->{_need_sessionId} = 1;
my $reply = $self->_req(
POST => '', { desiredCapabilities => $args{capabilities} // {} } );
POST => '', $req_args );

$self->[1] .= '/' . $reply->{sessionId};

Expand Down Expand Up @@ -274,14 +276,18 @@ sub window_switch($self, $handle) {
$self;
}

sub _req($self, $method, $path, $args = undef) {
sub _req($self, $method, $path, $args = {}) {
my $need_sessionId = delete $args->{_need_sessionId};

my $reply = $self->[0]->request(
$method,
$self->[1] . $path,
{ content => JSON::PP::encode_json( $args // {} ) },
{ content => JSON::PP::encode_json( $args ) },
);

my $value = eval { JSON::PP::decode_json( $reply->{content} )->{value} };
my $full_value = eval { JSON::PP::decode_json( $reply->{content} ) };
my $value = $full_value->{value};
$value->{sessionId} //= $full_value->{sessionId} if $need_sessionId;

unless ( $reply->{success} ) {
my $error = $value
Expand Down
6 changes: 4 additions & 2 deletions run-xt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/sh

docker-compose up --abort-on-container-exit --build --exit-code-from test -t0

docker-compose run --rm test
ret=$?
docker-compose run --rm test-chrome

ret=$? && $ret

docker-compose kill &> /dev/null
docker-compose rm -f &> /dev/null
Expand Down
5 changes: 3 additions & 2 deletions xt/alert.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use strict;
use warnings;

use JSON::PP ();
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/attr.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use strict;
use warnings;

use JSON::PP ();
use Test::Deep;
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use strict;
use utf8;
use warnings;

use JSON::PP ();
use Test::Deep;
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/cookies.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use strict;
use warnings;

use JSON::PP ();
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/form.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use utf8;
use warnings;

use JSON::PP ();
use Test::Deep;
use Test::More;
use URI;
Expand All @@ -15,8 +16,8 @@ sub pick { map { splice @_, rand @_, 1 } 1 .. shift }
sub roll { map { $_[ rand @_ ] } 1 .. shift }

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/ghost.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use strict;
use utf8;
use warnings;

use JSON::PP ();
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/javascript.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use strict;
use warnings;

use JSON::PP ();
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/screenshot.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use strict;
use warnings;

use JSON::PP ();
use File::Temp;
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/status.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use strict;
use warnings;

use JSON::PP ();
use Test::Deep;
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down
5 changes: 3 additions & 2 deletions xt/window-management.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use strict;
use warnings;

use JSON::PP ();
use Test::Deep;
use Test::More;
use WebDriver::Tiny;

my $drv = WebDriver::Tiny->new(
capabilities => { 'moz:firefoxOptions' => { args => ['-headless'] } },
host => 'geckodriver',
capabilities => JSON::PP::decode_json($ENV{WEBDRIVER_CAPABILITIES} || '{}'),
host => $ENV{WEBDRIVER_HOST},
port => 4444,
);

Expand Down