Created
October 21, 2020 16:06
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
import pytest | |
import pytest_html | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.by import By | |
import time | |
import urllib3 | |
import warnings | |
from time import sleep | |
import sys | |
ch_capabilities = { | |
"build" : "[Python-1] Localization Testing with Chrome & Windows on LambdaTest Selenium Grid", | |
"name" : "[Python-1] Localization Testing with Chrome & Windows on LambdaTest Selenium Grid", | |
"platform" : "Windows 10", | |
"browserName" : "Chrome", | |
"version" : "80.0" | |
} | |
ff_capabilities = { | |
"build" : "[Python-1] Localization Testing with Firefox & macOS on LambdaTest Selenium Grid", | |
"name" : "[Python-1] Localization Testing with Firefox & macOS on LambdaTest Selenium Grid", | |
"platform" : "macOS Mojave", | |
"browserName" : "Firefox", | |
"version" : "78.0" | |
} | |
user_name = "user-name" | |
app_key = "access-key" | |
@pytest.mark.parametrize( | |
"capabilities, test_url, b_locale", | |
[ | |
(ch_capabilities, "https://www.google.com", "he-IL"), #Chrome - Hebrew | |
(ff_capabilities, "https://www.google.com", "he-IL"), #Firefox - Hebrew | |
(ff_capabilities, "https://www.google.com", "ar-BH"), #Firefox - Arabic Bahrain | |
(ch_capabilities, "https://www.google.com", "zh-HK"), #Chrome - Chinese (Hong Kong) | |
(ch_capabilities, "https://www.google.com", "ar-DZ"), #Chrome - Arabic Algeria | |
(ff_capabilities, "https://www.google.com", "ar-DZ"), # Firefox - Arabic Algeria | |
(ch_capabilities, "https://www.google.com", "ar-BH"), #Chrome - Arabic Bahrain | |
(ff_capabilities, "https://www.google.com", "zh-HK"), #Chrome - Chinese (Hong Kong) | |
] | |
) | |
def test_open_url(capabilities, test_url, b_locale): | |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
if capabilities["browserName"] == "Chrome": | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_experimental_option('prefs', {'intl.accept_languages':'{locale}'.format(locale=b_locale)}) | |
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub" | |
web_driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = capabilities, options=chrome_options) | |
elif capabilities["browserName"] == "Firefox": | |
ff_profile = webdriver.FirefoxProfile() | |
ff_profile.set_preference("intl.accept_languages", b_locale) | |
ff_profile.update_preferences() | |
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub" | |
web_driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = capabilities, browser_profile=ff_profile) | |
web_driver.get(test_url) | |
web_driver.maximize_window() | |
print("Searching lambdatest on google.com ") | |
time.sleep(5) | |
elem = web_driver.find_element(By.NAME, "q") | |
elem.send_keys("LambdaTest") | |
elem.submit() | |
time.sleep(2) | |
if (b_locale == "he-IL"): | |
web_driver.find_element(By.XPATH, "//span[.='LambdaTest: Most Powerful Cross Browser Testing Tool ...']").click() | |
elif (b_locale == "zh-HK"): | |
web_driver.find_element(By.XPATH, "//h3[.='LambdaTest: Most Powerful Cross Browser Testing Tool Online']").click() | |
elif (b_locale == "ar-BH") or (b_locale == "ar-DZ"): | |
web_driver.find_element(By.XPATH, "//span[.='LambdaTest: Most Powerful Cross Browser Testing Tool ...']").click() | |
time.sleep(5) | |
title = "Most Powerful Cross Browser Testing Tool Online | LambdaTest" | |
assert title == web_driver.title | |
language = web_driver.execute_script("return window.navigator.userlanguage || window.navigator.language") | |
assert language == b_locale | |
web_driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment