Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created September 30, 2020 13:31

Revisions

  1. muditlambda created this gist Sep 30, 2020.
    61 changes: 61 additions & 0 deletions conftest.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    import pytest
    from selenium import webdriver
    import urllib3
    import warnings
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.firefox.options import Options

    ch_capabilities = {
    "build" : "[Python] Locale Testing with Chrome & Windows on LambdaTest Selenium Grid",
    "name" : "[Python] Locale Testing with Chrome & Windows on LambdaTest Selenium Grid",
    "platform" : "Windows 10",
    "browserName" : "Chrome",
    "version" : "80.0"
    }

    ff_capabilities = {
    "build" : "[Python] Locale Testing with Firefox & macOS on LambdaTest Selenium Grid",
    "name" : "[Python] Locale 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.fixture(scope="class")
    def driver_chrome_init(request):
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    # Set the locale
    chrome_locale = 'he-IL'
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--lang={}".format(chrome_locale))
    # End - Set the locale

    remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
    # web_driver = webdriver.Chrome()
    web_driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = ch_capabilities, options=chrome_options)
    request.cls.driver = web_driver
    yield
    web_driver.close()
    web_driver.quit()

    @pytest.fixture(scope="class")
    def driver_ff_init(request):
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    # Set the locale
    firefox_locale = 'ja-JP'
    ff_profile = webdriver.FirefoxProfile()
    ff_profile.set_preference("intl.accept_languages", firefox_locale)
    ff_profile.update_preferences()
    # End - Set the locale

    remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
    web_driver = webdriver.Remote(command_executor = remote_url, desired_capabilities = ff_capabilities, browser_profile=ff_profile)
    # web_driver = webdriver.Firefox()
    request.cls.driver = web_driver
    yield
    web_driver.quit()