From ae4808ab56ae194b108225c9ad4613ae2a6916b6 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Fri, 12 Apr 2024 07:59:33 +0000 Subject: [PATCH] [test][dynamic-grid]: share node-docker volume mappings for generated browser containers Signed-off-by: Viet Nguyen Duc --- Makefile | 16 +++++++++++++--- tests/SeleniumTests/__init__.py | 10 +++++++--- tests/config.toml | 6 +++--- tests/docker-compose-v3-test-node-docker.yaml | 4 +++- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 340dc0f11..b1a2d6542 100644 --- a/Makefile +++ b/Makefile @@ -389,6 +389,7 @@ test_firefox_standalone: VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) ./tests/bootstrap.sh StandaloneFirefox test_parallel: hub chrome firefox edge + sudo rm -rf ./tests/tests for node in DeploymentAutoscaling JobAutoscaling ; do \ cd ./tests || true ; \ echo TAG=$(TAG_VERSION) > .env ; \ @@ -406,7 +407,8 @@ test_parallel: hub chrome firefox edge # Its main purpose is to check that a video file was generated. test_video: video hub chrome firefox edge # Running a few tests with docker compose to generate the videos - rm -rf ./tests/videos; mkdir -p ./tests/videos + sudo rm -rf ./tests/tests + sudo rm -rf ./tests/videos; mkdir -p ./tests/videos for node in NodeChrome NodeFirefox NodeEdge ; do \ cd ./tests || true ; \ echo VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) > .env ; \ @@ -435,10 +437,13 @@ test_video: video hub chrome firefox edge docker run -u $$(id -u) -v $$(pwd):$$(pwd) -w $$(pwd) $(FFMPEG_BASED_NAME)/ffmpeg:$(FFMPEG_BASED_TAG) -v error -i ./tests/videos/edge_video.mp4 -f null - 2>error.log test_node_docker: hub standalone_docker standalone_chrome standalone_firefox standalone_edge video - rm -rf ./tests/videos; mkdir -p ./tests/videos - sudo chmod 777 ./tests/videos + sudo rm -rf ./tests/tests + sudo rm -rf ./tests/videos; mkdir -p ./tests/videos/Downloads + sudo chmod -R 777 ./tests/videos for node in DeploymentAutoscaling JobAutoscaling ; do \ cd tests || true ; \ + DOWNLOADS_DIR="./videos/Downloads" ; \ + sudo rm -rf $$DOWNLOADS_DIR/* ; \ echo NAMESPACE=$(NAME) > .env ; \ echo TAG=$(TAG_VERSION) >> .env ; \ echo VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) >> .env ; \ @@ -446,6 +451,7 @@ test_node_docker: hub standalone_docker standalone_chrome standalone_firefox sta echo TEST_PARALLEL_HARDENING=$(or $(TEST_PARALLEL_HARDENING), "false") >> .env ; \ echo LOG_LEVEL=$(or $(LOG_LEVEL), "INFO") >> .env ; \ echo REQUEST_TIMEOUT=$(or $(REQUEST_TIMEOUT), 300) >> .env ; \ + echo SELENIUM_ENABLE_MANAGED_DOWNLOADS=$(or $(SELENIUM_ENABLE_MANAGED_DOWNLOADS), "false") >> .env ; \ echo NODE=$$node >> .env ; \ echo UID=$$(id -u) >> .env ; \ echo BINDING_VERSION=$(BINDING_VERSION) >> .env ; \ @@ -454,6 +460,10 @@ test_node_docker: hub standalone_docker standalone_chrome standalone_firefox sta envsubst < config.toml > ./videos/config.toml ; \ docker compose -f docker-compose-v3-test-node-docker.yaml up --no-log-prefix --exit-code-from tests --build ; \ if [ $$? -ne 0 ]; then exit 1; fi ; \ + if [ -d "$$DOWNLOADS_DIR" ] && [ $$(ls -1q $$DOWNLOADS_DIR | wc -l) -eq 0 ]; then \ + echo "Mounted downloads directory is empty. Downloaded files could not be retrieved!" ; \ + exit 1 ; \ + fi ; \ done test_custom_ca_cert: diff --git a/tests/SeleniumTests/__init__.py b/tests/SeleniumTests/__init__.py index 7d431d1ea..a292d1860 100644 --- a/tests/SeleniumTests/__init__.py +++ b/tests/SeleniumTests/__init__.py @@ -17,6 +17,7 @@ SELENIUM_GRID_USERNAME = os.environ.get('SELENIUM_GRID_USERNAME', '') SELENIUM_GRID_PASSWORD = os.environ.get('SELENIUM_GRID_PASSWORD', '') SELENIUM_GRID_TEST_HEADLESS = os.environ.get('SELENIUM_GRID_TEST_HEADLESS', 'false').lower() == 'true' +SELENIUM_ENABLE_MANAGED_DOWNLOADS = os.environ.get('SELENIUM_ENABLE_MANAGED_DOWNLOADS', 'true').lower() == 'true' WEB_DRIVER_WAIT_TIMEOUT = int(os.environ.get('WEB_DRIVER_WAIT_TIMEOUT', 60)) TEST_PARALLEL_HARDENING = os.environ.get('TEST_PARALLEL_HARDENING', 'false').lower() == 'true' @@ -90,6 +91,9 @@ def test_download_file(self): ) driver.execute_script("arguments[0].scrollIntoView();", file_link) file_link.click() + if not SELENIUM_ENABLE_MANAGED_DOWNLOADS: + time.sleep(4) + return wait.until( lambda d: str(d.get_downloadable_files()[0]).endswith(file_name) ) @@ -108,7 +112,7 @@ class ChromeTests(SeleniumGenericTests): def setUp(self): try: options = ChromeOptions() - options.enable_downloads = True + options.enable_downloads = SELENIUM_ENABLE_MANAGED_DOWNLOADS options.add_argument('disable-features=DownloadBubble,DownloadBubbleV2') options.set_capability('se:recordVideo', True) if SELENIUM_GRID_TEST_HEADLESS: @@ -129,7 +133,7 @@ class EdgeTests(SeleniumGenericTests): def setUp(self): try: options = EdgeOptions() - options.enable_downloads = True + options.enable_downloads = SELENIUM_ENABLE_MANAGED_DOWNLOADS options.add_argument('disable-features=DownloadBubble,DownloadBubbleV2') options.set_capability('se:recordVideo', True) if SELENIUM_GRID_TEST_HEADLESS: @@ -154,7 +158,7 @@ def setUp(self): profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "*/*") options = FirefoxOptions() options.profile = profile - options.enable_downloads = True + options.enable_downloads = SELENIUM_ENABLE_MANAGED_DOWNLOADS options.set_capability('se:recordVideo', True) if SELENIUM_GRID_TEST_HEADLESS: options.add_argument('-headless') diff --git a/tests/config.toml b/tests/config.toml index 37867b482..3efc90c3e 100755 --- a/tests/config.toml +++ b/tests/config.toml @@ -5,13 +5,13 @@ configs = [ "${NAMESPACE}/standalone-edge:${TAG}", '{"browserName": "MicrosoftEdge", "platformName": "linux"}' ] -host-config-keys = ["Dns", "DnsOptions", "DnsSearch", "ExtraHosts"] +host-config-keys = ["Dns", "DnsOptions", "DnsSearch", "ExtraHosts", "Binds"] url = "http://127.0.0.1:2375" video-image = "${NAMESPACE}/video:${VIDEO_TAG}" [node] -enable-managed-downloads = true +enable-managed-downloads = "${SELENIUM_ENABLE_MANAGED_DOWNLOADS}" override-max-sessions = true -max-sessions = 4 +max-sessions = 3 diff --git a/tests/docker-compose-v3-test-node-docker.yaml b/tests/docker-compose-v3-test-node-docker.yaml index 025f83449..6728e4439 100644 --- a/tests/docker-compose-v3-test-node-docker.yaml +++ b/tests/docker-compose-v3-test-node-docker.yaml @@ -7,6 +7,7 @@ services: - ./videos:/opt/selenium/assets - ./videos/config.toml:/opt/bin/config.toml - /var/run/docker.sock:/var/run/docker.sock + - ./videos/Downloads:/home/seluser/Downloads dns: - 8.8.8.8 - 8.8.4.4 @@ -19,7 +20,7 @@ services: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 - - SE_NODE_ENABLE_MANAGED_DOWNLOADS=true + - SE_NODE_ENABLE_MANAGED_DOWNLOADS=${SELENIUM_ENABLE_MANAGED_DOWNLOADS} - SE_LOG_LEVEL=${LOG_LEVEL} selenium-hub: @@ -45,4 +46,5 @@ services: - RUN_IN_DOCKER_COMPOSE=true - SELENIUM_GRID_HOST=selenium-hub - BINDING_VERSION=${BINDING_VERSION} + - SELENIUM_ENABLE_MANAGED_DOWNLOADS=${SELENIUM_ENABLE_MANAGED_DOWNLOADS} command: ["./bootstrap.sh", "${NODE}"]