From d502c640877f59df4d6dc16cf9538faf2e8188d5 Mon Sep 17 00:00:00 2001 From: Dibir Magomedsaygitov <61747324+dibir-magomedsaygitov@users.noreply.github.com> Date: Fri, 29 Oct 2021 16:55:01 +0300 Subject: [PATCH] [Ubuntu] Rework Selenium installation (#4308) --- .../SoftwareReport/SoftwareReport.Browsers.psm1 | 10 ++++++++++ .../SoftwareReport/SoftwareReport.Generator.ps1 | 3 ++- .../SoftwareReport/SoftwareReport.Tools.psm1 | 2 +- images/linux/scripts/installers/selenium.sh | 15 ++++++++++----- images/linux/scripts/tests/Tools.Tests.ps1 | 6 ++++-- images/linux/toolsets/toolset-1804.json | 4 ++++ images/linux/toolsets/toolset-2004.json | 4 ++++ 7 files changed, 35 insertions(+), 9 deletions(-) diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 index 8ba6cb767..8c60f8d73 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Browsers.psm1 @@ -23,6 +23,12 @@ function Get-ChromiumVersion { return $chromiumVersion } +function Get-SeleniumVersion { + $seleniumBinaryName = Get-ToolsetValue "selenium.binary_name" + $fullSeleniumVersion = (Get-ChildItem "/usr/share/java/${seleniumBinaryName}-*").Name -replace "${seleniumBinaryName}-" + return "Selenium server $fullSeleniumVersion" +} + function Build-BrowserWebdriversEnvironmentTable { return @( @{ @@ -32,6 +38,10 @@ function Build-BrowserWebdriversEnvironmentTable { @{ "Name" = "GECKOWEBDRIVER" "Value" = $env:GECKOWEBDRIVER + }, + @{ + "Name" = "SELENIUM_JAR_PATH" + "Value" = $env:SELENIUM_JAR_PATH } ) | ForEach-Object { [PSCustomObject] @{ diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index a5178b70d..c11f0031c 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -212,7 +212,8 @@ $browsersAndDriversList = @( (Get-ChromeDriverVersion), (Get-FirefoxVersion), (Get-GeckodriverVersion), - (Get-ChromiumVersion) + (Get-ChromiumVersion), + (Get-SeleniumVersion) ) $markdown += New-MDList -Style Unordered -Lines $browsersAndDriversList diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Tools.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Tools.psm1 index a189d38b4..79b306cb0 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Tools.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Tools.psm1 @@ -287,4 +287,4 @@ function Get-ZstdVersion { function Get-YqVersion { $yqVersion = ($(yq -V) -Split " ")[-1] return "yq $yqVersion" -} +} \ No newline at end of file diff --git a/images/linux/scripts/installers/selenium.sh b/images/linux/scripts/installers/selenium.sh index f43b7b87c..23e723a4b 100644 --- a/images/linux/scripts/installers/selenium.sh +++ b/images/linux/scripts/installers/selenium.sh @@ -7,14 +7,19 @@ # Source the helpers for use with the script source $HELPER_SCRIPTS/install.sh -# Temporarily download Selenium 3.141.59, since 4.* can contain some breaking changes -SELENIUM_JAR_NAME="selenium-server-standalone.jar" +# Download Selenium server +SELENIUM_MAJOR_VERSION=$(get_toolset_value '.selenium.version') +SELENIUM_BINARY_NAME=$(get_toolset_value '.selenium.binary_name') SELENIUM_JAR_PATH="/usr/share/java" -SELENIUM_DOWNLOAD_URL="https://github.com/SeleniumHQ/selenium/releases/download/selenium-3.141.59/selenium-server-standalone-3.141.59.jar" -#SELENIUM_LATEST_VERSION_URL="$(curl -s https://api.github.com/repos/SeleniumHQ/selenium/releases/latest |\ -# jq -r '.assets[].browser_download_url | select(contains("selenium-server-standalone") and endswith(".jar"))')" +SELENIUM_JAR_NAME="$SELENIUM_BINARY_NAME.jar" +json=$(curl -s "https://api.github.com/repos/SeleniumHQ/selenium/releases?per_page=100") +SELENIUM_DOWNLOAD_URL=$(echo $json | jq -r ".[] | select(.prerelease==false).assets[].browser_download_url | select(contains(\"${SELENIUM_BINARY_NAME}-${SELENIUM_MAJOR_VERSION}\") and endswith(\".jar\"))" | head -1) download_with_retries $SELENIUM_DOWNLOAD_URL $SELENIUM_JAR_PATH $SELENIUM_JAR_NAME +# Create an epmty file to retrive selenium version +SELENIUM_FULL_VERSION=$(echo $SELENIUM_DOWNLOAD_URL | awk -F"${SELENIUM_BINARY_NAME}-|.jar" '{print $2}') +touch "$SELENIUM_JAR_PATH/$SELENIUM_BINARY_NAME-$SELENIUM_FULL_VERSION" + # Add SELENIUM_JAR_PATH environment variable echo "SELENIUM_JAR_PATH=$SELENIUM_JAR_PATH/$SELENIUM_JAR_NAME" | tee -a /etc/environment diff --git a/images/linux/scripts/tests/Tools.Tests.ps1 b/images/linux/scripts/tests/Tools.Tests.ps1 index 7ceb57c62..6cfbc01f2 100644 --- a/images/linux/scripts/tests/Tools.Tests.ps1 +++ b/images/linux/scripts/tests/Tools.Tests.ps1 @@ -194,8 +194,10 @@ Describe "Sbt" { } Describe "Selenium" { - It "Selenium Server 'selenium-server-standalone.jar' is installed" { - "/usr/share/java/selenium-server-standalone.jar" | Should -Exist + It "Selenium is installed" { + $seleniumBinaryName = (Get-ToolsetContent).selenium.binary_name + $seleniumPath = Join-Path "/usr/share/java" "$seleniumBinaryName.jar" + $seleniumPath | Should -Exist } } diff --git a/images/linux/toolsets/toolset-1804.json b/images/linux/toolsets/toolset-1804.json index f31017bc8..88692e622 100644 --- a/images/linux/toolsets/toolset-1804.json +++ b/images/linux/toolsets/toolset-1804.json @@ -278,6 +278,10 @@ "8.0" ] }, + "selenium": { + "version": "3", + "binary_name": "selenium-server-standalone" + }, "rubygems": [], "node_modules": [ { diff --git a/images/linux/toolsets/toolset-2004.json b/images/linux/toolsets/toolset-2004.json index 2cb1ed2db..d07ef4907 100644 --- a/images/linux/toolsets/toolset-2004.json +++ b/images/linux/toolsets/toolset-2004.json @@ -279,6 +279,10 @@ "rubygems": [ {"name": "fastlane"} ], + "selenium": { + "version": "3", + "binary_name": "selenium-server-standalone" + }, "node_modules": [ { "name": "grunt",