diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6cd1b28477..7374d704d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 @@ -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 diff --git a/t/lib/SGN/Test/WWW/WebDriver.pm b/t/lib/SGN/Test/WWW/WebDriver.pm index 2df1787cc8..f7f379b610 100644 --- a/t/lib/SGN/Test/WWW/WebDriver.pm +++ b/t/lib/SGN/Test/WWW/WebDriver.pm @@ -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 @@ -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} }, @@ -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; diff --git a/t/selenium2/01_list/list_groups.t b/t/selenium2/01_list/list_groups.t index d061e7092c..03449ebc51 100644 --- a/t/selenium2/01_list/list_groups.t +++ b/t/selenium2/01_list/list_groups.t @@ -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); @@ -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); @@ -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();