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
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
volumes:
- ${{ github.workspace }}:/home/production/cxgn/sgn
- ${{ github.workspace }}:/home/vagrant/cxgn/sgn
- ${{ github.workspace }}/.downloads:/downloads
options: --network-alias test_breedbase

services:
Expand All @@ -38,12 +39,13 @@ jobs:
volumes:
- ${{ github.workspace }}:/home/production/cxgn/sgn
- ${{ github.workspace }}:/home/vagrant/cxgn/sgn
options: --health-cmd="curl --silent --head http://localhost:4444 || exit 1"

- ${{ github.workspace }}/.downloads:/downloads
options: --health-cmd="curl --silent --head http://localhost:4444 || exit 1"

steps:
- name: Checkout sgn
uses: actions/checkout@v5

- name: Run unit tests
run: prove --recurse t/unit 2>/dev/null

Expand All @@ -64,6 +66,11 @@ jobs:
- name: Run unit_mech tests
run: /entrypoint.sh --nopatch t/unit_mech

- name: Prepare download directories
run: |
mkdir -p ${{ github.workspace}}/.downloads
chmod 0777 ${{ github.workspace}}/.downloads

# selenium tests for a moment as separate folders - will change once full solgs are ready
# but anyway, it will is still fully functional for tests purpose
- name: Run selenium tests 01_list
Expand Down
37 changes: 37 additions & 0 deletions t/lib/SGN/Test/WWW/WebDriver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Convenience accessors for driver functions:

For all other driver functions, use the driver() accessor, for example: $swd->driver->get_window_size().

For downloads, a /download dir needs to be mapped in the breedbase_web docker and in the selenium docker to the same host dir. The download dir can be obtained from this object using $d->download_dir(); .


=head1 AUTHOR

Lukas Mueller <lam87@cornell.edu>
Expand All @@ -60,8 +63,11 @@ use Moose;
use Try::Tiny;
use Test::More;
use File::Spec::Functions;
use Selenium::Firefox;
use Selenium::Firefox::Profile;
use Selenium::Remote::Driver;


has 'host' => ( is => 'rw',
isa => 'Str',
default => sub { $ENV{SGN_TEST_SERVER} },
Expand All @@ -88,6 +94,37 @@ has 'user_data' => ( is => 'rw',
}
});

has 'download_dir' => (is => 'ro',
isa => 'Str',
default => sub {
return "/downloads";
}
);

our $webdriver_instance;

sub BUILD {
my $self = shift;

$webdriver_instance = $self;

my $download_dir = $self->download_dir();

chown 1200, 1250, $download_dir;
chmod 0777, $download_dir;

my $profile = Selenium::Firefox::Profile->new;
$profile->set_preference( 'browser.download.folderList', 2 ); # Use custom download folder
$profile->set_preference( 'browser.download.dir', $download_dir );
$profile->set_preference( 'browser.download.manager.showWhenStarting', 0 );
$profile->set_preference( 'browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream,text/csv,application/zip,text/plain' );

my $driver = Selenium::Remote::Driver->new(firefox_profile => $profile, base_url => $ENV{SGN_TEST_SERVER}, remote_server_addr => $ENV{SGN_REMOTE_SERVER_ADDR} || 'localhost');


$self->driver($driver);
}

sub login_as {
my $self = shift;
my $role = shift;
Expand Down
30 changes: 21 additions & 9 deletions t/selenium2/01_list/list_groups.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ use lib 't/lib';

use Test::More;
use SGN::Test::WWW::WebDriver;
use Selenium::Firefox;
use Selenium::Firefox::Profile;

my $profile = Selenium::Firefox::Profile->new;
$profile->set_preference( 'browser.download.folderList', 2 ); # Use custom download folder
$profile->set_preference( 'browser.download.dir', '/tmp/download.txt' );
$profile->set_preference( 'browser.download.manager.showWhenStarting', 0 );
$profile->set_preference( 'browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream,text/csv,application/zip,text/plain' );

my $driver = Selenium::Remote::Driver->new(firefox_profile => $profile, base_url => $ENV{SGN_TEST_SERVER}, remote_server_addr => $ENV{SGN_REMOTE_SERVER_ADDR} || 'localhost');

my $d = SGN::Test::WWW::WebDriver->new();
$d->driver($driver);

my $download_dir = $d->download_dir();


$d->while_logged_in_as("submitter", sub {
# sleep(1);
Expand Down Expand Up @@ -143,6 +137,8 @@ $d->while_logged_in_as("submitter", sub {

# Compare two lists

unlink glob("$download_dir/*");

$d->find_element_ok("list_select_checkbox_808", "id", "checkbox select list 808")->click();

sleep(1);
Expand All @@ -163,6 +159,22 @@ $d->while_logged_in_as("submitter", sub {

sleep(1);


my @files = glob("$download_dir/*");

ok(@files, "File downloaded to tmp directory");

my $downloaded_file = "$download_dir/Only in johndoe_1_private.txt";

ok(-f $downloaded_file, "Found downloaded file: $downloaded_file");

open my $fh, '<', $downloaded_file or die "Could not open $downloaded_file: $!";
my $contents = do {local $/; <$fh> };
close $fh;

my $expected = "test1\ntest2";
like($contents, qr/\Q$expected\E/, "Downloaded file contains expected content");

## Delete list group

$d->find_element_ok("delete_selected_list_group", "id", "delete selected list group")->click();
Expand Down
Loading