Reputation: 75
I'm starting in the bitbucket pipeline world and I would like to understand how to share something between a service and the step that uses the service.
I have a working pipeline that runs automatically some system tests, and I'm creating a new test. This test just is to download a file from the browser and to check if the file is in a specific folder. To do it I'm using some services that are used in the step. I have something like this pipeline.yml file:
pipelines:
default:
- step:
...
script:
- exec system_tests
services:
- selenium_chrome
...
definitions:
services:
selenium_chrome:
image: selenium/standalone-chrome:4.0.0-beta-1-prerelease-20210128.
This is a simplification of my scenario, but I think it is enough to explain the issue I'm having.
The tests are executed from the step and, once the tests finish, I know that the file is being stored in a folder in the selenium_chrome container. Now I want to check from the step container if the file is there. i.e. Basically, I want to access a folder in the selenium_chrome service container from the step that uses that service.
I did a lot of tries, but I think the closest one was to use volumes in the service, maybe? I tried something like this:
definitions:
services:
selenium_chrome:
volumes:
- $BITBUCKET_CLONE_DIR/build/tmp/downloads:/build/tmp/downloads
image: selenium/standalone-chrome:4.0.0-beta-1-prerelease-20210128
but, when I look into the tmp folder of the step container, I can't find any downloads folder.
I have also configured the chrome driver in another configuration file using the same directory ('download.default_directory': '/build/tmp/downloads').
Can someone help me to know what I'm misunderstanding or doing wrong? I'm missing something in the .yml file maybe?
Thanks in advance
Upvotes: 1
Views: 1139
Reputation: 1
This has everything you need. I also had the same issue on bitbucket. I tried using docker volumes but it didn't. The link below helped me out.
Downloads
Chrome, Edge and Firefox each allow you to set the location of the download directory. When you do this on a remote computer, though, the location is on the remote computer’s local file system. Selenium allows you to enable downloads to get these files onto the client computer. Enable Downloads in the Grid
Regardless of the client, when starting the grid in node or standalone mode, you must add the flag:
--enable-managed-downloads true
Enable Downloads in the Client
The grid uses the se:downloadsEnabled capability to toggle whether to be responsible for managing the browser location. Each of the bindings have a method in the options class to set this.
ChromeOptions options = new ChromeOptions();
options.setEnableDownloads(true);
driver = new RemoteWebDriver(gridUrl, options);
View full example on GitHub List Downloadable Files
Be aware that Selenium is not waiting for files to finish downloading, so the list is an immediate snapshot of what file names are currently in the directory for the given session.
List<String> files = ((HasDownloads) driver).getDownloadableFiles();
View full example on GitHub Download a File
Selenium looks for the name of the provided file in the list and downloads it to the provided target directory.
((HasDownloads) driver).downloadFile(downloadableFile, targetDirectory);
View full example on GitHub Delete Downloaded Files
By default, the download directory is deleted at the end of the applicable session, but you can also delete all files during the session.
((HasDownloads) driver).deleteDownloadableFiles();
https://www.selenium.dev/documentation/webdriver/drivers/remote_webdriver/
Upvotes: 0
Reputation: 75
In the end, we didn't find a way to keep the service, so, the solution that worked for us was to remove the selenium_chrome
service and just add the dockerization of this into the script:
pipelines:
default:
- step:
...
script:
- mkdir -p tmp/tests_downloads
- docker run -d -p 4444:4444 -v $BITBUCKET_CLONE_DIR/tmp/tests_downloads:/tmp/tests_downloads selenium/standalone-chrome:89.0
- exec system_tests
services:
...
...
definitions:
services:
It is not exactly what I was looking for ( ideally we wanted to keep the docker layer as a service ), but it works.
Upvotes: 2