-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test and doc for changing Firefox browser language and locale
Fixes #2361 Signed-off-by: Viet Nguyen Duc <[email protected]>
- Loading branch information
Showing
12 changed files
with
140 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
function on_exit() { | ||
local exit_code=$? | ||
rm -f /tmp/xpi_files.txt | ||
exit $exit_code | ||
} | ||
trap on_exit EXIT ERR | ||
|
||
# Script is used to download language packs for a specific version of Firefox. | ||
# It requires the version number as the first argument and the target directory as the second argument. | ||
|
||
VERSION=${1:-$(firefox --version | awk '{print $3}')} | ||
TARGET_DIR="${2:-$(dirname $(readlink -f $(which firefox)))/distribution/extensions}" | ||
BASE_URL="https://ftp.mozilla.org/pub/firefox/releases/$VERSION/linux-x86_64/xpi/" | ||
|
||
# Create target directory if it doesn't exist | ||
mkdir -p "${TARGET_DIR}" | ||
|
||
# Download the list of files | ||
wget -q -O - "${BASE_URL}" | grep -oP '(?<=href=")[^"]*.xpi' >/tmp/xpi_files.txt | ||
|
||
echo "Downloading language packs for Firefox version $VERSION to $TARGET_DIR ..." | ||
|
||
# Loop through each file and download it | ||
while IFS= read -r file; do | ||
file=$(basename "${file}") | ||
echo "Downloading "${BASE_URL}${file}" ..." | ||
curl -sk -o "${TARGET_DIR}/${file}" "${BASE_URL}${file}" | ||
target_file="${TARGET_DIR}/langpack-${file%.xpi}@firefox.mozilla.org.xpi" | ||
mv "${TARGET_DIR}/${file}" "${target_file}" | ||
if [ -f "${target_file}" ]; then | ||
echo "Downloaded ${target_file}" | ||
fi | ||
done </tmp/xpi_files.txt | ||
|
||
echo "All language packs are downloaded to $TARGET_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
TEST_NODE_RELAY = os.environ.get('TEST_NODE_RELAY', 'false') | ||
TEST_ANDROID_PLATFORM_API = os.environ.get('ANDROID_PLATFORM_API') | ||
TEST_PLATFORMS = os.environ.get('TEST_PLATFORMS', 'linux/amd64') | ||
TEST_FIREFOX_INSTALL_LANG_PACKAGE = os.environ.get('TEST_FIREFOX_INSTALL_LANG_PACKAGE', 'false').lower() == 'true' | ||
|
||
if SELENIUM_GRID_USERNAME and SELENIUM_GRID_PASSWORD: | ||
SELENIUM_GRID_HOST = f"{SELENIUM_GRID_USERNAME}:{SELENIUM_GRID_PASSWORD}@{SELENIUM_GRID_HOST}" | ||
|
@@ -187,6 +188,8 @@ def setUp(self): | |
profile = webdriver.FirefoxProfile() | ||
profile.set_preference("browser.download.manager.showWhenStarting", False) | ||
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "*/*") | ||
profile.set_preference('intl.accept_languages', 'vi-VN,vi') | ||
profile.set_preference('intl.locale.requested', 'vi-VN,vi') | ||
options = FirefoxOptions() | ||
options.profile = profile | ||
options.enable_downloads = SELENIUM_ENABLE_MANAGED_DOWNLOADS | ||
|
@@ -212,6 +215,20 @@ def test_title_and_maximize_window(self): | |
self.driver.maximize_window() | ||
self.assertTrue(self.driver.title == 'The Internet') | ||
|
||
def test_accept_languages(self): | ||
if TEST_FIREFOX_INSTALL_LANG_PACKAGE: | ||
addon_id = webdriver.Firefox.install_addon(self.driver, "./target/firefox_lang_packs/[email protected]") | ||
self.driver.get('https://gtranslate.io/detect-browser-language') | ||
wait = WebDriverWait(self.driver, WEB_DRIVER_WAIT_TIMEOUT) | ||
lang_code = wait.until( | ||
EC.presence_of_element_located((By.XPATH, '(//*[@class="notranslate"])[1]')) | ||
) | ||
self.driver.execute_script("arguments[0].scrollIntoView();", lang_code) | ||
self.assertTrue(lang_code.text == 'vi-VN', "Language code should be vi-VN") | ||
time.sleep(1) | ||
self.driver.get('https://google.com') | ||
time.sleep(2) | ||
|
||
class Autoscaling(): | ||
def run(self, test_classes): | ||
with concurrent.futures.ThreadPoolExecutor() as executor: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters